!3116 Normalize Dpi Mark Rule

Merge pull request !3116 from 吴俊/master
This commit is contained in:
openharmony_ci 2024-10-12 08:32:18 +00:00 committed by Gitee
commit 8c5052eab9
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
18 changed files with 174 additions and 1 deletions

View File

@ -551,6 +551,15 @@ public:
* @return ErrCode - operation result
*/
virtual ErrCode GetDeviceConfig(const int &networkId, WifiDeviceConfig &config) = 0;
/**
* @Description set data packet identification mark rule
*
* @param uid - target app uid
* @param protocol - target protocol type
* @return enable - enable/disable dpi mark
*/
virtual ErrCode SetDpiMarkRule(const std::string &ifaceName, int uid, int protocol, int enable) = 0;
};
} // namespace Wifi
} // namespace OHOS

View File

@ -74,6 +74,7 @@ enum class DevInterfaceCode {
WIFI_SVR_CMD_SET_TX_POWER = 0x1041, /* set tx power */
WIFI_SVR_CMD_SET_LOW_TX_POWER = 0x1042, /* set low tx power */
WIFI_SVR_CMD_START_CONNECT_TO_USER_SELECT_NETWORK = 0x1043, /* connect to user select target bssid */
WIFI_SVR_CMD_SET_DPI_MARK_RULE = 0x1044, /* set dpi mark rule */
/* 以下CALL BACK类code不需要进行权限校验 */
WIFI_CBK_CMD_STATE_CHANGE = 0x3000, /* STA state change event */

View File

@ -60,6 +60,7 @@
GetSignalLevel;
SetLowLatencyMode;
SetLowTxPower;
SetDpiMarkRule;
IsBandTypeSupported;
Get5GHzChannelList;
RegisterWifiEvent;

View File

@ -612,5 +612,12 @@ ErrCode WifiDeviceImpl::GetDeviceConfig(const int &networkId, WifiDeviceConfig &
RETURN_IF_FAIL(GetWifiDeviceProxy());
return client_->GetDeviceConfig(networkId, config);
}
ErrCode WifiDeviceImpl::SetDpiMarkRule(const std::string &ifaceName, int uid, int protocol, int enable)
{
std::lock_guard<std::mutex> lock(mutex_);
RETURN_IF_FAIL(GetWifiDeviceProxy());
return client_->SetDpiMarkRule(ifaceName, uid, protocol, enable);
}
} // namespace Wifi
} // namespace OHOS

View File

@ -576,6 +576,15 @@ public:
* @return ErrCode - operation result
*/
ErrCode GetDeviceConfig(const int &networkId, WifiDeviceConfig &config) override;
/**
* @Description set data packet identification mark rule
*
* @param uid - target app uid
* @param protocol - target protocol type
* @return enable - enable/disable dpi mark
*/
ErrCode SetDpiMarkRule(const std::string &ifaceName, int uid, int protocol, int enable) override;
private:
bool GetWifiDeviceProxy();
std::atomic<int> systemAbilityId_;

View File

@ -2331,5 +2331,41 @@ ErrCode WifiDeviceProxy::GetDeviceConfig(const int &networkId, WifiDeviceConfig
return WIFI_OPT_SUCCESS;
}
ErrCode WifiDeviceProxy::SetDpiMarkRule(const std::string &ifaceName, int uid, int protocol, int enable)
{
if (mRemoteDied) {
WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
return WIFI_OPT_FAILED;
}
MessageOption option;
MessageParcel data, reply;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WIFI_LOGE("Write interface token error: %{public}s", __func__);
return WIFI_OPT_FAILED;
}
data.WriteInt32(0);
data.WriteCString(ifaceName.c_str());
data.WriteInt32(uid);
data.WriteInt32(protocol);
data.WriteInt32(enable);
int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_DPI_MARK_RULE),
data, reply, option);
if (error != ERR_NONE) {
WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_DPI_MARK_RULE), error);
return WIFI_OPT_FAILED;
}
int exception = reply.ReadInt32();
if (exception) {
return WIFI_OPT_FAILED;
}
int ret = reply.ReadInt32();
if (ret != WIFI_OPT_SUCCESS) {
return ErrCode(ret);
}
return WIFI_OPT_SUCCESS;
}
} // namespace Wifi
} // namespace OHOS

