diff --git a/wifi/frameworks/native/IWifiService.idl b/wifi/frameworks/native/IWifiService.idl new file mode 100644 index 0000000000000000000000000000000000000000..250725bda3456cb904c3f5536d07bf4aa3345b0c --- /dev/null +++ b/wifi/frameworks/native/IWifiService.idl @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +import OHOS.Wifi.IWifiScanCallback; +sequenceable OHOS.Wifi.ScanControlInfo; +sequenceable OHOS.Wifi.WifiScanParams; +sequenceable OHOS.Wifi.WifiScanInfo; +sequenceable OHOS.Wifi.WifiInfoElem; + +interface OHOS.Wifi.IWifiService { + void SetScanControlInfo([in] ScanControlInfo info); + void Scan([in] boolean compatible, [in] String bundleName); + void AdvanceScan([in] WifiScanParams params, [in] String bundleName); + void IsWifiClosedScan([out] boolean bOpen); + + void GetScanInfoList( + [in] boolean compatible, + [out] int retCode, + [out] unsigned int[] allSize, + [out] Ashmem scanInfoAshmem + ); + + void RegisterCallBack( + [in] IWifiScanCallback callback, + [in] int pid, + [in] int tokenId, + [in] String[] event + ); + + void GetSupportedFeatures([out] long features); + void SetScanOnlyAvailable([in] boolean bScanOnlyAvailable); + void GetScanOnlyAvailable([out] boolean bScanOnlyAvailable); + void StartWifiPnoScan( + [in] boolean isStartAction, + [in] int periodMs, + [in] int suspendReason + ); +} diff --git a/wifi/frameworks/native/scan_control_info_parcel.cpp b/wifi/frameworks/native/scan_control_info_parcel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5f12ee0e2aa2afb3d62046a0ed9e63c6006194f1 --- /dev/null +++ b/wifi/frameworks/native/scan_control_info_parcel.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "scan_control_info_parcel.h" + +namespace OHOS { +namespace Wifi { +bool ScanControlInfo::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteUint32(scanForbidList.size())) { + return false; + } + for (const auto &item : scanForbidList) { + if (!parcel.WriteInt32(item.scanScene) || !parcel.WriteInt32(item.scanMode) || + !parcel.WriteInt32(item.forbidTime) || !parcel.WriteInt32(item.forbidCount)) { + return false; + } + } + + if (!parcel.WriteUint32(scanIntervalList.size())) { + return false; + } + for (const auto &item : scanIntervalList) { + if (!parcel.WriteInt32(item.scanScene) || !parcel.WriteInt32(item.scanMode) || + !parcel.WriteBool(item.isSingle) || !parcel.WriteInt32(item.intervalMode) || + !parcel.WriteInt32(item.interval) || !parcel.WriteInt32(item.count)) { + return false; + } + } + return true; +} + +ScanControlInfo *ScanControlInfo::Unmarshalling(Parcel &parcel) +{ + std::unique_ptr info = std::make_unique(); + uint32_t size = 0; + + if (!parcel.ReadUint32(size)) { + return nullptr; + } + info->scanForbidList.reserve(size); + + for (uint32_t i = 0; i < size; i++) { + ScanForbidMode forbid; + if (!parcel.ReadInt32(forbid.scanScene) || !parcel.ReadInt32(forbid.scanMode) || + !parcel.ReadInt32(forbid.forbidTime) || !parcel.ReadInt32(forbid.forbidCount)) { + return nullptr; + } + info->scanForbidList.push_back(forbid); + } + + if (!parcel.ReadUint32(size)) { + return nullptr; + } + info->scanIntervalList.reserve(size); + + for (uint32_t i = 0; i < size; i++) { + ScanInterval interval; + if (!parcel.ReadInt32(interval.scanScene) || !parcel.ReadInt32(interval.scanMode) || + !parcel.ReadBool(interval.isSingle) || !parcel.ReadInt32(interval.intervalMode) || + !parcel.ReadInt32(interval.interval) || !parcel.ReadInt32(interval.count)) { + return nullptr; + } + info->scanIntervalList.push_back(interval); + } + + return info.release(); +} +} // namespace Wifi +} // namespace OHOS \ No newline at end of file diff --git a/wifi/frameworks/native/scan_control_info_parcel.h b/wifi/frameworks/native/scan_control_info_parcel.h new file mode 100644 index 0000000000000000000000000000000000000000..4737eb612b7a15d71a1c4a9d051e163ac1325949 --- /dev/null +++ b/wifi/frameworks/native/scan_control_info_parcel.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SCAN_CONTROL_INFO_PARCEL_H +#define SCAN_CONTROL_INFO_PARCEL_H + +#include "parcel.h" +#include +#include "wifi_scan_msg.h" + +namespace OHOS { +namespace Wifi { + +class ScanControlInfo : public Parcelable { +public: + std::vector scanForbidList; + std::vector scanIntervalList; + + bool Marshalling(Parcel &parcel) const override; + static ScanControlInfo *Unmarshalling(Parcel &parcel); +}; +} // namespace Wifi +} // namespace OHOS + +#endif // SCAN_CONTROL_INFO_PARCEL_H diff --git a/wifi/frameworks/native/wifi_info_elem_parcel.cpp b/wifi/frameworks/native/wifi_info_elem_parcel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6a423d45f46203e59fee9ce781d7fecfc18374c1 --- /dev/null +++ b/wifi/frameworks/native/wifi_info_elem_parcel.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "wifi_info_elem_parcel.h" + +namespace OHOS { +namespace Wifi { +bool WifiInfoElem::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteUint32(id)) { + return false; + } + + if (!parcel.WriteUint32(content.size())) { + return false; + } + + for (char c : content) { + if (!parcel.WriteInt8(c)) { + return false; + } + } + return true; +} + +WifiInfoElem *WifiInfoElem::Unmarshalling(Parcel &parcel) +{ + std::unique_ptr elem = std::make_unique(); + + if (!parcel.ReadUint32(elem->id)) { + return nullptr; + } + + uint32_t size = 0; + if (!parcel.ReadUint32(size)) { + return nullptr; + } + + elem->content.reserve(size); + + for (uint32_t i = 0; i < size; i++) { + int8_t c = 0; + if (!parcel.ReadInt8(c)) { + return nullptr; + } + elem->content.push_back(static_cast(c)); + } + + return elem.release(); +} +} // namespace Wifi +} // namespace OHOS \ No newline at end of file diff --git a/wifi/frameworks/native/wifi_info_elem_parcel.h b/wifi/frameworks/native/wifi_info_elem_parcel.h new file mode 100644 index 0000000000000000000000000000000000000000..e795c4558ebd75cb00ab4e1eff1638cbcf1d6f87 --- /dev/null +++ b/wifi/frameworks/native/wifi_info_elem_parcel.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef WIFI_INFO_ELEM_PARCEL_H +#define WIFI_INFO_ELEM_PARCEL_H + +#include "parcel.h" +#include + +namespace OHOS { +namespace Wifi { +struct WifiInfoElem : public Parcelable { + uint32_t id; + std::vector content; + + bool Marshalling(Parcel &parcel) const override; + static WifiInfoElem *Unmarshalling(Parcel &parcel); +}; +} // namespace Wifi +} // namespace OHOS + +#endif // WIFI_INFO_ELEM_PARCEL_H \ No newline at end of file diff --git a/wifi/frameworks/native/wifi_scan_info_parcel.cpp b/wifi/frameworks/native/wifi_scan_info_parcel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..256516842d9c42fd7f41776157a7fbf19ef6f54d --- /dev/null +++ b/wifi/frameworks/native/wifi_scan_info_parcel.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "wifi_scan_info_parcel.h" + +namespace OHOS { +namespace Wifi { + +bool WifiScanInfo::WriteBasicFields(Parcel &parcel, const WifiScanInfo &scanInfo) +{ + return parcel.WriteString(scanInfo.bssid) && parcel.WriteString(scanInfo.ssid) && + parcel.WriteInt32(scanInfo.bssidType) && parcel.WriteString(scanInfo.capabilities) && + parcel.WriteInt32(scanInfo.frequency) && parcel.WriteInt32(scanInfo.band) && + parcel.WriteInt32(scanInfo.channelWidth) && parcel.WriteInt32(scanInfo.centerFrequency0) && + parcel.WriteInt32(scanInfo.centerFrequency1) && parcel.WriteInt32(scanInfo.rssi) && + parcel.WriteInt32(scanInfo.securityType); +} + +bool WifiScanInfo::WriteExtendedFields(Parcel &parcel, const WifiScanInfo &scanInfo) +{ + return parcel.WriteInt64(scanInfo.features) && parcel.WriteInt64(scanInfo.timestamp) && + parcel.WriteInt32(scanInfo.wifiStandard) && parcel.WriteInt32(scanInfo.maxSupportedRxLinkSpeed) && + parcel.WriteInt32(scanInfo.maxSupportedTxLinkSpeed) && parcel.WriteInt32(scanInfo.disappearCount) && + parcel.WriteInt32(scanInfo.isHiLinkNetwork) && parcel.WriteInt32(scanInfo.supportedWifiCategory); +} + +bool WifiScanInfo::WriteInfoElems(Parcel &parcel, const std::vector &infoElems) +{ + if (!parcel.WriteUint32(infoElems.size())) { + return false; + } + for (const auto &elem : infoElems) { + if (!elem.Marshalling(parcel)) { + return false; + } + } + return true; +} + +bool WifiScanInfo::ReadBasicFields(Parcel &parcel, WifiScanInfo &scanInfo) +{ + scanInfo.bssid = parcel.ReadString(); + scanInfo.ssid = parcel.ReadString(); + return parcel.ReadInt32(scanInfo.bssidType) && parcel.ReadString(scanInfo.capabilities) && + parcel.ReadInt32(scanInfo.frequency) && parcel.ReadInt32(scanInfo.band) && + parcel.ReadInt32(scanInfo.channelWidth) && parcel.ReadInt32(scanInfo.centerFrequency0) && + parcel.ReadInt32(scanInfo.centerFrequency1) && parcel.ReadInt32(scanInfo.rssi) && + parcel.ReadInt32(scanInfo.securityType); +} + +bool WifiScanInfo::ReadExtendedFields(Parcel &parcel, WifiScanInfo &scanInfo) +{ + return parcel.ReadInt64(scanInfo.features) && parcel.ReadInt64(scanInfo.timestamp) && + parcel.ReadInt32(scanInfo.wifiStandard) && parcel.ReadInt32(scanInfo.maxSupportedRxLinkSpeed) && + parcel.ReadInt32(scanInfo.maxSupportedTxLinkSpeed) && parcel.ReadInt32(scanInfo.disappearCount) && + parcel.ReadInt32(scanInfo.isHiLinkNetwork) && parcel.ReadInt32(scanInfo.supportedWifiCategory); +} + +bool WifiScanInfo::ReadInfoElems(Parcel &parcel, std::vector &infoElems) +{ + uint32_t elemCount = 0; + if (!parcel.ReadUint32(elemCount)) { + return false; + } + infoElems.reserve(elemCount); + for (uint32_t i = 0; i < elemCount; ++i) { + std::unique_ptr elem(WifiInfoElem::Unmarshalling(parcel)); + if (!elem) { + return false; + } + infoElems.push_back(std::move(*elem)); + } + return true; +} +} // namespace + +bool WifiScanInfo::Marshalling(Parcel &parcel) const +{ + if (!WriteBasicFields(parcel, *this)) { + return false; + } + if (!WriteInfoElems(parcel, infoElems)) { + return false; + } + if (!WriteExtendedFields(parcel, *this)) { + return false; + } + return true; +} + +WifiScanInfo *WifiScanInfo::Unmarshalling(Parcel &parcel) +{ + auto scanInfo = std::make_unique(); + if (!ReadBasicFields(parcel, *scanInfo)) { + return nullptr; + } + if (!ReadInfoElems(parcel, scanInfo->infoElems)) { + return nullptr; + } + if (!ReadExtendedFields(parcel, *scanInfo)) { + return nullptr; + } + return scanInfo.release(); +} + +} // namespace Wifi +} // namespace OHOS \ No newline at end of file diff --git a/wifi/frameworks/native/wifi_scan_info_parcel.h b/wifi/frameworks/native/wifi_scan_info_parcel.h new file mode 100644 index 0000000000000000000000000000000000000000..e040631fbf70945a332f9b268d0fc384097aab49 --- /dev/null +++ b/wifi/frameworks/native/wifi_scan_info_parcel.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef WIFI_SCAN_INFO_PARCEL_H +#define WIFI_SCAN_INFO_PARCEL_H + +#include "parcel.h" +#include "wifi_scan_msg.h" +#include "wifi_info_elem_parcel.h" +#include +#include + +namespace OHOS { +namespace Wifi { +struct WifiScanInfo : public Parcelable { + std::string bssid; + std::string ssid; + int bssidType; + std::string capabilities; + int frequency; + int band; + int channelWidth; + int centerFrequency0; + int centerFrequency1; + int rssi; + int securityType; + std::vector infoElems; + int64_t features; + int64_t timestamp; + int wifiStandard; + int maxSupportedRxLinkSpeed; + int maxSupportedTxLinkSpeed; + int disappearCount; + int isHiLinkNetwork; + int supportedWifiCategory; + + bool Marshalling(Parcel &parcel) const override; + static WifiScanInfo *Unmarshalling(Parcel &parcel); + bool WriteBasicFields(Parcel &parcel, const WifiScanInfo &scanInfo); + bool WriteExtendedFields(Parcel &parcel, const WifiScanInfo &scanInfo); + bool WriteInfoElems(Parcel &parcel, const std::vector &infoElems); + bool ReadBasicFields(Parcel &parcel, WifiScanInfo &scanInfo); + bool ReadExtendedFields(Parcel &parcel, WifiScanInfo &scanInfo); + bool ReadInfoElems(Parcel &parcel, std::vector &infoElems); +} // namespace Wifi +} // namespace OHOS + +#endif // WIFI_SCAN_INFO_PARCEL_H \ No newline at end of file diff --git a/wifi/frameworks/native/wifi_scan_params_parcel.cpp b/wifi/frameworks/native/wifi_scan_params_parcel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..975f36f4ff971af451c0ee6702d7241d7bc127bf --- /dev/null +++ b/wifi/frameworks/native/wifi_scan_params_parcel.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "wifi_scan_params_parcel.h" + +namespace OHOS { +namespace Wifi { +bool WifiScanParams::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteString(ssid)) { + return false; + } + if (!parcel.WriteString(bssid)) { + return false; + } + if (!parcel.WriteInt32(band)) { + return false; + } + + if (!parcel.WriteUint32(freqs.size())) { + return false; + } + for (int freq : freqs) { + if (!parcel.WriteInt32(freq)) return false; + } + return true; +} + +WifiScanParams *WifiScanParams::Unmarshalling(Parcel &parcel) +{ + std::unique_ptr params = std::make_unique(); + + params->ssid = parcel.ReadString(); + params->bssid = parcel.ReadString(); + + if (!parcel.ReadInt32(params->band)) { + return nullptr; + } + + uint32_t size = 0; + if (!parcel.ReadUint32(size)) { + return nullptr; + } + + params->freqs.reserve(size); + + for (uint32_t i = 0; i < size; i++) { + int freq = 0; + if (!parcel.ReadInt32(freq)) { + return nullptr; + } + params->freqs.push_back(freq); + } + + return params.release(); +} +} // namespace Wifi +} // namespace OHOS \ No newline at end of file diff --git a/wifi/frameworks/native/wifi_scan_params_parcel.h b/wifi/frameworks/native/wifi_scan_params_parcel.h new file mode 100644 index 0000000000000000000000000000000000000000..26df62e73ba1f485c30060fd838a33c97be5607c --- /dev/null +++ b/wifi/frameworks/native/wifi_scan_params_parcel.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef WIFI_SCAN_PARAMS_PARCEL_H +#define WIFI_SCAN_PARAMS_PARCEL_H + +#include "parcel.h" +#include +#include + +namespace OHOS { +namespace Wifi { +struct WifiScanParams : public Parcelable { + std::string ssid; + std::string bssid; + int band; + std::vector freqs; + + bool Marshalling(Parcel &parcel) const override; + static WifiScanParams *Unmarshalling(Parcel &parcel); +}; +} // namespace Wifi +} // namespace OHOS + +#endif // WIFI_SCAN_PARAMS_PARCEL_H