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 /* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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]))) ((((unsigned char*)a)[5])==(((unsigned char*)b)[5])))
struct whd_scan_userdata { struct whd_scan_userdata {
Semaphore* sema; Semaphore *sema;
WiFiAccessPoint *aps; WiFiAccessPoint *aps;
vector<whd_scan_result_t> *result_buff; std::vector<whd_scan_result_t> *result_buff;
unsigned count; unsigned count;
unsigned offset; unsigned offset;
whd_interface_t ifp; 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); 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) { switch (res) {
case WHD_SUCCESS: return NSAPI_ERROR_OK; case WHD_SUCCESS:
return NSAPI_ERROR_OK;
case WHD_UNSUPPORTED: case WHD_UNSUPPORTED:
case WHD_WLAN_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_BADARG:
case WHD_WLAN_BADARG: return NSAPI_ERROR_PARAMETER; case WHD_WLAN_BADARG:
return NSAPI_ERROR_PARAMETER;
case WHD_WLAN_NOTASSOCIATED: 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_PERMANENT:
case WHD_BUFFER_UNAVAILABLE_TEMPORARY: case WHD_BUFFER_UNAVAILABLE_TEMPORARY:
case WHD_RX_BUFFER_ALLOC_FAIL: case WHD_RX_BUFFER_ALLOC_FAIL:
case WHD_BUFFER_ALLOC_FAIL: case WHD_BUFFER_ALLOC_FAIL:
case WHD_WLAN_NOMEM: 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_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_NOT_AUTHENTICATED:
case WHD_INVALID_KEY: 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_PENDING:
case WHD_JOIN_IN_PROGRESS: return NSAPI_ERROR_IN_PROGRESS; case WHD_JOIN_IN_PROGRESS:
case WHD_CONNECTION_LOST: return NSAPI_ERROR_CONNECTION_LOST; return NSAPI_ERROR_IN_PROGRESS;
case WHD_CONNECTION_LOST:
return NSAPI_ERROR_CONNECTION_LOST;
case WHD_TIMEOUT: case WHD_TIMEOUT:
case WHD_EAPOL_KEY_PACKET_M1_TIMEOUT: case WHD_EAPOL_KEY_PACKET_M1_TIMEOUT:
case WHD_EAPOL_KEY_PACKET_M3_TIMEOUT: case WHD_EAPOL_KEY_PACKET_M3_TIMEOUT:
case WHD_EAPOL_KEY_PACKET_G1_TIMEOUT: return NSAPI_ERROR_CONNECTION_TIMEOUT; case WHD_EAPOL_KEY_PACKET_G1_TIMEOUT:
case WHD_WLAN_BUSY: return NSAPI_ERROR_BUSY; return NSAPI_ERROR_CONNECTION_TIMEOUT;
case WHD_WLAN_NODEVICE: return NSAPI_ERROR_DEVICE_ERROR; case WHD_WLAN_BUSY:
default: return -res; 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) { 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_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_PSK:
case WHD_SECURITY_WPA_TKIP_ENT: return NSAPI_SECURITY_WPA; case WHD_SECURITY_WPA_TKIP_ENT:
case WHD_SECURITY_WPA2_MIXED_PSK: return NSAPI_SECURITY_WPA_WPA2; 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_PSK:
case WHD_SECURITY_WPA2_AES_ENT: case WHD_SECURITY_WPA2_AES_ENT:
case WHD_SECURITY_WPA2_FBT_PSK: 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: default:
return NSAPI_SECURITY_UNKNOWN; return NSAPI_SECURITY_UNKNOWN;
} }
} }
whd_security_t whd_fromsecurity(nsapi_security_t sec) { whd_security_t whd_fromsecurity(nsapi_security_t sec)
{
switch (sec) { switch (sec) {
case NSAPI_SECURITY_NONE: return WHD_SECURITY_OPEN; case NSAPI_SECURITY_NONE:
case NSAPI_SECURITY_WEP: return WHD_SECURITY_WEP_PSK; return WHD_SECURITY_OPEN;
case NSAPI_SECURITY_WPA: return WHD_SECURITY_WPA_MIXED_PSK; case NSAPI_SECURITY_WEP:
case NSAPI_SECURITY_WPA2: return WHD_SECURITY_WPA2_AES_PSK; return WHD_SECURITY_WEP_PSK;
case NSAPI_SECURITY_WPA_WPA2: return WHD_SECURITY_WPA2_MIXED_PSK; case NSAPI_SECURITY_WPA:
default: return WHD_SECURITY_UNKNOWN; 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( nsapi_error_t WhdSTAInterface::connect(
const char *ssid, const char *pass, const char *ssid, const char *pass,
nsapi_security_t security, nsapi_security_t security,
uint8_t channel) uint8_t channel)
{ {
int err = set_channel(channel); int err = set_channel(channel);
if (err) { 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) nsapi_error_t WhdSTAInterface::set_credentials(const char *ssid, const char *pass, nsapi_security_t security)
{ {
if ((ssid == NULL) || if ((ssid == NULL) ||
(strlen(ssid) == 0) || (strlen(ssid) == 0) ||
(pass == NULL && (security != NSAPI_SECURITY_NONE)) || (pass == NULL && (security != NSAPI_SECURITY_NONE)) ||
(strlen(pass) == 0 && ( 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(pass) > 63 && (security == NSAPI_SECURITY_WPA2 || security == NSAPI_SECURITY_WPA || security == NSAPI_SECURITY_WPA_WPA2))
) ) {
{
return NSAPI_ERROR_PARAMETER; return NSAPI_ERROR_PARAMETER;
} }
@ -177,8 +204,9 @@ nsapi_error_t WhdSTAInterface::connect()
int i; int i;
// initialize wiced, this is noop if already init // initialize wiced, this is noop if already init
if (!_whd_emac.powered_up) if (!_whd_emac.powered_up) {
_whd_emac.power_up(); _whd_emac.power_up();
}
if (!_interface) { if (!_interface) {
nsapi_error_t err = _stack.add_ethernet_interface(_emac, true, &_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 // Initialize the Offload Manager
if(_olm != NULL) { if (_olm != NULL) {
_olm->init_ols(_whd_emac.ifp, this); _olm->init_ols(_whd_emac.ifp, this);
} }
if ((_ssid == NULL) || if ((_ssid == NULL) ||
(strlen(_ssid) == 0)) { (strlen(_ssid) == 0)) {
return NSAPI_ERROR_PARAMETER; return NSAPI_ERROR_PARAMETER;
} }
// setup ssid // setup ssid
whd_ssid_t ssid; whd_ssid_t ssid;
strncpy((char*)ssid.value, _ssid, SSID_NAME_SIZE); strncpy((char *)ssid.value, _ssid, SSID_NAME_SIZE);
ssid.value[SSID_NAME_SIZE-1] = '\0'; ssid.value[SSID_NAME_SIZE - 1] = '\0';
ssid.length = strlen((char*)ssid.value); ssid.length = strlen((char *)ssid.value);
// choose network security // choose network security
whd_security_t security = whd_fromsecurity(_security); whd_security_t security = whd_fromsecurity(_security);
// join the network // join the network
whd_result_t res; whd_result_t res;
for ( i = 0; i < MAX_RETRY_COUNT; i++ ) for (i = 0; i < MAX_RETRY_COUNT; i++) {
{ res = (whd_result_t)whd_wifi_join(_whd_emac.ifp,
res = (whd_result_t)whd_wifi_join(_whd_emac.ifp, &ssid,
&ssid, security,
security, (const uint8_t *)_pass, strlen(_pass));
(const uint8_t *)_pass, strlen(_pass)); if (res == WHD_SUCCESS) {
if (res == WHD_SUCCESS) { break;
break; }
}
} }
if (res != WHD_SUCCESS) { if (res != WHD_SUCCESS) {
return whd_toerror(res); return whd_toerror(res);
} }
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);
whd_emac_wifi_link_state_changed(true, _whd_emac.ifp);
} }
// bring up // bring up
return _interface->bringup(_dhcp, return _interface->bringup(_dhcp,
_ip_address[0] ? _ip_address : 0, _ip_address[0] ? _ip_address : 0,
_netmask[0] ? _netmask : 0, _netmask[0] ? _netmask : 0,
_gateway[0] ? _gateway : 0, _gateway[0] ? _gateway : 0,
DEFAULT_STACK); DEFAULT_STACK);
} }
void WhdSTAInterface::wifi_on() void WhdSTAInterface::wifi_on()
{ {
if (!_whd_emac.powered_up) if (!_whd_emac.powered_up) {
_whd_emac.power_up(); _whd_emac.power_up();
}
} }
nsapi_error_t WhdSTAInterface::disconnect() nsapi_error_t WhdSTAInterface::disconnect()
@ -263,7 +290,7 @@ nsapi_error_t WhdSTAInterface::disconnect()
} }
// de-init Offload Manager // de-init Offload Manager
if(_olm != NULL) { if (_olm != NULL) {
_olm->deinit_ols(); _olm->deinit_ols();
} }
@ -276,8 +303,9 @@ int8_t WhdSTAInterface::get_rssi()
whd_result_t res; whd_result_t res;
// initialize wiced, this is noop if already init // initialize wiced, this is noop if already init
if (!_whd_emac.powered_up) if (!_whd_emac.powered_up) {
_whd_emac.power_up(); _whd_emac.power_up();
}
res = (whd_result_t)whd_wifi_get_rssi(_whd_emac.ifp, &rssi); res = (whd_result_t)whd_wifi_get_rssi(_whd_emac.ifp, &rssi);
if (res != 0) { if (res != 0) {
@ -287,11 +315,11 @@ int8_t WhdSTAInterface::get_rssi()
return (int8_t)rssi; return (int8_t)rssi;
} }
static void whd_scan_handler(whd_scan_result_t** result_ptr, static void whd_scan_handler(whd_scan_result_t **result_ptr,
void* user_data, whd_scan_status_t status) 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 */ /* Even after stopping scan, some results will still come as results are already present in the queue */
if (data->scan_in_progress == false) { if (data->scan_in_progress == false) {
@ -312,11 +340,12 @@ static void whd_scan_handler(whd_scan_result_t** result_ptr,
return; 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++) { for (unsigned int i = 0; i < data->result_buff->size(); i++) {
if (CMP_MAC( (*data->result_buff)[i].BSSID.octet, record->BSSID.octet )) if (CMP_MAC((*data->result_buff)[i].BSSID.octet, record->BSSID.octet)) {
return; return;
}
} }
if (data->count > 0) { if (data->count > 0) {
@ -324,8 +353,8 @@ static void whd_scan_handler(whd_scan_result_t** result_ptr,
nsapi_wifi_ap ap; nsapi_wifi_ap ap;
uint8_t length = record->SSID.length; uint8_t length = record->SSID.length;
if (length < sizeof(ap.ssid)-1) { if (length < sizeof(ap.ssid) - 1) {
length = sizeof(ap.ssid)-1; length = sizeof(ap.ssid) - 1;
} }
memcpy(ap.ssid, record->SSID.value, length); memcpy(ap.ssid, record->SSID.value, length);
ap.ssid[length] = '\0'; 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) int WhdSTAInterface::scan(WiFiAccessPoint *aps, unsigned count)
{ {
// initialize wiced, this is noop if already init // initialize wiced, this is noop if already init
if (!_whd_emac.powered_up) if (!_whd_emac.powered_up) {
_whd_emac.power_up(); _whd_emac.power_up();
}
interal_scan_data.sema = new Semaphore(); interal_scan_data.sema = new Semaphore();
interal_scan_data.aps = aps; interal_scan_data.aps = aps;
@ -357,13 +387,13 @@ int WhdSTAInterface::scan(WiFiAccessPoint *aps, unsigned count)
interal_scan_data.offset = 0; interal_scan_data.offset = 0;
interal_scan_data.ifp = _whd_emac.ifp; interal_scan_data.ifp = _whd_emac.ifp;
interal_scan_data.scan_in_progress = true; 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; whd_result_t whd_res;
int res; int res;
whd_res = (whd_result_t)whd_wifi_scan(_whd_emac.ifp, WHD_SCAN_TYPE_ACTIVE, WHD_BSS_TYPE_ANY, 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) { if (whd_res != WHD_SUCCESS) {
res = whd_toerror(whd_res); res = whd_toerror(whd_res);
} else { } else {
@ -380,99 +410,92 @@ int WhdSTAInterface::scan(WiFiAccessPoint *aps, unsigned count)
return res; return res;
} }
int WhdSTAInterface::is_interface_connected(void ) int WhdSTAInterface::is_interface_connected(void)
{ {
_whd_emac.ifp->role = WHD_STA_ROLE; _whd_emac.ifp->role = WHD_STA_ROLE;
if ( ( whd_wifi_is_ready_to_transceive( _whd_emac.ifp ) == WHD_SUCCESS ) ) if ((whd_wifi_is_ready_to_transceive(_whd_emac.ifp) == WHD_SUCCESS)) {
{ return WHD_SUCCESS;
return WHD_SUCCESS; } else {
} return WHD_CONNECTION_LOST;
else }
{
return WHD_CONNECTION_LOST;
}
} }
int WhdSTAInterface::get_bssid(uint8_t *bssid) int WhdSTAInterface::get_bssid(uint8_t *bssid)
{ {
whd_mac_t ap_mac; 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_result_t res = WHD_SUCCESS; whd_result_t res = WHD_SUCCESS;
if ( buffer != NULL )
{ memset(&ap_mac, 0, sizeof(ap_mac));
res = whd_wifi_read_wlan_log( _whd_emac.drvp, buffer, buffer_size); _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; 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; return whd_wifi_print_whd_log(_whd_emac.drvp);
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_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_result_t res = WHD_SUCCESS;
_whd_emac.ifp->role = WHD_STA_ROLE; if (buffer != NULL) {
res = whd_wifi_set_iovar_value (_whd_emac.ifp, iovar, value ); res = whd_wifi_read_wlan_log(_whd_emac.drvp, buffer, buffer_size);
return res; }
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_result_t res = WHD_SUCCESS;
_whd_emac.ifp->role = WHD_STA_ROLE; edcf_acparam_t *ac_param = (edcf_acparam_t *)acp;
res = whd_wifi_get_iovar_value ( _whd_emac.ifp, iovar, value );
return res; res = whd_wifi_get_acparams(_whd_emac.ifp, ac_param);
} if (res != WHD_SUCCESS) {
int WhdSTAInterface::wifi_set_ioctl_value( uint32_t ioctl, uint32_t value ) return res;
{ }
int res = WHD_SUCCESS; return res;
_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 WhdSTAInterface::wifi_set_iovar_value(const char *iovar, uint32_t value)
{ {
int res = WHD_SUCCESS; whd_result_t res = WHD_SUCCESS;
res = whd_wifi_set_up(_whd_emac.ifp); _whd_emac.ifp->role = WHD_STA_ROLE;
return res; 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; int res = WHD_SUCCESS;
res = whd_wifi_set_down(_whd_emac.ifp); _whd_emac.ifp->role = WHD_STA_ROLE;
return res; 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 /* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,8 +18,8 @@
#ifndef WHD_STA_INTERFACE_H #ifndef WHD_STA_INTERFACE_H
#define WHD_STA_INTERFACE_H #define WHD_STA_INTERFACE_H
#include "mbed.h" #include "netsocket/WiFiInterface.h"
#include "EthernetInterface.h" #include "netsocket/EMACInterface.h"
#include "netsocket/OnboardNetworkStack.h" #include "netsocket/OnboardNetworkStack.h"
#include "whd_emac.h" #include "whd_emac.h"
#include "whd_types_int.h" #include "whd_types_int.h"
@ -28,29 +29,36 @@ struct ol_desc;
/** WhdSTAInterface class /** WhdSTAInterface class
* Implementation of the NetworkStack for the WHD * Implementation of the NetworkStack for the WHD
*/ */
class WhdSTAInterface : public WiFiInterface, public EMACInterface class WhdSTAInterface : public WiFiInterface, public EMACInterface {
{
public: public:
class OlmInterface class OlmInterface {
{
public: public:
/** Get the default OLM interface. */ /** Get the default OLM interface. */
static OlmInterface &get_default_instance(); static OlmInterface &get_default_instance();
OlmInterface(struct ol_desc *list = NULL) {} OlmInterface(struct ol_desc *list = NULL) {}
virtual int init_ols(void *whd, void *ip) { return 0; } virtual int init_ols(void *whd, void *ip)
virtual int sleep() { return 0; } {
virtual int wake() { return 0; } return 0;
}
virtual int sleep()
{
return 0;
}
virtual int wake()
{
return 0;
}
virtual void deinit_ols(void) {} virtual void deinit_ols(void) {}
}; };
WhdSTAInterface( WhdSTAInterface(
WHD_EMAC &emac = WHD_EMAC::get_instance(), WHD_EMAC &emac = WHD_EMAC::get_instance(),
OnboardNetworkStack &stack = OnboardNetworkStack::get_default_instance(), OnboardNetworkStack &stack = OnboardNetworkStack::get_default_instance(),
OlmInterface &olm = OlmInterface::get_default_instance()); OlmInterface &olm = OlmInterface::get_default_instance());
static WhdSTAInterface *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) * @param channel Channel on which the connection is to be made, or 0 for any (Default: 0)
* @return Not supported, returns NSAPI_ERROR_UNSUPPORTED * @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) { if (channel != 0) {
return NSAPI_ERROR_UNSUPPORTED; return NSAPI_ERROR_UNSUPPORTED;
} }
@ -135,28 +144,28 @@ public:
/* print WHD log (this routine will malloc/free a buffer /* print WHD log (this routine will malloc/free a buffer
* You need to enable printing with WHD_LOGGING_BUFFER_ENABLE * You need to enable printing with WHD_LOGGING_BUFFER_ENABLE
*/ */
int whd_log_print ( void ); int whd_log_print(void);
/* read WHD log */ /* 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 */ /* 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 */ /* 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 */ /* 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 */ /* 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 */ /* set wifi interface up */
int wifi_set_up (void ); int wifi_set_up(void);
/* set wifi interface down */ /* set wifi interface down */
int wifi_set_down (void ); int wifi_set_down(void);
/** Set Offload Manager Information /** Set Offload Manager Information
* NOTE: Only allowed while disconnected * NOTE: Only allowed while disconnected
@ -165,9 +174,9 @@ public:
* @return true if completed successfully * @return true if completed successfully
* false if Interface is connected * false if Interface is connected
*/ */
int set_olm(OlmInterface *olm) { int set_olm(OlmInterface *olm)
if (get_connection_status() == NSAPI_STATUS_DISCONNECTED) {
{ if (get_connection_status() == NSAPI_STATUS_DISCONNECTED) {
_olm = olm; _olm = olm;
return true; return true;
} }
@ -178,7 +187,8 @@ public:
* *
* @return 0 if successful * @return 0 if successful
*/ */
int net_suspended() { int net_suspended()
{
int ret = _olm->sleep(); int ret = _olm->sleep();
return ret; return ret;
} }
@ -187,7 +197,8 @@ public:
* *
* @return 0 if successful * @return 0 if successful
*/ */
int net_resuming() { int net_resuming()
{
int ret = _olm->wake(); int ret = _olm->wake();
return ret; return ret;
} }
@ -196,9 +207,9 @@ private:
char _ssid[33]; /* The longest possible name (defined in 802.11) +1 for the \0 */ char _ssid[33]; /* The longest possible name (defined in 802.11) +1 for the \0 */
char _pass[64]; /* The longest allowed passphrase + 1 */ char _pass[64]; /* The longest allowed passphrase + 1 */
nsapi_security_t _security; nsapi_security_t _security;
WHD_EMAC& _whd_emac; WHD_EMAC &_whd_emac;
OlmInterface *_olm; OlmInterface *_olm;
}; };
extern int wiced_leave_ap ( int interface ); extern int wiced_leave_ap(int interface);
#endif #endif

View File

@ -1,5 +1,6 @@
/* Wiced implementation of NetworkInterfaceAPI /* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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) WhdSoftAPInterface::WhdSoftAPInterface(WHD_EMAC &emac, OnboardNetworkStack &stack)
: EMACInterface(emac, 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, 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; nsapi_error_t err;
@ -59,16 +60,16 @@ int WhdSoftAPInterface::start(const char *ssid, const char *pass, nsapi_security
// setup ssid // setup ssid
whd_ssid_t whd_ssid; whd_ssid_t whd_ssid;
strncpy((char*)whd_ssid.value, ssid, SSID_NAME_SIZE); strncpy((char *)whd_ssid.value, ssid, SSID_NAME_SIZE);
whd_ssid.value[SSID_NAME_SIZE-1] = '\0'; whd_ssid.value[SSID_NAME_SIZE - 1] = '\0';
whd_ssid.length = strlen((char*)whd_ssid.value); whd_ssid.length = strlen((char *)whd_ssid.value);
// choose network security // choose network security
whd_security_t whd_security = whd_fromsecurity(security); whd_security_t whd_security = whd_fromsecurity(security);
/* set up the AP info */ /* set up the AP info */
err = whd_wifi_init_ap(_whd_emac.ifp, &whd_ssid, whd_security, (const uint8_t*)pass, err = whd_wifi_init_ap(_whd_emac.ifp, &whd_ssid, whd_security, (const uint8_t *)pass,
strlen(pass), channel); strlen(pass), channel);
if (err != NSAPI_ERROR_OK) { if (err != NSAPI_ERROR_OK) {
printf("whd_wifi_init_ap() ERROR: %d\n", err); printf("whd_wifi_init_ap() ERROR: %d\n", err);
return err; return err;
@ -76,7 +77,7 @@ int WhdSoftAPInterface::start(const char *ssid, const char *pass, nsapi_security
if (ie_info) { if (ie_info) {
err = whd_wifi_manage_custom_ie(_whd_emac.ifp, WHD_ADD_CUSTOM_IE, (const uint8_t *)ie_info->oui, 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) { if (err != NSAPI_ERROR_OK) {
printf("whd_wifi_manage_custom_ie() ERROR: %d\n", err); printf("whd_wifi_manage_custom_ie() ERROR: %d\n", err);
return 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); printf("whd_wifi_start_ap() ERROR: %d\n", err);
return err; return err;
} }
// Set static IP address for SoftAP and bring up // Set static IP address for SoftAP and bring up
set_dhcp(false); 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); whd_emac_wifi_link_state_changed(true, _whd_emac.ifp);
} }
// bring up // bring up
err = _interface->bringup(_dhcp, err = _interface->bringup(_dhcp,
_ip_address[0] ? _ip_address : 0, _ip_address[0] ? _ip_address : 0,
_netmask[0] ? _netmask : 0, _netmask[0] ? _netmask : 0,
_gateway[0] ? _gateway : 0, _gateway[0] ? _gateway : 0,
DEFAULT_STACK); DEFAULT_STACK);
if (err != NSAPI_ERROR_OK) { if (err != NSAPI_ERROR_OK) {
printf("bringup() ERROR: %d\n", err); printf("bringup() ERROR: %d\n", err);
} }
@ -115,15 +116,15 @@ int WhdSoftAPInterface::stop(void)
return whd_wifi_stop_ap(_whd_emac.ifp); 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, 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); 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 /* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,8 +18,7 @@
#ifndef WHD_SOFTAP_INTERFACE_H #ifndef WHD_SOFTAP_INTERFACE_H
#define WHD_SOFTAP_INTERFACE_H #define WHD_SOFTAP_INTERFACE_H
#include "mbed.h" #include "netsocket/EMACInterface.h"
#include "EthernetInterface.h"
#include "netsocket/OnboardNetworkStack.h" #include "netsocket/OnboardNetworkStack.h"
#include "whd_emac.h" #include "whd_emac.h"
@ -26,11 +26,10 @@
/** /**
* Vendor IE details * Vendor IE details
*/ */
typedef struct typedef struct {
{
uint8_t oui[WIFI_IE_OUI_LENGTH]; /**< Unique identifier for the IE */ uint8_t oui[WIFI_IE_OUI_LENGTH]; /**< Unique identifier for the IE */
uint8_t subtype; /**< Sub-type of 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 length; /**< IE data length */
uint16_t which_packets; /**< Mask of the packet in which this IE details to be included */ uint16_t which_packets; /**< Mask of the packet in which this IE details to be included */
} whd_custom_ie_info_t; } whd_custom_ie_info_t;
@ -40,14 +39,13 @@ typedef struct
/** WhdSoftAPInterface class /** WhdSoftAPInterface class
* Implementation of the SoftAPInterface for the Whd * Implementation of the SoftAPInterface for the Whd
*/ */
class WhdSoftAPInterface : public EMACInterface class WhdSoftAPInterface : public EMACInterface {
{
public: public:
/** Construct SoftAP interface /** Construct SoftAP interface
* @return pointer to default WhdSoftAPInterface instance * @return pointer to default WhdSoftAPInterface instance
*/ */
WhdSoftAPInterface(WHD_EMAC &emac = WHD_EMAC::get_instance(WHD_AP_ROLE), 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. /** Get the default WhdSoftAPInterface instance.
* @return pointer to default WhdSoftAPInterface instance * @return pointer to default WhdSoftAPInterface instance
@ -79,7 +77,7 @@ public:
* see @a nsapi_error * see @a nsapi_error
*/ */
int start(const char *ssid, const char *pass, nsapi_security_t security, uint8_t channel, 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 * Remove Wi-Fi custom IE
@ -89,7 +87,7 @@ public:
* @return 0 on success, or error code on failure * @return 0 on success, or error code on failure
* see @a nsapi_error * 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 /** Stop the Software Access Point
* *
@ -97,7 +95,7 @@ public:
* see @a nsapi_error * see @a nsapi_error
*/ */
int stop(void); int stop(void);
/** /**
* Gets information about associated clients. * Gets information about associated clients.
* *
@ -109,7 +107,7 @@ public:
* @return 0 on success, or error code on failure * @return 0 on success, or error code on failure
* see @a nsapi_error * 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: protected:
WHD_EMAC& _whd_emac; WHD_EMAC &_whd_emac;
}; };
#endif #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 * SPDX-License-Identifier: Apache-2.0
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * 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 * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 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 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 * Structures
@ -56,8 +56,8 @@ typedef void (*eapol_packet_handler_t) (whd_interface_t interface, whd_buffer_t
/****************************************************** /******************************************************
* Function Declarations * Function Declarations
******************************************************/ ******************************************************/
whd_result_t emac_register_eapol_packet_handler ( eapol_packet_handler_t eapol_packet_handler ); whd_result_t emac_register_eapol_packet_handler(eapol_packet_handler_t eapol_packet_handler);
void emac_unregister_eapol_packet_handler( void ); void emac_unregister_eapol_packet_handler(void);
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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); 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_sta(WHD_STA_ROLE);
static WHD_EMAC emac_ap(WHD_AP_ROLE); static WHD_EMAC emac_ap(WHD_AP_ROLE);
return role == WHD_AP_ROLE ? emac_ap : emac_sta; 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() void WHD_EMAC::power_down()
{ {
if(powered_up) if (powered_up) {
{
powered_up = false; powered_up = false;
whd_wifi_off(ifp); whd_wifi_off(ifp);
whd_deinit(ifp); whd_deinit(ifp);
@ -93,17 +95,16 @@ void WHD_EMAC::power_down()
bool WHD_EMAC::power_up() bool WHD_EMAC::power_up()
{ {
if(!powered_up) if (!powered_up) {
{ if (CY_RSLT_SUCCESS != cybsp_wifi_init()) {
if(CY_RSLT_SUCCESS != cybsp_wifi_init()){
return false; return false;
} }
drvp = *(cybsp_get_wifi_driver()); 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; return false;
} }
powered_up = true; powered_up = true;
if (link_state && emac_link_state_cb ) { if (link_state && emac_link_state_cb) {
emac_link_state_cb(link_state); 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); 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); whd_result_t res = whd_host_buffer_get(drvp, &buffer, WHD_NETWORK_TX, size + offset, WHD_TRUE);
if ( res != WHD_SUCCESS) if (res != WHD_SUCCESS) {
{
memory_manager->free(buf); memory_manager->free(buf);
return true; return true;
} }
@ -186,86 +186,81 @@ void WHD_EMAC::set_activity_cb(mbed::Callback<void(bool)> cb)
extern "C" extern "C"
{ {
static void emac_receive_eapol_packet(whd_interface_t interface, whd_buffer_t buffer) static void emac_receive_eapol_packet(whd_interface_t interface, whd_buffer_t buffer)
{
if ( buffer != NULL )
{ {
if ( emac_eapol_packet_handler != NULL ) if (buffer != NULL) {
{ if (emac_eapol_packet_handler != NULL) {
emac_eapol_packet_handler( interface, buffer ); emac_eapol_packet_handler(interface, buffer);
} } else {
else whd_buffer_release(interface->whd_driver, buffer, WHD_NETWORK_RX);
{
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.emac_link_input_cb(mem_buf);
}
} }
} }
void whd_emac_wifi_link_state_changed(bool state_up, whd_interface_t ifp) whd_result_t emac_register_eapol_packet_handler(eapol_packet_handler_t eapol_packet_handler)
{ {
WHD_EMAC &emac = WHD_EMAC::get_instance(ifp->role);
emac.link_state = state_up; if (emac_eapol_packet_handler == NULL) {
if (emac.emac_link_state_cb ) { emac_eapol_packet_handler = eapol_packet_handler;
emac.emac_link_state_cb(state_up); 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" } // 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

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