新增fuzz接口

Signed-off-by: xuepengcheng <1390206200@qq.com>
This commit is contained in:
xuepengcheng 2022-11-24 03:36:39 +00:00
parent 23bc2d7976
commit e6401f1491

View File

@ -14,6 +14,7 @@
*/
#include <cstddef>
#include <cstdint>
#include "securec.h"
#include "wificdevice_fuzzer.h"
#include "../../../../../../interfaces/kits/c/wifi_device.h"
@ -66,6 +67,64 @@ void ConnectToTest(const uint8_t* data, size_t size)
int networkId = static_cast<int>(data[0]);
ConnectTo(networkId);
}
void AddDeviceConfigTest(const uint8_t* data, size_t size)
{
int index = 0;
WifiDeviceConfig config;
if (size >= sizeof(WifiDeviceConfig)) {
if (memcpy_s(config.ssid, WIFI_MAX_SSID_LEN, data, WIFI_MAX_SSID_LEN - 1) != EOK){
return;
}
if (memcpy_s(config.bssid, WIFI_MAC_LEN, data, WIFI_MAC_LEN - 1) != EOK){
return;
}
if (memcpy_s(config.preSharedKey, WIFI_MAX_KEY_LEN, data, WIFI_MAX_KEY_LEN - 1) != EOK){
return;
}
config.securityType = static_cast<int>(data[index++]);
config.netId = static_cast<int>(data[index++]);
config.freq = static_cast<int>(data[index++]);
config.wapiPskType = static_cast<int>(data[index++]);
config.isHiddenSsid = static_cast<int>(data[index++]);
IpType ipType = STATIC_IP;
if (ipType % 2 ==1) {
ipType = DHCP;
} else if(ipType % 2 ==1) {
ipType = UNKNOWN;
}
}
int result = static_cast<int>(data[index++]);
AddDeviceConfig(&config, &result);
}
void AdvanceScanTest(const uint8_t* data, size_t size)
{
int index = 0;
WifiScanParams params;
if (size >= sizeof(WifiScanParams)) {
if (memcpy_s(params.ssid, WIFI_MAX_SSID_LEN, data, WIFI_MAX_SSID_LEN - 1) != EOK){
return;
}
if (memcpy_s(params.bssid, WIFI_MAC_LEN, data, WIFI_MAC_LEN - 1) != EOK){
return;
}
params.scanType = WIFI_FREQ_SCAN;
params.freqs = static_cast<int>(data[index++]);
params.band = static_cast<int>(data[index++]);
params.ssidLen = static_cast<int>(data[index++]);
}
AdvanceScan(&params);
}
void GetSignalLevelTest(const uint8_t* data, size_t size)
{
int rssi = 0;
int band = 0;
int index = 0;
if (size >= 2) {
rssi = static_cast<int>(data[index++]);
band = static_cast<int>(data[index++]);
}
GetSignalLevel(rssi, band);
}
namespace OHOS {
namespace Wifi {
bool WifiCDeviceFuzzerTest(const uint8_t* data, size_t size)
@ -78,6 +137,9 @@ namespace Wifi {
EnableDeviceConfigTest(data, size);
ConnectToTest(data, size);
DisconnectTest();
AddDeviceConfig(data, size);
AdvanceScanTest(data, size);
GetSignalLevel(data, size);
return true;
}
} // namespace Wifi