View File

@ -551,6 +551,15 @@ public:
* @return ErrCode - operation result
*/
ErrCode GetDeviceConfig(const int &networkId, WifiDeviceConfig &config) override;
/**
* @Description set data packet identification mark rule
*
* @param uid - target app uid
* @param protocol - target protocol type
* @return enable - enable/disable dpi mark
*/
ErrCode SetDpiMarkRule(const std::string &ifaceName, int uid, int protocol, int enable) override;
#ifdef OHOS_ARCH_LITE
/**
* @Description Handle remote object died event.

View File

@ -548,6 +548,15 @@ public:
* @return ErrCode - operation result
*/
virtual ErrCode GetDeviceConfig(const int &networkId, WifiDeviceConfig &config) = 0;
/**
* @Description set data packet identification mark rule
*
* @param uid - target app uid
* @param protocol - target protocol type
* @return enable - enable/disable dpi mark
*/
virtual ErrCode SetDpiMarkRule(const std::string &ifaceName, int uid, int protocol, int enable) = 0;
};
} // namespace Wifi
} // namespace OHOS

View File

@ -76,6 +76,14 @@ bool WifiAuthCenter::IsNativeProcess()
}
#endif
int WifiAuthCenter::VerifySameProcessPermission(const int &pid, const int &uid)
{
if (g_permissinAlwaysGrant) {
return PERMISSION_GRANTED;
}
return WifiPermissionHelper::VerifySameProcessPermission(pid, uid);
}
int WifiAuthCenter::VerifySetWifiInfoPermission(const int &pid, const int &uid)
{
if (g_permissinAlwaysGrant) {

View File

@ -46,6 +46,15 @@ public:
*/
static bool IsNativeProcess();
/**
* @Description Verify whether the app has the same process permission
*
* @param pid - the app's process id
* @param uid - the app id
* @return int - PERMISSION_DENIED or PERMISSION_GRANTED
*/
int VerifySameProcessPermission(const int &pid, const int &uid);
/**
* @Description Verify whether the app has the permission to operator wifi
*

View File

@ -51,6 +51,18 @@ int WifiPermissionHelper::VerifyPermission(const std::string &permissionName, co
#endif
}
int WifiPermissionHelper::VerifySameProcessPermission(const int &pid, const int &uid)
{
#ifdef OHOS_ARCH_LITE
return PERMISSION_GRANTED;
#else
if (uid == static_cast<int>(getuid()) && pid == static_cast<int>(getpid())) {
return PERMISSION_GRANTED;
}
return PERMISSION_DENIED;
#endif
}
int WifiPermissionHelper::VerifySetWifiInfoPermission(const int &pid, const int &uid)
{
if (VerifyPermission("ohos.permission.SET_WIFI_INFO", pid, uid, 0) == PERMISSION_DENIED) {

View File

@ -36,6 +36,15 @@ public:
*/
static int VerifyPermission(const std::string &permissionName, const int &pid, const int &uid, const int &tokenId);
/**
* @Description : Verify Same Process Permission.
*
* @param pid - Process ID.[in]
* @param uid - User ID.[in]
* @return int
*/
static int VerifySameProcessPermission(const int &pid, const int &uid);
/**
* @Description : Verify Set Wifi Information Permission.
*

View File

@ -33,6 +33,11 @@ int WifiPermissionUtils::VerifyGetWifiInfoPermission()
return PERMISSION_GRANTED;
}
int WifiPermissionUtils::VerifySameProcessPermission()
{
return PERMISSION_GRANTED;
}
int WifiPermissionUtils::VerifyWifiConnectionPermission()
{
return PERMISSION_GRANTED;
@ -108,6 +113,12 @@ int WifiPermissionUtils::VerifyGetWifiInfoPermission()
IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid());
}
int WifiPermissionUtils::VerifySameProcessPermission()
{
return WifiAuthCenter::GetInstance().VerifySameProcessPermission(
IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid());
}
int WifiPermissionUtils::VerifyWifiConnectionPermission()
{
return WifiAuthCenter::GetInstance().VerifyWifiConnectionPermission(

View File

@ -29,6 +29,7 @@ class WifiPermissionUtils {
public:
static int VerifySetWifiInfoPermission();
static int VerifyGetWifiInfoPermission();
static int VerifySameProcessPermission();
static int VerifyWifiConnectionPermission();
static int VerifyGetScanInfosPermission();
static int VerifyGetWifiLocalMacPermission();

View File

@ -715,6 +715,24 @@ ErrCode WifiDeviceServiceImpl::SetTxPower(int power)
return WIFI_OPT_SUCCESS;
}
ErrCode WifiDeviceServiceImpl::SetDpiMarkRule(const std::string &ifaceName, int uid, int protocol, int enable)
{
if (WifiPermissionUtils::VerifySameProcessPermission() == PERMISSION_DENIED) {
WIFI_LOGE("SetDpiMarkRule:VerifySameProcessPermission PERMISSION_DENIED!");
return WIFI_OPT_PERMISSION_DENIED;
}
if (!IsStaServiceRunning()) {
return WIFI_OPT_STA_NOT_OPENED;
}
if (WifiStaHalInterface::GetInstance().SetDpiMarkRule(ifaceName, uid, protocol, enable) != WIFI_HAL_OPT_OK) {
WIFI_LOGE("SetDpiMarkRule failed");
return WIFI_OPT_FAILED;
}
return WIFI_OPT_SUCCESS;
}
void WifiDeviceServiceImpl::ReplaceConfigWhenCandidateConnected(std::vector<WifiDeviceConfig> &result)
{
WifiLinkedInfo linkedInfo;

View File

@ -73,6 +73,8 @@ public:
ErrCode GetDeviceConfigs(std::vector<WifiDeviceConfig> &result, bool isCandidate) override;
ErrCode SetDpiMarkRule(const std::string &ifaceName, int uid, int protocol, int enable) override;
ErrCode EnableDeviceConfig(int networkId, bool attemptEnable) override;
ErrCode DisableDeviceConfig(int networkId) override;

View File

@ -123,6 +123,8 @@ void WifiDeviceStub::InitHandleMapEx2()
};
handleFuncMap[static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DEVICE_CONFIG)] = [this](uint32_t code,
MessageParcel &data, MessageParcel &reply) { OnGetDeviceConfig(code, data, reply); };
handleFuncMap[static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_DPI_MARK_RULE)] = [this](uint32_t code,
MessageParcel &data, MessageParcel &reply) { OnSetDpiMarkRule(code, data, reply); };
}
void WifiDeviceStub::InitHandleMap()
@ -1258,5 +1260,24 @@ void WifiDeviceStub::OnGetDeviceConfig(uint32_t code, MessageParcel &data, Messa
return;
}
void WifiDeviceStub::OnSetDpiMarkRule(uint32_t code, MessageParcel &data, MessageParcel &reply)
{
WIFI_LOGD("run %{public}s code %{public}u, datasize %{public}zu", __func__, code, data.GetRawDataSize());
ErrCode ret = WIFI_OPT_FAILED;
const char *readStr = data.ReadCString();
int uid = data.ReadInt32();
int protocol = data.ReadInt32();
int enable = data.ReadInt32();
if (readStr == nullptr) {
ret = WIFI_OPT_INVALID_PARAM;
} else {
std::string ifaceName = readStr;
ret = SetDpiMarkRule(ifaceName, uid, protocol, enable);
}
reply.WriteInt32(0);
reply.WriteInt32(ret);
return;
}
} // namespace Wifi
} // namespace OHOS

View File

@ -93,7 +93,8 @@ private:
void OnSetSatelliteState(uint32_t code, MessageParcel &data, MessageParcel &reply);
void OnSetLowTxPower(uint32_t code, MessageParcel &data, MessageParcel &reply);
void OnSetTxPower(uint32_t code, MessageParcel &data, MessageParcel &reply);
void OnGetDeviceConfig(uint32_t code, MessageParcel &data, MessageParcel &reply);
void OnGetDeviceConfig(uint32_t code, MessageParcel &data, MessageParcel &reply);
void OnSetDpiMarkRule(uint32_t code, MessageParcel &data, MessageParcel &reply);
private:
void ReadEapConfig(MessageParcel &data, WifiEapConfig &wifiEapConfig);