PSOC6: apply astyle to WHD EMAC driver implementation

pull/10692/head
Volodymyr Medvid 2019-07-08 15:49:10 +03:00 committed by Volodymyr Medvid
parent 1501ffe704
commit 85a5bc0bf9
9 changed files with 352 additions and 331 deletions

View File

@ -1,5 +1,6 @@
/* WHD STAION implementation of NetworkInterfaceAPI
* Copyright (c) 2017 ARM Limited
* Copyright (c) 2017-2019 ARM Limited
* 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.
@ -35,9 +36,9 @@
((((unsigned char*)a)[5])==(((unsigned char*)b)[5])))
struct whd_scan_userdata {
Semaphore* sema;
Semaphore *sema;
WiFiAccessPoint *aps;
vector<whd_scan_result_t> *result_buff;
std::vector<whd_scan_result_t> *result_buff;
unsigned count;
unsigned offset;
whd_interface_t ifp;
@ -51,65 +52,92 @@ static whd_scan_result_t *result_ptr = &internal_scan_result;
extern "C" void whd_emac_wifi_link_state_changed(bool state_up, whd_interface_t ifp);
int whd_toerror(whd_result_t res) {
int whd_toerror(whd_result_t res)
{
switch (res) {
case WHD_SUCCESS: return NSAPI_ERROR_OK;
case WHD_SUCCESS:
return NSAPI_ERROR_OK;
case WHD_UNSUPPORTED:
case WHD_WLAN_UNSUPPORTED:
case WHD_WLAN_ACM_NOTSUPPORTED: return NSAPI_ERROR_UNSUPPORTED;
case WHD_WLAN_ACM_NOTSUPPORTED:
return NSAPI_ERROR_UNSUPPORTED;
case WHD_BADARG:
case WHD_WLAN_BADARG: return NSAPI_ERROR_PARAMETER;
case WHD_WLAN_BADARG:
return NSAPI_ERROR_PARAMETER;
case WHD_WLAN_NOTASSOCIATED:
case WHD_INVALID_JOIN_STATUS: return NSAPI_ERROR_NO_CONNECTION;
case WHD_INVALID_JOIN_STATUS:
return NSAPI_ERROR_NO_CONNECTION;
case WHD_BUFFER_UNAVAILABLE_PERMANENT:
case WHD_BUFFER_UNAVAILABLE_TEMPORARY:
case WHD_RX_BUFFER_ALLOC_FAIL:
case WHD_BUFFER_ALLOC_FAIL:
case WHD_WLAN_NOMEM:
case WHD_MALLOC_FAILURE: return NSAPI_ERROR_NO_MEMORY;
case WHD_MALLOC_FAILURE:
return NSAPI_ERROR_NO_MEMORY;
case WHD_ACCESS_POINT_NOT_FOUND:
case WHD_NETWORK_NOT_FOUND: return NSAPI_ERROR_NO_SSID;
case WHD_NETWORK_NOT_FOUND:
return NSAPI_ERROR_NO_SSID;
case WHD_NOT_AUTHENTICATED:
case WHD_INVALID_KEY:
case WHD_NOT_KEYED: return NSAPI_ERROR_AUTH_FAILURE;
case WHD_NOT_KEYED:
return NSAPI_ERROR_AUTH_FAILURE;
case WHD_PENDING:
case WHD_JOIN_IN_PROGRESS: return NSAPI_ERROR_IN_PROGRESS;
case WHD_CONNECTION_LOST: return NSAPI_ERROR_CONNECTION_LOST;
case WHD_JOIN_IN_PROGRESS:
return NSAPI_ERROR_IN_PROGRESS;
case WHD_CONNECTION_LOST:
return NSAPI_ERROR_CONNECTION_LOST;
case WHD_TIMEOUT:
case WHD_EAPOL_KEY_PACKET_M1_TIMEOUT:
case WHD_EAPOL_KEY_PACKET_M3_TIMEOUT:
case WHD_EAPOL_KEY_PACKET_G1_TIMEOUT: return NSAPI_ERROR_CONNECTION_TIMEOUT;
case WHD_WLAN_BUSY: return NSAPI_ERROR_BUSY;
case WHD_WLAN_NODEVICE: return NSAPI_ERROR_DEVICE_ERROR;
default: return -res;
case WHD_EAPOL_KEY_PACKET_G1_TIMEOUT:
return NSAPI_ERROR_CONNECTION_TIMEOUT;
case WHD_WLAN_BUSY:
return NSAPI_ERROR_BUSY;
case WHD_WLAN_NODEVICE:
return NSAPI_ERROR_DEVICE_ERROR;
default:
return -res;
}
}
static nsapi_security_t whd_tosecurity(whd_security_t sec) {
static nsapi_security_t whd_tosecurity(whd_security_t sec)
{
switch (sec) {
case WHD_SECURITY_OPEN: return NSAPI_SECURITY_NONE;
case WHD_SECURITY_OPEN:
return NSAPI_SECURITY_NONE;
case WHD_SECURITY_WEP_PSK:
case WHD_SECURITY_WEP_SHARED: return NSAPI_SECURITY_WEP;
case WHD_SECURITY_WEP_SHARED:
return NSAPI_SECURITY_WEP;
case WHD_SECURITY_WPA_TKIP_PSK:
case WHD_SECURITY_WPA_TKIP_ENT: return NSAPI_SECURITY_WPA;
case WHD_SECURITY_WPA2_MIXED_PSK: return NSAPI_SECURITY_WPA_WPA2;
case WHD_SECURITY_WPA_TKIP_ENT:
return NSAPI_SECURITY_WPA;
case WHD_SECURITY_WPA2_MIXED_PSK:
return NSAPI_SECURITY_WPA_WPA2;
case WHD_SECURITY_WPA2_AES_PSK:
case WHD_SECURITY_WPA2_AES_ENT:
case WHD_SECURITY_WPA2_FBT_PSK:
case WHD_SECURITY_WPA2_FBT_ENT: return NSAPI_SECURITY_WPA2;
case WHD_SECURITY_WPA2_FBT_ENT:
return NSAPI_SECURITY_WPA2;
default:
return NSAPI_SECURITY_UNKNOWN;
}
}
whd_security_t whd_fromsecurity(nsapi_security_t sec) {
whd_security_t whd_fromsecurity(nsapi_security_t sec)
{
switch (sec) {
case NSAPI_SECURITY_NONE: return WHD_SECURITY_OPEN;
case NSAPI_SECURITY_WEP: return WHD_SECURITY_WEP_PSK;
case NSAPI_SECURITY_WPA: return WHD_SECURITY_WPA_MIXED_PSK;
case NSAPI_SECURITY_WPA2: return WHD_SECURITY_WPA2_AES_PSK;
case NSAPI_SECURITY_WPA_WPA2: return WHD_SECURITY_WPA2_MIXED_PSK;
default: return WHD_SECURITY_UNKNOWN;
case NSAPI_SECURITY_NONE:
return WHD_SECURITY_OPEN;
case NSAPI_SECURITY_WEP:
return WHD_SECURITY_WEP_PSK;
case NSAPI_SECURITY_WPA:
return WHD_SECURITY_WPA_MIXED_PSK;
case NSAPI_SECURITY_WPA2:
return WHD_SECURITY_WPA2_AES_PSK;
case NSAPI_SECURITY_WPA_WPA2:
return WHD_SECURITY_WPA2_MIXED_PSK;
default:
return WHD_SECURITY_UNKNOWN;
}
}
@ -130,9 +158,9 @@ WhdSTAInterface::WhdSTAInterface(WHD_EMAC &emac, OnboardNetworkStack &stack, Olm
}
nsapi_error_t WhdSTAInterface::connect(
const char *ssid, const char *pass,
nsapi_security_t security,
uint8_t channel)
const char *ssid, const char *pass,
nsapi_security_t security,
uint8_t channel)
{
int err = set_channel(channel);
if (err) {
@ -150,12 +178,11 @@ nsapi_error_t WhdSTAInterface::connect(
nsapi_error_t WhdSTAInterface::set_credentials(const char *ssid, const char *pass, nsapi_security_t security)
{
if ((ssid == NULL) ||
(strlen(ssid) == 0) ||
(pass == NULL && (security != NSAPI_SECURITY_NONE)) ||
(strlen(pass) == 0 && ( security != NSAPI_SECURITY_NONE)) ||
(strlen(pass) > 63 && (security == NSAPI_SECURITY_WPA2 || security == NSAPI_SECURITY_WPA || security == NSAPI_SECURITY_WPA_WPA2))
)
{
(strlen(ssid) == 0) ||
(pass == NULL && (security != NSAPI_SECURITY_NONE)) ||
(strlen(pass) == 0 && (security != NSAPI_SECURITY_NONE)) ||
(strlen(pass) > 63 && (security == NSAPI_SECURITY_WPA2 || security == NSAPI_SECURITY_WPA || security == NSAPI_SECURITY_WPA_WPA2))
) {
return NSAPI_ERROR_PARAMETER;
}
@ -177,8 +204,9 @@ nsapi_error_t WhdSTAInterface::connect()
int i;
// initialize wiced, this is noop if already init
if (!_whd_emac.powered_up)
if (!_whd_emac.powered_up) {
_whd_emac.power_up();
}
if (!_interface) {
nsapi_error_t err = _stack.add_ethernet_interface(_emac, true, &_interface);
@ -190,58 +218,57 @@ nsapi_error_t WhdSTAInterface::connect()
}
// Initialize the Offload Manager
if(_olm != NULL) {
if (_olm != NULL) {
_olm->init_ols(_whd_emac.ifp, this);
}
if ((_ssid == NULL) ||
(strlen(_ssid) == 0)) {
(strlen(_ssid) == 0)) {
return NSAPI_ERROR_PARAMETER;
}
// setup ssid
whd_ssid_t ssid;
strncpy((char*)ssid.value, _ssid, SSID_NAME_SIZE);
ssid.value[SSID_NAME_SIZE-1] = '\0';
ssid.length = strlen((char*)ssid.value);
strncpy((char *)ssid.value, _ssid, SSID_NAME_SIZE);
ssid.value[SSID_NAME_SIZE - 1] = '\0';
ssid.length = strlen((char *)ssid.value);
// choose network security
whd_security_t security = whd_fromsecurity(_security);
// join the network
whd_result_t res;
for ( i = 0; i < MAX_RETRY_COUNT; i++ )
{
res = (whd_result_t)whd_wifi_join(_whd_emac.ifp,
&ssid,
security,
(const uint8_t *)_pass, strlen(_pass));
if (res == WHD_SUCCESS) {
break;
}
for (i = 0; i < MAX_RETRY_COUNT; i++) {
res = (whd_result_t)whd_wifi_join(_whd_emac.ifp,
&ssid,
security,
(const uint8_t *)_pass, strlen(_pass));
if (res == WHD_SUCCESS) {
break;
}
}
if (res != WHD_SUCCESS) {
return whd_toerror(res);
}
if(whd_wifi_is_ready_to_transceive(_whd_emac.ifp) == WHD_SUCCESS)
{
whd_emac_wifi_link_state_changed(true, _whd_emac.ifp);
if (whd_wifi_is_ready_to_transceive(_whd_emac.ifp) == WHD_SUCCESS) {
whd_emac_wifi_link_state_changed(true, _whd_emac.ifp);
}
// bring up
return _interface->bringup(_dhcp,
_ip_address[0] ? _ip_address : 0,
_netmask[0] ? _netmask : 0,
_gateway[0] ? _gateway : 0,
DEFAULT_STACK);
_ip_address[0] ? _ip_address : 0,
_netmask[0] ? _netmask : 0,
_gateway[0] ? _gateway : 0,
DEFAULT_STACK);
}
void WhdSTAInterface::wifi_on()
{
if (!_whd_emac.powered_up)
if (!_whd_emac.powered_up) {
_whd_emac.power_up();
}
}
nsapi_error_t WhdSTAInterface::disconnect()
@ -263,7 +290,7 @@ nsapi_error_t WhdSTAInterface::disconnect()
}
// de-init Offload Manager
if(_olm != NULL) {
if (_olm != NULL) {
_olm->deinit_ols();
}
@ -276,8 +303,9 @@ int8_t WhdSTAInterface::get_rssi()
whd_result_t res;
// initialize wiced, this is noop if already init
if (!_whd_emac.powered_up)
_whd_emac.power_up();
if (!_whd_emac.powered_up) {
_whd_emac.power_up();
}
res = (whd_result_t)whd_wifi_get_rssi(_whd_emac.ifp, &rssi);
if (res != 0) {
@ -287,11 +315,11 @@ int8_t WhdSTAInterface::get_rssi()
return (int8_t)rssi;
}
static void whd_scan_handler(whd_scan_result_t** result_ptr,
void* user_data, whd_scan_status_t status)
static void whd_scan_handler(whd_scan_result_t **result_ptr,
void *user_data, whd_scan_status_t status)
{
whd_scan_userdata *data = (whd_scan_userdata*)user_data;
whd_scan_userdata *data = (whd_scan_userdata *)user_data;
/* Even after stopping scan, some results will still come as results are already present in the queue */
if (data->scan_in_progress == false) {
@ -312,11 +340,12 @@ static void whd_scan_handler(whd_scan_result_t** result_ptr,
return;
}
whd_scan_result_t* record = *result_ptr;
whd_scan_result_t *record = *result_ptr;
for (unsigned int i=0; i<data->result_buff->size(); i++) {
if (CMP_MAC( (*data->result_buff)[i].BSSID.octet, record->BSSID.octet ))
for (unsigned int i = 0; i < data->result_buff->size(); i++) {
if (CMP_MAC((*data->result_buff)[i].BSSID.octet, record->BSSID.octet)) {
return;
}
}
if (data->count > 0) {
@ -324,8 +353,8 @@ static void whd_scan_handler(whd_scan_result_t** result_ptr,
nsapi_wifi_ap ap;
uint8_t length = record->SSID.length;
if (length < sizeof(ap.ssid)-1) {
length = sizeof(ap.ssid)-1;
if (length < sizeof(ap.ssid) - 1) {
length = sizeof(ap.ssid) - 1;
}
memcpy(ap.ssid, record->SSID.value, length);
ap.ssid[length] = '\0';
@ -348,8 +377,9 @@ static void whd_scan_handler(whd_scan_result_t** result_ptr,
int WhdSTAInterface::scan(WiFiAccessPoint *aps, unsigned count)
{
// initialize wiced, this is noop if already init
if (!_whd_emac.powered_up)
if (!_whd_emac.powered_up) {
_whd_emac.power_up();
}
interal_scan_data.sema = new Semaphore();
interal_scan_data.aps = aps;
@ -357,13 +387,13 @@ int WhdSTAInterface::scan(WiFiAccessPoint *aps, unsigned count)
interal_scan_data.offset = 0;
interal_scan_data.ifp = _whd_emac.ifp;
interal_scan_data.scan_in_progress = true;
interal_scan_data.result_buff = new vector<whd_scan_result_t>();
interal_scan_data.result_buff = new std::vector<whd_scan_result_t>();
whd_result_t whd_res;
int res;
whd_res = (whd_result_t)whd_wifi_scan(_whd_emac.ifp, WHD_SCAN_TYPE_ACTIVE, WHD_BSS_TYPE_ANY,
NULL, NULL, NULL, NULL, whd_scan_handler, (whd_scan_result_t **) &result_ptr, &interal_scan_data );
NULL, NULL, NULL, NULL, whd_scan_handler, (whd_scan_result_t **) &result_ptr, &interal_scan_data);
if (whd_res != WHD_SUCCESS) {
res = whd_toerror(whd_res);
} else {
@ -380,99 +410,92 @@ int WhdSTAInterface::scan(WiFiAccessPoint *aps, unsigned count)
return res;
}
int WhdSTAInterface::is_interface_connected(void )
int WhdSTAInterface::is_interface_connected(void)
{
_whd_emac.ifp->role = WHD_STA_ROLE;
if ( ( whd_wifi_is_ready_to_transceive( _whd_emac.ifp ) == WHD_SUCCESS ) )
{
return WHD_SUCCESS;
}
else
{
return WHD_CONNECTION_LOST;
}
_whd_emac.ifp->role = WHD_STA_ROLE;
if ((whd_wifi_is_ready_to_transceive(_whd_emac.ifp) == WHD_SUCCESS)) {
return WHD_SUCCESS;
} else {
return WHD_CONNECTION_LOST;
}
}
int WhdSTAInterface::get_bssid(uint8_t *bssid)
{
whd_mac_t ap_mac;
whd_result_t res = WHD_SUCCESS;
memset(&ap_mac, 0, sizeof(ap_mac));
_whd_emac.ifp->role = WHD_STA_ROLE;
if ( ( whd_wifi_is_ready_to_transceive( _whd_emac.ifp ) == WHD_SUCCESS ) )
{
res = whd_wifi_get_bssid(_whd_emac.ifp, &ap_mac);
if ( res == WHD_SUCCESS )
{
memcpy(bssid, ap_mac.octet, sizeof(ap_mac.octet));
}
}
return res;
}
int WhdSTAInterface::whd_log_print ( void )
{
return whd_wifi_print_whd_log( _whd_emac.drvp );
}
int WhdSTAInterface::whd_log_read ( char *buffer, int buffer_size )
{
whd_mac_t ap_mac;
whd_result_t res = WHD_SUCCESS;
if ( buffer != NULL )
{
res = whd_wifi_read_wlan_log( _whd_emac.drvp, buffer, buffer_size);
memset(&ap_mac, 0, sizeof(ap_mac));
_whd_emac.ifp->role = WHD_STA_ROLE;
if ((whd_wifi_is_ready_to_transceive(_whd_emac.ifp) == WHD_SUCCESS)) {
res = whd_wifi_get_bssid(_whd_emac.ifp, &ap_mac);
if (res == WHD_SUCCESS) {
memcpy(bssid, ap_mac.octet, sizeof(ap_mac.octet));
}
}
return res;
}
nsapi_error_t WhdSTAInterface::wifi_get_ac_params_sta(void *acp )
int WhdSTAInterface::whd_log_print(void)
{
whd_result_t res = WHD_SUCCESS;
edcf_acparam_t *ac_param = ( edcf_acparam_t * )acp;
res = whd_wifi_get_acparams(_whd_emac.ifp, ac_param );
if ( res != WHD_SUCCESS )
{
return res;
}
return res;
return whd_wifi_print_whd_log(_whd_emac.drvp);
}
int WhdSTAInterface::wifi_set_iovar_value ( const char *iovar, uint32_t value )
int WhdSTAInterface::whd_log_read(char *buffer, int buffer_size)
{
whd_result_t res = WHD_SUCCESS;
_whd_emac.ifp->role = WHD_STA_ROLE;
res = whd_wifi_set_iovar_value (_whd_emac.ifp, iovar, value );
return res;
whd_result_t res = WHD_SUCCESS;
if (buffer != NULL) {
res = whd_wifi_read_wlan_log(_whd_emac.drvp, buffer, buffer_size);
}
return res;
}
int WhdSTAInterface::wifi_get_iovar_value ( const char *iovar, uint32_t *value )
nsapi_error_t WhdSTAInterface::wifi_get_ac_params_sta(void *acp)
{
int res = WHD_SUCCESS;
_whd_emac.ifp->role = WHD_STA_ROLE;
res = whd_wifi_get_iovar_value ( _whd_emac.ifp, iovar, value );
return res;
}
int WhdSTAInterface::wifi_set_ioctl_value( uint32_t ioctl, uint32_t value )
{
int res = WHD_SUCCESS;
_whd_emac.ifp->role = WHD_STA_ROLE;
res = whd_wifi_set_ioctl_value(_whd_emac.ifp, ioctl, value );
return res;
whd_result_t res = WHD_SUCCESS;
edcf_acparam_t *ac_param = (edcf_acparam_t *)acp;
res = whd_wifi_get_acparams(_whd_emac.ifp, ac_param);
if (res != WHD_SUCCESS) {
return res;
}
return res;
}
int WhdSTAInterface::wifi_set_up ( void )
int WhdSTAInterface::wifi_set_iovar_value(const char *iovar, uint32_t value)
{
int res = WHD_SUCCESS;
res = whd_wifi_set_up(_whd_emac.ifp);
return res;
whd_result_t res = WHD_SUCCESS;
_whd_emac.ifp->role = WHD_STA_ROLE;
res = whd_wifi_set_iovar_value(_whd_emac.ifp, iovar, value);
return res;
}
int WhdSTAInterface::wifi_set_down ( void )
int WhdSTAInterface::wifi_get_iovar_value(const char *iovar, uint32_t *value)
{
int res = WHD_SUCCESS;
res = whd_wifi_set_down(_whd_emac.ifp);
return res;
int res = WHD_SUCCESS;
_whd_emac.ifp->role = WHD_STA_ROLE;
res = whd_wifi_get_iovar_value(_whd_emac.ifp, iovar, value);
return res;
}
int WhdSTAInterface::wifi_set_ioctl_value(uint32_t ioctl, uint32_t value)
{
int res = WHD_SUCCESS;
_whd_emac.ifp->role = WHD_STA_ROLE;
res = whd_wifi_set_ioctl_value(_whd_emac.ifp, ioctl, value);
return res;
}
int WhdSTAInterface::wifi_set_up(void)
{
int res = WHD_SUCCESS;
res = whd_wifi_set_up(_whd_emac.ifp);
return res;
}
int WhdSTAInterface::wifi_set_down(void)
{
int res = WHD_SUCCESS;
res = whd_wifi_set_down(_whd_emac.ifp);
return res;
}

View File

@ -1,5 +1,6 @@
/* WHD implementation of NetworkInterfaceAPI
* Copyright (c) 2017 ARM Limited
* Copyright (c) 2017-2019 ARM Limited
* 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.
@ -17,8 +18,8 @@
#ifndef WHD_STA_INTERFACE_H
#define WHD_STA_INTERFACE_H
#include "mbed.h"
#include "EthernetInterface.h"
#include "netsocket/WiFiInterface.h"
#include "netsocket/EMACInterface.h"
#include "netsocket/OnboardNetworkStack.h"
#include "whd_emac.h"
#include "whd_types_int.h"
@ -28,29 +29,36 @@ struct ol_desc;
/** WhdSTAInterface class
* Implementation of the NetworkStack for the WHD
*/
class WhdSTAInterface : public WiFiInterface, public EMACInterface
{
class WhdSTAInterface : public WiFiInterface, public EMACInterface {
public:
class OlmInterface
{
class OlmInterface {
public:
/** Get the default OLM interface. */
static OlmInterface &get_default_instance();
OlmInterface(struct ol_desc *list = NULL) {}
virtual int init_ols(void *whd, void *ip) { return 0; }
virtual int sleep() { return 0; }
virtual int wake() { return 0; }
virtual int init_ols(void *whd, void *ip)
{
return 0;
}
virtual int sleep()
{
return 0;
}
virtual int wake()
{
return 0;
}
virtual void deinit_ols(void) {}
};
WhdSTAInterface(
WHD_EMAC &emac = WHD_EMAC::get_instance(),
OnboardNetworkStack &stack = OnboardNetworkStack::get_default_instance(),
OlmInterface &olm = OlmInterface::get_default_instance());
WHD_EMAC &emac = WHD_EMAC::get_instance(),
OnboardNetworkStack &stack = OnboardNetworkStack::get_default_instance(),
OlmInterface &olm = OlmInterface::get_default_instance());
static WhdSTAInterface *get_default_instance();
@ -100,7 +108,8 @@ public:
* @param channel Channel on which the connection is to be made, or 0 for any (Default: 0)
* @return Not supported, returns NSAPI_ERROR_UNSUPPORTED
*/
nsapi_error_t set_channel(uint8_t channel) {
nsapi_error_t set_channel(uint8_t channel)
{
if (channel != 0) {
return NSAPI_ERROR_UNSUPPORTED;
}
@ -135,28 +144,28 @@ public:
/* print WHD log (this routine will malloc/free a buffer
* You need to enable printing with WHD_LOGGING_BUFFER_ENABLE
*/
int whd_log_print ( void );
int whd_log_print(void);
/* read WHD log */
int whd_log_read ( char *buffer, int buffer_size );
int whd_log_read(char *buffer, int buffer_size);
/* Get EDCF AC params */
nsapi_error_t wifi_get_ac_params_sta(void * ac_param );
nsapi_error_t wifi_get_ac_params_sta(void *ac_param);
/* get iovar value */
int wifi_get_iovar_value ( const char *iovar, uint32_t *value );
int wifi_get_iovar_value(const char *iovar, uint32_t *value);
/* set iovar value */
int wifi_set_iovar_value ( const char *iovar, uint32_t value );
int wifi_set_iovar_value(const char *iovar, uint32_t value);
/* set ioctl value */
int wifi_set_ioctl_value( uint32_t ioctl, uint32_t value ) ;
int wifi_set_ioctl_value(uint32_t ioctl, uint32_t value) ;
/* set wifi interface up */
int wifi_set_up (void );
int wifi_set_up(void);
/* set wifi interface down */
int wifi_set_down (void );
int wifi_set_down(void);
/** Set Offload Manager Information
* NOTE: Only allowed while disconnected
@ -165,9 +174,9 @@ public:
* @return true if completed successfully
* false if Interface is connected
*/
int set_olm(OlmInterface *olm) {
if (get_connection_status() == NSAPI_STATUS_DISCONNECTED)
{
int set_olm(OlmInterface *olm)
{
if (get_connection_status() == NSAPI_STATUS_DISCONNECTED) {
_olm = olm;
return true;
}
@ -178,7 +187,8 @@ public:
*
* @return 0 if successful
*/
int net_suspended() {
int net_suspended()
{
int ret = _olm->sleep();
return ret;
}
@ -187,7 +197,8 @@ public:
*
* @return 0 if successful
*/
int net_resuming() {
int net_resuming()
{
int ret = _olm->wake();
return ret;
}
@ -196,9 +207,9 @@ private:
char _ssid[33]; /* The longest possible name (defined in 802.11) +1 for the \0 */
char _pass[64]; /* The longest allowed passphrase + 1 */
nsapi_security_t _security;
WHD_EMAC& _whd_emac;
WHD_EMAC &_whd_emac;
OlmInterface *_olm;
};
extern int wiced_leave_ap ( int interface );
extern int wiced_leave_ap(int interface);
#endif

View File

@ -1,5 +1,6 @@
/* Wiced implementation of NetworkInterfaceAPI
* Copyright (c) 2017 ARM Limited
* Copyright (c) 2017-2019 ARM Limited
* 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.
@ -36,14 +37,14 @@ static uint16_t ap_event_entry = 2;
WhdSoftAPInterface::WhdSoftAPInterface(WHD_EMAC &emac, OnboardNetworkStack &stack)
: EMACInterface(emac, stack),
_whd_emac(emac)
_whd_emac(emac)
{
}
int WhdSoftAPInterface::start(const char *ssid, const char *pass, nsapi_security_t security, uint8_t channel,
bool start_dhcp_server, const whd_custom_ie_info_t* ie_info)
bool start_dhcp_server, const whd_custom_ie_info_t *ie_info)
{
nsapi_error_t err;
@ -59,16 +60,16 @@ int WhdSoftAPInterface::start(const char *ssid, const char *pass, nsapi_security
// setup ssid
whd_ssid_t whd_ssid;
strncpy((char*)whd_ssid.value, ssid, SSID_NAME_SIZE);
whd_ssid.value[SSID_NAME_SIZE-1] = '\0';
whd_ssid.length = strlen((char*)whd_ssid.value);
strncpy((char *)whd_ssid.value, ssid, SSID_NAME_SIZE);
whd_ssid.value[SSID_NAME_SIZE - 1] = '\0';
whd_ssid.length = strlen((char *)whd_ssid.value);
// choose network security
whd_security_t whd_security = whd_fromsecurity(security);
/* set up the AP info */
err = whd_wifi_init_ap(_whd_emac.ifp, &whd_ssid, whd_security, (const uint8_t*)pass,
strlen(pass), channel);
err = whd_wifi_init_ap(_whd_emac.ifp, &whd_ssid, whd_security, (const uint8_t *)pass,
strlen(pass), channel);
if (err != NSAPI_ERROR_OK) {
printf("whd_wifi_init_ap() ERROR: %d\n", err);
return err;
@ -76,7 +77,7 @@ int WhdSoftAPInterface::start(const char *ssid, const char *pass, nsapi_security
if (ie_info) {
err = whd_wifi_manage_custom_ie(_whd_emac.ifp, WHD_ADD_CUSTOM_IE, (const uint8_t *)ie_info->oui,
ie_info->subtype, (const void *)ie_info->data, ie_info->length, ie_info->which_packets);
ie_info->subtype, (const void *)ie_info->data, ie_info->length, ie_info->which_packets);
if (err != NSAPI_ERROR_OK) {
printf("whd_wifi_manage_custom_ie() ERROR: %d\n", err);
return err;
@ -88,20 +89,20 @@ int WhdSoftAPInterface::start(const char *ssid, const char *pass, nsapi_security
printf("whd_wifi_start_ap() ERROR: %d\n", err);
return err;
}
// Set static IP address for SoftAP and bring up
set_dhcp(false);
if(whd_wifi_is_ready_to_transceive(_whd_emac.ifp) == WHD_SUCCESS) {
if (whd_wifi_is_ready_to_transceive(_whd_emac.ifp) == WHD_SUCCESS) {
whd_emac_wifi_link_state_changed(true, _whd_emac.ifp);
}
// bring up
err = _interface->bringup(_dhcp,
_ip_address[0] ? _ip_address : 0,
_netmask[0] ? _netmask : 0,
_gateway[0] ? _gateway : 0,
DEFAULT_STACK);
_ip_address[0] ? _ip_address : 0,
_netmask[0] ? _netmask : 0,
_gateway[0] ? _gateway : 0,
DEFAULT_STACK);
if (err != NSAPI_ERROR_OK) {
printf("bringup() ERROR: %d\n", err);
}
@ -115,15 +116,15 @@ int WhdSoftAPInterface::stop(void)
return whd_wifi_stop_ap(_whd_emac.ifp);
}
int WhdSoftAPInterface::remove_custom_ie(const whd_custom_ie_info_t* ie_info)
int WhdSoftAPInterface::remove_custom_ie(const whd_custom_ie_info_t *ie_info)
{
return whd_wifi_manage_custom_ie(_whd_emac.ifp, WHD_REMOVE_CUSTOM_IE, (const uint8_t *)ie_info->oui,
ie_info->subtype, (const void *)ie_info->data, ie_info->length, ie_info->which_packets);
ie_info->subtype, (const void *)ie_info->data, ie_info->length, ie_info->which_packets);
}
int WhdSoftAPInterface::get_associated_client_list(void* client_list_buffer, uint16_t buffer_length)
int WhdSoftAPInterface::get_associated_client_list(void *client_list_buffer, uint16_t buffer_length)
{
return whd_wifi_get_associated_client_list(_whd_emac.ifp, client_list_buffer, buffer_length);
}

View File

@ -1,5 +1,6 @@
/* WHD SoftAP implementation of SoftAPInterface
* Copyright (c) 2017 ARM Limited
* Copyright (c) 2017-2019 ARM Limited
* 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.
@ -17,8 +18,7 @@
#ifndef WHD_SOFTAP_INTERFACE_H
#define WHD_SOFTAP_INTERFACE_H
#include "mbed.h"
#include "EthernetInterface.h"
#include "netsocket/EMACInterface.h"
#include "netsocket/OnboardNetworkStack.h"
#include "whd_emac.h"
@ -26,11 +26,10 @@
/**
* Vendor IE details
*/
typedef struct
{
typedef struct {
uint8_t oui[WIFI_IE_OUI_LENGTH]; /**< Unique identifier for the IE */
uint8_t subtype; /**< Sub-type of the IE */
void* data; /**< Pointer to IE data */
void *data; /**< Pointer to IE data */
uint16_t length; /**< IE data length */
uint16_t which_packets; /**< Mask of the packet in which this IE details to be included */
} whd_custom_ie_info_t;
@ -40,14 +39,13 @@ typedef struct
/** WhdSoftAPInterface class
* Implementation of the SoftAPInterface for the Whd
*/
class WhdSoftAPInterface : public EMACInterface
{
class WhdSoftAPInterface : public EMACInterface {
public:
/** Construct SoftAP interface
/** Construct SoftAP interface
* @return pointer to default WhdSoftAPInterface instance
*/
WhdSoftAPInterface(WHD_EMAC &emac = WHD_EMAC::get_instance(WHD_AP_ROLE),
OnboardNetworkStack &stack = OnboardNetworkStack::get_default_instance());
OnboardNetworkStack &stack = OnboardNetworkStack::get_default_instance());
/** Get the default WhdSoftAPInterface instance.
* @return pointer to default WhdSoftAPInterface instance
@ -79,7 +77,7 @@ public:
* see @a nsapi_error
*/
int start(const char *ssid, const char *pass, nsapi_security_t security, uint8_t channel,
bool start_dhcp_server = true, const whd_custom_ie_info_t* ie_info = NULL);
bool start_dhcp_server = true, const whd_custom_ie_info_t *ie_info = NULL);
/**
* Remove Wi-Fi custom IE
@ -89,7 +87,7 @@ public:
* @return 0 on success, or error code on failure
* see @a nsapi_error
*/
int remove_custom_ie(const whd_custom_ie_info_t* ie_info);
int remove_custom_ie(const whd_custom_ie_info_t *ie_info);
/** Stop the Software Access Point
*
@ -97,7 +95,7 @@ public:
* see @a nsapi_error
*/
int stop(void);
/**
* Gets information about associated clients.
*
@ -109,7 +107,7 @@ public:
* @return 0 on success, or error code on failure
* see @a nsapi_error
*/
int get_associated_client_list(void* client_list_buffer, uint16_t buffer_length);
int get_associated_client_list(void *client_list_buffer, uint16_t buffer_length);
/**
@ -132,7 +130,7 @@ public:
protected:
WHD_EMAC& _whd_emac;
WHD_EMAC &_whd_emac;
};
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* Copyright (c) 2018-2019, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -7,7 +7,7 @@
* 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.
@ -43,7 +43,7 @@ extern "C"
typedef whd_buffer_t whd_eapol_packet_t;
typedef void (*eapol_packet_handler_t) (whd_interface_t interface, whd_buffer_t buffer);
typedef void (*eapol_packet_handler_t)(whd_interface_t interface, whd_buffer_t buffer);
/******************************************************
* Structures
@ -56,8 +56,8 @@ typedef void (*eapol_packet_handler_t) (whd_interface_t interface, whd_buffer_t
/******************************************************
* Function Declarations
******************************************************/
whd_result_t emac_register_eapol_packet_handler ( eapol_packet_handler_t eapol_packet_handler );
void emac_unregister_eapol_packet_handler( void );
whd_result_t emac_register_eapol_packet_handler(eapol_packet_handler_t eapol_packet_handler);
void emac_unregister_eapol_packet_handler(void);
#ifdef __cplusplus
} /* extern "C" */

View File

@ -1,5 +1,6 @@
/*
* Copyright (c) 2018 ARM Limited
* Copyright (c) 2018-2019 ARM Limited
* 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.
@ -45,11 +46,13 @@ WHD_EMAC::WHD_EMAC()
{
}
WHD_EMAC &WHD_EMAC::get_instance() {
WHD_EMAC &WHD_EMAC::get_instance()
{
return get_instance(WHD_STA_ROLE);
}
WHD_EMAC &WHD_EMAC::get_instance(whd_interface_role_t role) {
WHD_EMAC &WHD_EMAC::get_instance(whd_interface_role_t role)
{
static WHD_EMAC emac_sta(WHD_STA_ROLE);
static WHD_EMAC emac_ap(WHD_AP_ROLE);
return role == WHD_AP_ROLE ? emac_ap : emac_sta;
@ -83,8 +86,7 @@ void WHD_EMAC::set_all_multicast(bool all)
void WHD_EMAC::power_down()
{
if(powered_up)
{
if (powered_up) {
powered_up = false;
whd_wifi_off(ifp);
whd_deinit(ifp);
@ -93,17 +95,16 @@ void WHD_EMAC::power_down()
bool WHD_EMAC::power_up()
{
if(!powered_up)
{
if(CY_RSLT_SUCCESS != cybsp_wifi_init()){
if (!powered_up) {
if (CY_RSLT_SUCCESS != cybsp_wifi_init()) {
return false;
}
drvp = *(cybsp_get_wifi_driver());
if(WHD_SUCCESS != whd_wifi_on(drvp, &ifp /* OUT */)){
if (WHD_SUCCESS != whd_wifi_on(drvp, &ifp /* OUT */)) {
return false;
}
powered_up = true;
if (link_state && emac_link_state_cb ) {
if (link_state && emac_link_state_cb) {
emac_link_state_cb(link_state);
}
}
@ -152,9 +153,8 @@ bool WHD_EMAC::link_out(emac_mem_buf_t *buf)
uint16_t size = memory_manager->get_total_len(buf);
whd_result_t res = whd_host_buffer_get(drvp, &buffer, WHD_NETWORK_TX, size+offset, WHD_TRUE);
if ( res != WHD_SUCCESS)
{
whd_result_t res = whd_host_buffer_get(drvp, &buffer, WHD_NETWORK_TX, size + offset, WHD_TRUE);
if (res != WHD_SUCCESS) {
memory_manager->free(buf);
return true;
}
@ -186,86 +186,81 @@ void WHD_EMAC::set_activity_cb(mbed::Callback<void(bool)> cb)
extern "C"
{
static void emac_receive_eapol_packet(whd_interface_t interface, whd_buffer_t buffer)
{
if ( buffer != NULL )
static void emac_receive_eapol_packet(whd_interface_t interface, whd_buffer_t buffer)
{
if ( emac_eapol_packet_handler != NULL )
{
if (buffer != NULL) {
if (emac_eapol_packet_handler != NULL) {
emac_eapol_packet_handler( interface, buffer );
}
else
{
whd_buffer_release( interface->whd_driver,buffer, WHD_NETWORK_RX );
}
}
}
whd_result_t emac_register_eapol_packet_handler( eapol_packet_handler_t eapol_packet_handler )
{
if ( emac_eapol_packet_handler == NULL )
{
emac_eapol_packet_handler = eapol_packet_handler;
return WHD_SUCCESS;
}
return WHD_HANDLER_ALREADY_REGISTERED;
}
void emac_unregister_eapol_packet_handler( void )
{
emac_eapol_packet_handler = NULL;
}
void cy_network_process_ethernet_data(whd_interface_t ifp, whd_buffer_t buffer)
{
emac_mem_buf_t *mem_buf = NULL;
WHD_EMAC &emac = WHD_EMAC::get_instance(ifp->role);
if (!emac.powered_up && !emac.emac_link_input_cb) {
// ignore any trailing packets
whd_buffer_release(emac.drvp, buffer, WHD_NETWORK_RX);
return;
}
uint8_t *data = whd_buffer_get_current_piece_data_pointer(emac.drvp, buffer);
uint16_t size = whd_buffer_get_current_piece_size(emac.drvp, buffer);
if (size > WHD_ETHERNET_SIZE ) {
uint16_t ethertype;
ethertype = (uint16_t) (data[12] << 8 | data[13]);
if (ethertype == EAPOL_PACKET_TYPE) {
/* pass it to the EAP layer, but do not release the packet */
emac_receive_eapol_packet(ifp,buffer);
} else {
mem_buf = buffer;
if (emac.activity_cb) {
emac.activity_cb(false);
emac_eapol_packet_handler(interface, buffer);
} else {
whd_buffer_release(interface->whd_driver, buffer, WHD_NETWORK_RX);
}
emac.emac_link_input_cb(mem_buf);
}
}
}
void whd_emac_wifi_link_state_changed(bool state_up, whd_interface_t ifp)
{
WHD_EMAC &emac = WHD_EMAC::get_instance(ifp->role);
whd_result_t emac_register_eapol_packet_handler(eapol_packet_handler_t eapol_packet_handler)
{
emac.link_state = state_up;
if (emac.emac_link_state_cb ) {
emac.emac_link_state_cb(state_up);
if (emac_eapol_packet_handler == NULL) {
emac_eapol_packet_handler = eapol_packet_handler;
return WHD_SUCCESS;
}
return WHD_HANDLER_ALREADY_REGISTERED;
}
void emac_unregister_eapol_packet_handler(void)
{
emac_eapol_packet_handler = NULL;
}
void cy_network_process_ethernet_data(whd_interface_t ifp, whd_buffer_t buffer)
{
emac_mem_buf_t *mem_buf = NULL;
WHD_EMAC &emac = WHD_EMAC::get_instance(ifp->role);
if (!emac.powered_up && !emac.emac_link_input_cb) {
// ignore any trailing packets
whd_buffer_release(emac.drvp, buffer, WHD_NETWORK_RX);
return;
}
uint8_t *data = whd_buffer_get_current_piece_data_pointer(emac.drvp, buffer);
uint16_t size = whd_buffer_get_current_piece_size(emac.drvp, buffer);
if (size > WHD_ETHERNET_SIZE) {
uint16_t ethertype;
ethertype = (uint16_t)(data[12] << 8 | data[13]);
if (ethertype == EAPOL_PACKET_TYPE) {
/* pass it to the EAP layer, but do not release the packet */
emac_receive_eapol_packet(ifp, buffer);
} else {
mem_buf = buffer;
if (emac.activity_cb) {
emac.activity_cb(false);
}
emac.emac_link_input_cb(mem_buf);
}
}
}
void whd_emac_wifi_link_state_changed(bool state_up, whd_interface_t ifp)
{
WHD_EMAC &emac = WHD_EMAC::get_instance(ifp->role);
emac.link_state = state_up;
if (emac.emac_link_state_cb) {
emac.emac_link_state_cb(state_up);
}
}
}
} // extern "C"

View File

@ -1,5 +1,6 @@
/*
* Copyright (c) 2018 ARM Limited
* Copyright (c) 2018-2019 ARM Limited
* 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.

View File

@ -1,5 +1,6 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
* 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.
@ -48,17 +49,15 @@ extern "C"
* Enumerations
******************************************************/
typedef enum
{
typedef enum {
WICED_SOCKET_ERROR
} wiced_socket_state_t;
/******************************************************
* Type Definitions
******************************************************/
typedef struct
{
uint8_t* payload;
typedef struct {
uint8_t *payload;
uint16_t len;
uint16_t pktstart;
} wiced_packet_t;
@ -69,7 +68,7 @@ typedef struct
//typedef NOOS_DUMMY wiced_tls_session_t;
//typedef NOOS_DUMMY wiced_tls_certificate_t;
//typedef NOOS_DUMMY wiced_tls_endpoint_type_t;
typedef void* NOOS_TCP_SOCKET;
typedef void *NOOS_TCP_SOCKET;
/******************************************************
* Structures
@ -78,54 +77,47 @@ typedef void* NOOS_TCP_SOCKET;
typedef struct wiced_tcp_socket_struct wiced_tcp_socket_t;
typedef struct wiced_udp_socket_struct wiced_udp_socket_t;
typedef wiced_result_t (*wiced_tcp_socket_callback_t)( wiced_tcp_socket_t* socket, void* arg );
typedef wiced_result_t (*wiced_udp_socket_callback_t)( wiced_udp_socket_t* socket, void* arg );
typedef wiced_result_t (*wiced_tcp_socket_callback_t)(wiced_tcp_socket_t *socket, void *arg);
typedef wiced_result_t (*wiced_udp_socket_callback_t)(wiced_udp_socket_t *socket, void *arg);
struct wiced_udp_socket_struct
{
wiced_dtls_context_t* dtls_context;
struct
{
struct wiced_udp_socket_struct {
wiced_dtls_context_t *dtls_context;
struct {
wiced_tcp_socket_callback_t disconnect;
wiced_tcp_socket_callback_t receive;
wiced_tcp_socket_callback_t connect;
} callbacks;
void* callback_arg;
void *callback_arg;
};
struct wiced_tcp_socket_struct
{
struct wiced_tcp_socket_struct {
NOOS_TCP_SOCKET socket;
wiced_tls_context_t* tls_context;
wiced_tls_context_t *tls_context;
wiced_bool_t context_malloced;
struct
{
struct {
wiced_tcp_socket_callback_t disconnect;
wiced_tcp_socket_callback_t receive;
wiced_tcp_socket_callback_t connect;
} callbacks;
void* callback_arg;
void *callback_arg;
};
typedef struct
{
typedef struct {
wiced_tcp_socket_t socket[WICED_MAXIMUM_NUMBER_OF_SERVER_SOCKETS];
int interface;
uint16_t port;
wiced_tls_identity_t* tls_identity;
wiced_tls_identity_t *tls_identity;
} wiced_tcp_server_t;
/******************************************************
* Global Variables
******************************************************/
typedef struct
{
typedef struct {
int dummy;
}NOOS_IP;
typedef struct
{
} NOOS_IP;
typedef struct {
int dummy;
}NOOS_PACKET_POOL;
} NOOS_PACKET_POOL;
/*
* Note: These objects are for internal use only!
*/