mirror of https://github.com/ARMmbed/mbed-os.git
Update COMPONENT_SCL.
parent
0944d0e9b0
commit
6ba8885ad3
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright 2018-2020 Cypress Semiconductor Corporation
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* 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 <cstdlib>
|
||||
#include <utility>
|
||||
#include "SclAccessPoint.h"
|
||||
|
||||
SclAccessPoint::SclAccessPoint(nsapi_wifi_ap_t ap, scl_bss_type_t bss_type, uint8_t *ie_ptr, uint32_t ie_len) :
|
||||
WiFiAccessPoint(ap), _bss_type(bss_type)
|
||||
{
|
||||
_ie_ptr = (uint8_t *)malloc(ie_len * sizeof(uint8_t));
|
||||
if (_ie_ptr != NULL) {
|
||||
_ie_len = ie_len;
|
||||
memcpy(_ie_ptr, ie_ptr, ie_len);
|
||||
}
|
||||
}
|
||||
|
||||
SclAccessPoint &SclAccessPoint::operator=(SclAccessPoint &&rhs)
|
||||
{
|
||||
if (this != &rhs) {
|
||||
WiFiAccessPoint::operator=(rhs);
|
||||
_bss_type = rhs._bss_type;
|
||||
_ie_ptr = rhs._ie_ptr;
|
||||
_ie_len = rhs._ie_len;
|
||||
rhs._ie_ptr = NULL;
|
||||
rhs._ie_len = 0;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
scl_bss_type_t SclAccessPoint::get_bss_type() const
|
||||
{
|
||||
return _bss_type;
|
||||
}
|
||||
|
||||
uint8_t *SclAccessPoint::get_ie_data() const
|
||||
{
|
||||
return _ie_ptr;
|
||||
}
|
||||
|
||||
uint32_t SclAccessPoint::get_ie_len() const
|
||||
{
|
||||
return _ie_len;
|
||||
}
|
||||
|
||||
SclAccessPoint::~SclAccessPoint()
|
||||
{
|
||||
if (_ie_ptr != NULL) {
|
||||
free(_ie_ptr);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright 2018-2020 Cypress Semiconductor Corporation
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* 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 SCL_ACCESS_POINT_H
|
||||
#define SCL_ACCESS_POINT_H
|
||||
|
||||
#include "netsocket/WiFiAccessPoint.h"
|
||||
#include "scl_types.h"
|
||||
|
||||
/* Enum for scan result type */
|
||||
enum scan_result_type {
|
||||
SRES_TYPE_WIFI_ACCESS_POINT,
|
||||
SRES_TYPE_SCL_ACCESS_POINT
|
||||
};
|
||||
|
||||
/** SclAccessPoint class
|
||||
*
|
||||
* Class that represents a Scl Access Point
|
||||
* which contains additional Scl specific information
|
||||
*/
|
||||
class SclAccessPoint : public WiFiAccessPoint {
|
||||
public:
|
||||
SclAccessPoint() : WiFiAccessPoint() {};
|
||||
SclAccessPoint(nsapi_wifi_ap_t ap, scl_bss_type_t bss_type, uint8_t *ie_ptr, uint32_t ie_len);
|
||||
|
||||
/** Define move assignment and prevent copy-assignment
|
||||
*
|
||||
* Due to IE element data could have large memory footprint,
|
||||
* only move assignment is allowed.
|
||||
*/
|
||||
SclAccessPoint &operator=(SclAccessPoint &&rhs);
|
||||
SclAccessPoint &operator=(const SclAccessPoint &rhs) = delete;
|
||||
|
||||
/** Get SCL access point's bss type
|
||||
*
|
||||
* @return The scl_bss_type_t of the access point
|
||||
*/
|
||||
scl_bss_type_t get_bss_type() const;
|
||||
|
||||
/** Get SCL access point's IE data
|
||||
*
|
||||
* @return The pointer to ie data buffer
|
||||
*/
|
||||
uint8_t *get_ie_data() const;
|
||||
|
||||
/** Get SCL access point's IE length
|
||||
*
|
||||
* @return The ie data length
|
||||
*/
|
||||
uint32_t get_ie_len() const;
|
||||
|
||||
virtual ~SclAccessPoint();
|
||||
|
||||
private:
|
||||
scl_bss_type_t _bss_type;
|
||||
uint8_t *_ie_ptr; /**< Pointer to received Beacon/Probe Response IE(Information Element) */
|
||||
uint32_t _ie_len; /**< Length of IE(Information Element) */
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -27,8 +27,8 @@
|
|||
#include "scl_emac.h"
|
||||
#include "scl_ipc.h"
|
||||
#include "mbed_wait_api.h"
|
||||
|
||||
|
||||
#include "SclAccessPoint.h"
|
||||
#include "scl_buffer_api.h"
|
||||
/** @file
|
||||
* Provides SCL interface functions to be used with WiFiInterface or NetworkInterface Objects
|
||||
*/
|
||||
|
|
@ -43,8 +43,31 @@ struct scl_tx_net_credentials {
|
|||
const char *network_passphrase;
|
||||
} scl_tx_network_credentials;
|
||||
|
||||
|
||||
struct scl_scan_userdata {
|
||||
rtos::Semaphore *sema;
|
||||
scan_result_type sres_type;
|
||||
WiFiAccessPoint *aps;
|
||||
std::vector<scl_scan_result_t> *result_buff;
|
||||
unsigned count;
|
||||
unsigned offset;
|
||||
bool scan_in_progress;
|
||||
};
|
||||
|
||||
static scl_scan_userdata interal_scan_data;
|
||||
static scl_scan_result_t internal_scan_result;
|
||||
network_params_t network_parameter;
|
||||
|
||||
/* Internal scan callback that handles the scan results */
|
||||
void scl_scan_handler(scl_scan_result_t *result_ptr,void *user_data, scl_scan_status_t status);
|
||||
|
||||
#define CMP_MAC( a, b ) (((((unsigned char*)a)[0])==(((unsigned char*)b)[0]))&& \
|
||||
((((unsigned char*)a)[1])==(((unsigned char*)b)[1]))&& \
|
||||
((((unsigned char*)a)[2])==(((unsigned char*)b)[2]))&& \
|
||||
((((unsigned char*)a)[3])==(((unsigned char*)b)[3]))&& \
|
||||
((((unsigned char*)a)[4])==(((unsigned char*)b)[4]))&& \
|
||||
((((unsigned char*)a)[5])==(((unsigned char*)b)[5])))
|
||||
|
||||
int scl_toerror(scl_result_t res)
|
||||
{
|
||||
switch (res) {
|
||||
|
|
@ -93,14 +116,22 @@ nsapi_security_t scl_tosecurity(scl_security_t sec)
|
|||
case SCL_SECURITY_WEP_SHARED:
|
||||
return NSAPI_SECURITY_WEP;
|
||||
case SCL_SECURITY_WPA_TKIP_PSK:
|
||||
case SCL_SECURITY_WPA_AES_PSK:
|
||||
case SCL_SECURITY_WPA_TKIP_ENT:
|
||||
case SCL_SECURITY_WPA_AES_ENT:
|
||||
case SCL_SECURITY_WPA_MIXED_ENT:
|
||||
return NSAPI_SECURITY_WPA;
|
||||
case SCL_SECURITY_WPA2_MIXED_PSK:
|
||||
case SCL_SECURITY_WPA2_WPA_PSK:
|
||||
case SCL_SECURITY_WPA2_WPA_TKIP_PSK:
|
||||
return NSAPI_SECURITY_WPA_WPA2;
|
||||
case SCL_SECURITY_WPA2_MIXED_ENT:
|
||||
return NSAPI_SECURITY_WPA2_ENT;
|
||||
case SCL_SECURITY_WPA2_AES_PSK:
|
||||
case SCL_SECURITY_WPA2_AES_ENT:
|
||||
case SCL_SECURITY_WPA2_FBT_PSK:
|
||||
case SCL_SECURITY_WPA2_FBT_ENT:
|
||||
case SCL_SECURITY_WPA2_TKIP_ENT:
|
||||
return NSAPI_SECURITY_WPA2;
|
||||
default:
|
||||
return NSAPI_SECURITY_UNKNOWN;
|
||||
|
|
@ -125,12 +156,13 @@ scl_security_t scl_fromsecurity(nsapi_security_t sec)
|
|||
}
|
||||
}
|
||||
|
||||
SclSTAInterface::SclSTAInterface(SCL_EMAC &emac, OnboardNetworkStack &stack)
|
||||
SclSTAInterface::SclSTAInterface(SCL_EMAC &emac, OnboardNetworkStack &stack, scl_interface_shared_info_t &shared)
|
||||
: EMACInterface(emac, stack),
|
||||
_ssid("\0"),
|
||||
_pass("\0"),
|
||||
_security(NSAPI_SECURITY_NONE),
|
||||
_scl_emac(emac)
|
||||
_scl_emac(emac),
|
||||
_iface_shared(shared)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -180,7 +212,7 @@ nsapi_error_t SclSTAInterface::connect()
|
|||
uint32_t connection_status = 0;
|
||||
|
||||
scl_tx_network_credentials.network_ssid = _ssid;
|
||||
if ((strlen(_ssid) < MAX_SSID_LENGTH) && (strlen(_ssid) > MIN_SSID_LENGTH)) {
|
||||
if ((strlen(_ssid) < MAX_SSID_LENGTH) && (strlen(_ssid) > MIN_SSID_LENGTH) ) {
|
||||
scl_tx_network_credentials.ssid_len = strlen(_ssid);
|
||||
} else {
|
||||
return NSAPI_ERROR_PARAMETER;
|
||||
|
|
@ -288,10 +320,106 @@ nsapi_error_t SclSTAInterface::disconnect()
|
|||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
int SclSTAInterface::scan(WiFiAccessPoint *res, unsigned count)
|
||||
void scl_scan_handler(scl_scan_result_t *result_ptr,
|
||||
void *user_data, scl_scan_status_t status)
|
||||
{
|
||||
/* To Do */
|
||||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
scl_scan_userdata *data = (scl_scan_userdata *)&interal_scan_data;
|
||||
scl_scan_result_t *record = result_ptr;
|
||||
unsigned int i;
|
||||
nsapi_wifi_ap ap;
|
||||
uint8_t length;
|
||||
|
||||
/* Even after stopping scan, some results will still come as results are already present in the queue */
|
||||
if (data->scan_in_progress == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
// finished scan, either succesfully or through an abort
|
||||
if (status != SCL_SCAN_INCOMPLETE) {
|
||||
data->scan_in_progress = false;
|
||||
data->sema->release();
|
||||
return;
|
||||
}
|
||||
|
||||
// can't really keep anymore scan results
|
||||
if (data->count > 0 && data->offset >= data->count) {
|
||||
/* We can not abort the scan as this function is getting executed in SCL context,
|
||||
Note that to call any SCL API, caller function should not in SCL context */
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < data->result_buff->size(); i++) {
|
||||
if (memcmp(((*data->result_buff)[i].BSSID.octet),(record->BSSID.octet),sizeof(scl_mac_t)) == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (data->count > 0 && (data->aps != NULL)) {
|
||||
// get ap stats
|
||||
length = record->SSID.length;
|
||||
if (length < (sizeof(ap.ssid) - 1)) {
|
||||
length = sizeof(ap.ssid) - 1;
|
||||
}
|
||||
memcpy(ap.ssid, record->SSID.value, length);
|
||||
ap.ssid[length] = '\0';
|
||||
|
||||
memcpy(ap.bssid, record->BSSID.octet, sizeof(ap.bssid));
|
||||
|
||||
ap.security = scl_tosecurity(record->security);
|
||||
ap.rssi = record->signal_strength;
|
||||
ap.channel = record->channel;
|
||||
if (data->sres_type == SRES_TYPE_WIFI_ACCESS_POINT) {
|
||||
data->aps[data->offset] = WiFiAccessPoint(ap);
|
||||
} else if (data->sres_type == SRES_TYPE_SCL_ACCESS_POINT) {
|
||||
SclAccessPoint *aps_sres = static_cast<SclAccessPoint *>(data->aps);
|
||||
aps_sres[data->offset] = std::move(SclAccessPoint(ap, record->bss_type,
|
||||
record->ie_ptr, record->ie_len));
|
||||
}
|
||||
}
|
||||
|
||||
// store to result_buff for future duplication removal
|
||||
data->result_buff->push_back(*record);
|
||||
data->offset = data->result_buff->size();
|
||||
}
|
||||
|
||||
int SclSTAInterface::internal_scan(WiFiAccessPoint *aps, unsigned count, scan_result_type sres_type)
|
||||
{
|
||||
ScopedMutexLock lock(_iface_shared.mutex);
|
||||
scl_result_t scl_res;
|
||||
int res;
|
||||
|
||||
// initialize wifi, this is noop if already init
|
||||
if (!_scl_emac.powered_up) {
|
||||
if(!_scl_emac.power_up()) {
|
||||
return NSAPI_ERROR_DEVICE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
interal_scan_data.sema = new Semaphore();
|
||||
interal_scan_data.sres_type = sres_type;
|
||||
interal_scan_data.aps = aps;
|
||||
interal_scan_data.count = count;
|
||||
interal_scan_data.offset = 0;
|
||||
interal_scan_data.scan_in_progress = true;
|
||||
interal_scan_data.result_buff = new std::vector<scl_scan_result_t>();
|
||||
|
||||
scl_res = (scl_result_t)scl_wifi_scan(SCL_SCAN_TYPE_ACTIVE, SCL_BSS_TYPE_ANY,
|
||||
NULL, NULL, NULL, NULL, scl_scan_handler, &internal_scan_result, &interal_scan_data);
|
||||
if (scl_res != SCL_SUCCESS) {
|
||||
res = scl_toerror(scl_res);
|
||||
} else {
|
||||
/* This semaphore will be released in scan callback once the scan is completed */
|
||||
interal_scan_data.sema->acquire();
|
||||
res = interal_scan_data.offset;
|
||||
}
|
||||
delete interal_scan_data.sema;
|
||||
delete interal_scan_data.result_buff;
|
||||
return res;
|
||||
}
|
||||
|
||||
int SclSTAInterface::scan(WiFiAccessPoint *aps, unsigned count)
|
||||
{
|
||||
return internal_scan(aps, count, SRES_TYPE_WIFI_ACCESS_POINT);
|
||||
}
|
||||
|
||||
int8_t SclSTAInterface::get_rssi()
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@
|
|||
#include "scl_emac.h"
|
||||
#include "scl_wifi_api.h"
|
||||
#include "scl_types.h"
|
||||
#include "SclAccessPoint.h"
|
||||
#include "scl_interface.h"
|
||||
#define MAX_SSID_LENGTH (33) /**< Maximum ssid length */
|
||||
#define MAX_PASSWORD_LENGTH (64) /**< Maximum password length */
|
||||
|
||||
|
|
@ -40,7 +42,8 @@ public:
|
|||
|
||||
SclSTAInterface(
|
||||
SCL_EMAC &emac = SCL_EMAC::get_instance(),
|
||||
OnboardNetworkStack &stack = OnboardNetworkStack::get_default_instance());
|
||||
OnboardNetworkStack &stack = OnboardNetworkStack::get_default_instance(),
|
||||
scl_interface_shared_info_t &shared = scl_iface_shared);
|
||||
|
||||
/** Gets the current instance of the SclSTAInterface
|
||||
*
|
||||
|
|
@ -127,11 +130,16 @@ public:
|
|||
*/
|
||||
int8_t get_rssi();
|
||||
|
||||
/** Scans for available networks - NOT SUPPORTED
|
||||
/** Scan for available networks in WiFiAccessPoint format
|
||||
*
|
||||
* @return NSAPI_ERROR_UNSUPPORTED
|
||||
* This function will block.
|
||||
*
|
||||
* @param aps Pointer to allocated array of WiFiAccessPoint format for discovered AP
|
||||
* @param count Size of allocated @a res array, or 0 to only count available AP
|
||||
* @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error
|
||||
* see @a nsapi_error
|
||||
*/
|
||||
int scan(WiFiAccessPoint *res, unsigned count);
|
||||
int scan(WiFiAccessPoint *aps, unsigned count);
|
||||
|
||||
/** This function is used to indicate if the device is connected to the network.
|
||||
*
|
||||
|
|
@ -154,6 +162,8 @@ public:
|
|||
* @return SCL_SUCCESS if the Wi-Fi interface is set up successfully.
|
||||
*/
|
||||
int wifi_set_up(void);
|
||||
protected:
|
||||
int internal_scan(WiFiAccessPoint *aps, unsigned count, scan_result_type sres_type);
|
||||
|
||||
private:
|
||||
|
||||
|
|
@ -161,5 +171,6 @@ private:
|
|||
char _pass[MAX_PASSWORD_LENGTH]; /**< The longest allowed passphrase + 1 */
|
||||
nsapi_security_t _security; /**< Security type */
|
||||
SCL_EMAC &_scl_emac; /**< SCL_EMAC object */
|
||||
scl_interface_shared_info_t &_iface_shared;
|
||||
};
|
||||
#endif /* ifndef SCL_STA_INTERFACE_H */
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
|
||||
#include "SclSTAInterface.h"
|
||||
|
||||
#include "scl_interface.h"
|
||||
/** @file
|
||||
* Provides function definition to override get_target_default_intance of WiFiInterface and NetworkInterface classes
|
||||
*/
|
||||
|
|
@ -27,6 +27,7 @@
|
|||
*
|
||||
* @return pointer to WiFiInterface object.
|
||||
*/
|
||||
scl_interface_shared_info_t scl_iface_shared;
|
||||
|
||||
WiFiInterface *WiFiInterface::get_target_default_instance()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright 2018-2020 Cypress Semiconductor Corporation
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* 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 SCL_INTERFACE_H
|
||||
#define SCL_INTERFACE_H
|
||||
|
||||
#include "rtos/Mutex.h"
|
||||
#include "OnboardNetworkStack.h"
|
||||
|
||||
|
||||
/** SclSTAInterface class
|
||||
* Shared information
|
||||
*/
|
||||
#define IF_STATUS_ALL_IF_DOWN 0x0
|
||||
#define IF_STATUS_STA_UP 0x1
|
||||
|
||||
enum scl_default_interface_config
|
||||
{
|
||||
DEFAULT_IF_NOT_SET,
|
||||
DEFAULT_IF_STA,
|
||||
};
|
||||
|
||||
struct scl_interface_shared_info_t {
|
||||
rtos::Mutex mutex;
|
||||
scl_default_interface_config default_if_cfg;
|
||||
uint32_t if_status_flags;
|
||||
OnboardNetworkStack::Interface *iface_sta;
|
||||
scl_interface_shared_info_t() : default_if_cfg(DEFAULT_IF_NOT_SET), if_status_flags(IF_STATUS_ALL_IF_DOWN),
|
||||
iface_sta(NULL)
|
||||
{}
|
||||
};
|
||||
|
||||
extern scl_interface_shared_info_t scl_iface_shared;
|
||||
|
||||
#endif
|
||||
|
|
@ -175,7 +175,8 @@ typedef enum {
|
|||
SCL_RX_TEST_MSG = 1, /**< Test message */
|
||||
SCL_RX_GET_BUFFER = 2, /**< Get the buffer */
|
||||
SCL_RX_GET_CONNECTION_STATUS = 3, /**< Get the connection status */
|
||||
SCL_RX_VERSION_COMPATIBILITY = 4 /**< Get the SCL version compatibility*/
|
||||
SCL_RX_SCAN_STATUS = 4, /**< Get the scan status */
|
||||
SCL_RX_VERSION_COMPATIBILITY = 5 /**< Get the SCL version compatibility*/
|
||||
} scl_ipc_rx_t;
|
||||
|
||||
/**
|
||||
|
|
@ -197,7 +198,8 @@ typedef enum {
|
|||
SCL_TX_CONNECT = 13, /**< Wi-Fi connect */
|
||||
SCL_TX_DISCONNECT = 14, /**< Wi-Fi disconnect */
|
||||
SCL_TX_CONNECTION_STATUS = 15, /**< Transmit connection status */
|
||||
SCL_TX_SCL_VERSION_NUMBER = 16 /**< Transmit SCL version number */
|
||||
SCL_TX_SCL_VERSION_NUMBER = 16, /**< Transmit SCL version number */
|
||||
SCL_TX_SCAN = 17, /**< Wi-Fi scan */
|
||||
} scl_ipc_tx_t;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
#include "cy_result.h"
|
||||
|
||||
#include "scl_common.h"
|
||||
#ifndef INCLUDED_SCL_TYPES_H_
|
||||
#define INCLUDED_SCL_TYPES_H_
|
||||
|
||||
|
|
@ -91,6 +91,8 @@ typedef enum {
|
|||
SCL_SECURITY_WPA2_FBT_PSK = (WPA2_SECURITY | AES_ENABLED | FBT_ENABLED), /**< WPA2 FBT PSK Security with AES & TKIP */
|
||||
SCL_SECURITY_WPA3_SAE = (WPA3_SECURITY | AES_ENABLED), /**< WPA3 Security with AES */
|
||||
SCL_SECURITY_WPA3_WPA2_PSK = (WPA3_SECURITY | WPA2_SECURITY | AES_ENABLED), /**< WPA3 WPA2 PSK Security with AES */
|
||||
SCL_SECURITY_WPA2_WPA_PSK = (WPA2_SECURITY | WPA_SECURITY | AES_ENABLED), /**< WPA2 WPA PSK Security with AES */
|
||||
SCL_SECURITY_WPA2_WPA_TKIP_PSK = (WPA2_SECURITY | WPA_SECURITY | AES_ENABLED | TKIP_ENABLED), /**< WPA2 WPA PSK Security with AES & TKIP*/
|
||||
|
||||
SCL_SECURITY_WPA_TKIP_ENT = (ENTERPRISE_ENABLED | WPA_SECURITY | TKIP_ENABLED), /**< WPA Enterprise Security with TKIP */
|
||||
SCL_SECURITY_WPA_AES_ENT = (ENTERPRISE_ENABLED | WPA_SECURITY | AES_ENABLED), /**< WPA Enterprise Security with AES */
|
||||
|
|
@ -109,6 +111,160 @@ typedef enum {
|
|||
SCL_SECURITY_FORCE_32_BIT = 0x7fffffff /**< Exists only to force scl_security_t type to 32 bits */
|
||||
} scl_security_t;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Enumeration of 802.11 radio bands
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
SCL_802_11_BAND_5GHZ = 0, /**< Denotes 5GHz radio band */
|
||||
SCL_802_11_BAND_2_4GHZ = 1 /**< Denotes 2.4GHz radio band */
|
||||
} scl_802_11_band_t;
|
||||
|
||||
/** Structure for storing 802.11 powersave listen interval values \n
|
||||
* See @ref scl_wifi_get_listen_interval for more information
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t beacon; /**< Listen interval in beacon periods */
|
||||
uint8_t dtim; /**< Listen interval in DTIM periods */
|
||||
uint16_t assoc; /**< Listen interval as sent to APs */
|
||||
} scl_listen_interval_t;
|
||||
|
||||
/**
|
||||
* Enumeration of methods of scanning
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
SCL_SCAN_TYPE_ACTIVE = 0x00, /**< Actively scan a network by sending 802.11 probe(s) */
|
||||
SCL_SCAN_TYPE_PASSIVE = 0x01, /**< Passively scan a network by listening for beacons from APs */
|
||||
SCL_SCAN_TYPE_PNO = 0x02, /**< Use preferred network offload to detect an AP */
|
||||
SCL_SCAN_TYPE_PROHIBITED_CHANNELS = 0x04, /**< Permit (passively) scanning a channel that isn't valid for the current country */
|
||||
SCL_SCAN_TYPE_NO_BSSID_FILTER = 0x08 /**< Return a scan record for each beacon or probe response RX'ed */
|
||||
} scl_scan_type_t;
|
||||
|
||||
/**
|
||||
* Enumeration of network types
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
SCL_BSS_TYPE_INFRASTRUCTURE = 0, /**< Denotes infrastructure network */
|
||||
SCL_BSS_TYPE_ADHOC = 1, /**< Denotes an 802.11 ad-hoc IBSS network */
|
||||
SCL_BSS_TYPE_ANY = 2, /**< Denotes either infrastructure or ad-hoc network */
|
||||
SCL_BSS_TYPE_MESH = 3, /**< Denotes 802.11 mesh network */
|
||||
|
||||
SCL_BSS_TYPE_UNKNOWN = -1 /**< May be returned by scan function if BSS type is unknown. Do not pass this to the Join function */
|
||||
} scl_bss_type_t;
|
||||
|
||||
/**
|
||||
* Structure for storing a Service Set Identifier (i.e. Name of Access Point)
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t length; /**< SSID length */
|
||||
uint8_t value[SSID_NAME_SIZE]; /**< SSID name (AP name) */
|
||||
} scl_ssid_t;
|
||||
|
||||
/**
|
||||
* Structure for storing scan status
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
SCL_SCAN_INCOMPLETE = 0, /**< Denotes that scan is not finished */
|
||||
SCL_SCAN_COMPLETED_SUCCESSFULLY, /**< Successful completion of scan */
|
||||
SCL_SCAN_ABORTED, /**< Scan is aborted */
|
||||
} scl_scan_status_t;
|
||||
|
||||
/**
|
||||
* Structure for storing extended scan parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int32_t number_of_probes_per_channel; /**< Number of probes to send on each channel */
|
||||
int32_t scan_active_dwell_time_per_channel_ms; /**< Period of time to wait on each channel when active scanning */
|
||||
int32_t scan_passive_dwell_time_per_channel_ms; /**< Period of time to wait on each channel when passive scanning */
|
||||
int32_t scan_home_channel_dwell_time_between_channels_ms; /**< Period of time to wait on the home channel when scanning. Only relevant if associated. */
|
||||
} scl_scan_extended_params_t;
|
||||
|
||||
/**
|
||||
* Structure for storing scan results
|
||||
*/
|
||||
#pragma pack(1)
|
||||
typedef struct scl_scan_result
|
||||
{
|
||||
scl_ssid_t SSID; /**< Service Set Identification (i.e. Name of Access Point) */
|
||||
scl_mac_t BSSID; /**< Basic Service Set Identification (i.e. MAC address of Access Point) */
|
||||
int16_t signal_strength; /**< Receive Signal Strength Indication in dBm. <-90=Very poor, >-30=Excellent */
|
||||
uint32_t max_data_rate; /**< Maximum data rate in kilobits/s */
|
||||
scl_bss_type_t bss_type; /**< Network type */
|
||||
scl_security_t security; /**< Security type */
|
||||
uint8_t channel; /**< Radio channel that the AP beacon was received on */
|
||||
scl_802_11_band_t band; /**< Radio band */
|
||||
uint8_t ccode[2]; /**< Two letter ISO country code from AP */
|
||||
uint8_t flags; /**< flags */
|
||||
struct scl_scan_result *next; /**< Pointer to the next scan result */
|
||||
uint8_t *ie_ptr; /**< Pointer to received Beacon/Probe Response IE(Information Element) */
|
||||
uint32_t ie_len; /**< Length of IE(Information Element) */
|
||||
} scl_scan_result_t;
|
||||
#pragma pack()
|
||||
|
||||
/**
|
||||
* Structure to store scan result parameters for each AP
|
||||
*/
|
||||
typedef struct scl_simple_scan_result
|
||||
{
|
||||
scl_ssid_t SSID; /**< Service Set Identification (i.e. Name of Access Point) */
|
||||
scl_mac_t BSSID; /**< Basic Service Set Identification (i.e. MAC address of Access Point) */
|
||||
int16_t signal_strength; /**< Receive Signal Strength Indication in dBm. <-90=Very poor, >-30=Excellent */
|
||||
scl_security_t security; /**< Security type */
|
||||
uint8_t channel; /**< Radio channel that the AP beacon was received on */
|
||||
} scl_sync_scan_result_t;
|
||||
|
||||
typedef uint16_t wl_chanspec_t; /**< Channel specified in uint16_t */
|
||||
#define MCSSET_LEN 16 /**< Maximum allowed mcs rate */
|
||||
|
||||
/** BSS(Basic Service Set) information structure
|
||||
*
|
||||
* Applications MUST CHECK ie_offset field and length field to access IEs(Information Elements) and
|
||||
* next bss_info structure in a vector (in scl_sync_scan_result_t)
|
||||
*/
|
||||
typedef struct wl_bss_info_struct
|
||||
{
|
||||
uint32_t version; /**< version field */
|
||||
uint32_t length; /**< byte length of data in this record, starting at version and including IEs */
|
||||
scl_mac_t BSSID; /**< Unique 6-byte MAC address */
|
||||
uint16_t beacon_period; /**< Interval between two consecutive beacon frames. Units are Kusec */
|
||||
uint16_t capability; /**< Capability information */
|
||||
uint8_t SSID_len; /**< SSID length */
|
||||
uint8_t SSID[32]; /**< Array to store SSID */
|
||||
struct
|
||||
{
|
||||
uint32_t count; /**< Count of rates in this set */
|
||||
uint8_t rates[16]; /**< rates in 500kbps units, higher bit set if basic */
|
||||
} rateset; /**< supported rates */
|
||||
wl_chanspec_t chanspec; /**< Channel specification for basic service set */
|
||||
uint16_t atim_window; /**< Announcement traffic indication message window size. Units are Kusec */
|
||||
uint8_t dtim_period; /**< Delivery traffic indication message period */
|
||||
int16_t RSSI; /**< receive signal strength (in dBm) */
|
||||
int8_t phy_noise; /**< noise (in dBm) */
|
||||
|
||||
uint8_t n_cap; /**< BSS is 802.11N Capable */
|
||||
uint32_t nbss_cap; /**< 802.11N BSS Capabilities (based on HT_CAP_*) */
|
||||
uint8_t ctl_ch; /**< 802.11N BSS control channel number */
|
||||
uint32_t reserved32[1]; /**< Reserved for expansion of BSS properties */
|
||||
uint8_t flags; /**< flags */
|
||||
uint8_t reserved[3]; /**< Reserved for expansion of BSS properties */
|
||||
uint8_t basic_mcs[MCSSET_LEN]; /**< 802.11N BSS required MCS set */
|
||||
|
||||
uint16_t ie_offset; /**< offset at which IEs start, from beginning */
|
||||
uint32_t ie_length; /**< byte length of Information Elements */
|
||||
int16_t SNR; /**< Average SNR(signal to noise ratio) during frame reception */
|
||||
/* Add new fields here */
|
||||
/* variable length Information Elements */
|
||||
} wl_bss_info_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include <stdbool.h>
|
||||
#include "scl_common.h"
|
||||
#include "scl_types.h"
|
||||
#ifndef INCLUDED_SCL_WIFI_API_H
|
||||
#define INCLUDED_SCL_WIFI_API_H
|
||||
|
||||
|
|
@ -145,6 +146,54 @@ extern void scl_network_process_ethernet_data(scl_buffer_t buffer);
|
|||
*/
|
||||
extern void scl_emac_wifi_link_state_changed(bool state_up);
|
||||
|
||||
/** Scan result callback function pointer type
|
||||
*
|
||||
* @param result_ptr A pointer to the pointer that indicates where to put the next scan result
|
||||
* @param user_data User provided data
|
||||
* @param status Status of scan process
|
||||
*/
|
||||
typedef void (*scl_scan_result_callback_t)(scl_scan_result_t *result_ptr, void *user_data, scl_scan_status_t status);
|
||||
|
||||
/** Initiates a scan to search for 802.11 networks.
|
||||
*
|
||||
* The scan progressively accumulates results over time, and may take between 1 and 10 seconds to complete.
|
||||
* The results of the scan will be individually provided to the callback function.
|
||||
* Note: The callback function will be executed in the context of the SCL thread and so must not perform any
|
||||
* actions that may cause a bus transaction.
|
||||
*
|
||||
* @param scan_type Specifies whether the scan should be Active, Passive or scan Prohibited channels
|
||||
* @param bss_type Specifies whether the scan should search for Infrastructure networks (those using
|
||||
* an Access Point), Ad-hoc networks, or both types.
|
||||
* @param optional_ssid If this is non-Null, then the scan will only search for networks using the specified SSID.
|
||||
* @param optional_mac If this is non-Null, then the scan will only search for networks where
|
||||
* the BSSID (MAC address of the Access Point) matches the specified MAC address.
|
||||
* @param optional_channel_list If this is non-Null, then the scan will only search for networks on the
|
||||
* specified channels - array of channel numbers to search, terminated with a zero
|
||||
* @param optional_extended_params If this is non-Null, then the scan will obey the specifications about
|
||||
* dwell times and number of probes.
|
||||
* @param callback The callback function which will receive and process the result data.
|
||||
* @param result_ptr Pointer to a pointer to a result storage structure.
|
||||
* @param user_data user specific data that will be passed directly to the callback function
|
||||
*
|
||||
* @note - When scanning specific channels, devices with a strong signal strength on nearby channels may be detected
|
||||
* - Callback must not use blocking functions, nor use SCL functions, since it is called from the context of the
|
||||
* SCL thread.
|
||||
* - The callback, result_ptr and user_data variables will be referenced after the function returns.
|
||||
* Those variables must remain valid until the scan is complete.
|
||||
*
|
||||
* @return SCL_SUCCESS or Error code
|
||||
*/
|
||||
extern uint32_t scl_wifi_scan(scl_scan_type_t scan_type,
|
||||
scl_bss_type_t bss_type,
|
||||
const scl_ssid_t *optional_ssid,
|
||||
const scl_mac_t *optional_mac,
|
||||
const uint16_t *optional_channel_list,
|
||||
const scl_scan_extended_params_t *optional_extended_params,
|
||||
scl_scan_result_callback_t callback,
|
||||
scl_scan_result_t *result_ptr,
|
||||
void *user_data);
|
||||
|
||||
extern scl_scan_result_callback_t scan_callback;
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@
|
|||
#include "mbed_wait_api.h"
|
||||
#include "string.h"
|
||||
#include "nsapi_types.h"
|
||||
#include "scl_wifi_api.h"
|
||||
#include "scl_types.h"
|
||||
/******************************************************
|
||||
** Macros
|
||||
*******************************************************/
|
||||
|
|
@ -280,6 +282,12 @@ scl_result_t scl_end(void)
|
|||
|
||||
/** Thread to handle the received buffer
|
||||
*/
|
||||
|
||||
struct scan_callback_data {
|
||||
scl_scan_result_t *result_ptr;
|
||||
void *user_data;
|
||||
scl_scan_status_t status;
|
||||
};
|
||||
static void scl_rx_handler(void)
|
||||
{
|
||||
char *buffer = NULL;
|
||||
|
|
@ -289,6 +297,8 @@ static void scl_rx_handler(void)
|
|||
scl_buffer_t cp_buffer;
|
||||
uint32_t rx_ipc_size;
|
||||
int *rx_cp_buffer;
|
||||
struct scan_callback_data* scan_callback_data_for_cp;
|
||||
|
||||
SCL_LOG(("Starting CP Rx thread\r\n"));
|
||||
scl_receive = Cy_IPC_Drv_GetIpcBaseAddress(SCL_RX_CHANNEL);
|
||||
|
||||
|
|
@ -328,6 +338,16 @@ static void scl_rx_handler(void)
|
|||
SCL_LOG(("connection status = %d\r\n", connection_status));
|
||||
break;
|
||||
}
|
||||
case SCL_RX_SCAN_STATUS: {
|
||||
rx_cp_buffer = (int*) REG_IPC_STRUCT_DATA1(scl_receive);
|
||||
scan_callback_data_for_cp = (struct scan_callback_data*) scl_buffer_get_current_piece_data_pointer(rx_cp_buffer);
|
||||
|
||||
scan_callback(scan_callback_data_for_cp->result_ptr,scan_callback_data_for_cp->user_data,scan_callback_data_for_cp->status);
|
||||
scl_buffer_release(rx_cp_buffer,SCL_NETWORK_RX);
|
||||
REG_IPC_STRUCT_RELEASE(scl_receive) = SCL_RELEASE;
|
||||
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
SCL_LOG(("incorrect IPC from Network Processor\r\n"));
|
||||
REG_IPC_STRUCT_RELEASE(scl_receive) = SCL_RELEASE;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include "scl_wifi_api.h"
|
||||
#include "scl_ipc.h"
|
||||
#include "scl_types.h"
|
||||
|
||||
/******************************************************
|
||||
* Variables Definitions
|
||||
|
|
@ -27,6 +28,20 @@ typedef struct {
|
|||
uint32_t retval;
|
||||
} scl_mac;
|
||||
|
||||
typedef struct {
|
||||
scl_scan_type_t scan_type;
|
||||
scl_bss_type_t bss_type;
|
||||
const scl_ssid_t *optional_ssid;
|
||||
const scl_mac_t *optional_mac;
|
||||
const uint16_t *optional_channel_list;
|
||||
const scl_scan_extended_params_t *optional_extended_params;
|
||||
//scl_scan_result_callback_t callback;
|
||||
scl_scan_result_t *result_ptr;
|
||||
void *user_data;
|
||||
} scl_scan_parameters_for_np_t;
|
||||
|
||||
scl_scan_result_callback_t scan_callback;
|
||||
|
||||
/******************************************************
|
||||
* Function Definitions
|
||||
******************************************************/
|
||||
|
|
@ -158,3 +173,35 @@ scl_result_t scl_wifi_get_rssi(int32_t *rssi)
|
|||
return SCL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* NOTE: search references of function wlu_get in wl/exe/wlu.c to find what format the returned IOCTL data is.
|
||||
*/
|
||||
uint32_t scl_wifi_scan(scl_scan_type_t scan_type,
|
||||
scl_bss_type_t bss_type,
|
||||
const scl_ssid_t *optional_ssid,
|
||||
const scl_mac_t *optional_mac,
|
||||
const uint16_t *optional_channel_list,
|
||||
const scl_scan_extended_params_t *optional_extended_params,
|
||||
scl_scan_result_callback_t callback,
|
||||
scl_scan_result_t *result_ptr,
|
||||
void *user_data
|
||||
)
|
||||
{
|
||||
scl_scan_parameters_for_np_t scl_scan_parameters_for_np;
|
||||
scl_result_t retval = SCL_SUCCESS;
|
||||
/* fill the scan parameters to a structure and send it to NP */
|
||||
scl_scan_parameters_for_np.scan_type = scan_type;
|
||||
scl_scan_parameters_for_np.bss_type = bss_type;
|
||||
scl_scan_parameters_for_np.optional_ssid = optional_ssid;
|
||||
scl_scan_parameters_for_np.optional_mac = optional_mac;
|
||||
scl_scan_parameters_for_np.optional_channel_list = optional_channel_list;
|
||||
scl_scan_parameters_for_np.optional_extended_params = optional_extended_params;
|
||||
scl_scan_parameters_for_np.result_ptr = result_ptr;
|
||||
scl_scan_parameters_for_np.user_data = user_data;
|
||||
/* callback to be used when there is a scan result from CP */
|
||||
scan_callback = callback;
|
||||
/* send scan parameters to NP*/
|
||||
retval = scl_send_data(SCL_TX_SCAN, (char *)&scl_scan_parameters_for_np, TIMER_DEFAULT_VALUE);
|
||||
return retval;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue