Add COMPONENT_SCL.

pull/12603/head
Dustin Crossman 2020-03-02 15:04:56 -08:00
parent 89549e7bc9
commit e754510cce
16 changed files with 2612 additions and 0 deletions

View File

@ -0,0 +1,347 @@
/*
* (c) (2019-2020), Cypress Semiconductor Corporation. All rights reserved.
*
* This software, including source code, documentation and related materials
* ("Software"), is owned by Cypress Semiconductor Corporation or one of its
* subsidiaries ("Cypress") and is protected by and subject to worldwide patent
* protection (United States and foreign), United States copyright laws and
* international treaty provisions. Therefore, you may use this Software only
* as provided in the license agreement accompanying the software package from
* which you obtained this Software ("EULA").
*
* If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
* non-transferable license to copy, modify, and compile the Software source
* code solely for use in connection with Cypress's integrated circuit products.
* Any reproduction, modification, translation, compilation, or representation
* of this Software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
* reserves the right to make changes to the Software without notice. Cypress
* does not assume any liability arising out of the application or use of the
* Software or any product or circuit described in the Software. Cypress does
* not authorize its products for use in any products where a malfunction or
* failure of the Cypress product may reasonably be expected to result in
* significant property damage, injury or death ("High Risk Product"). By
* including Cypress's product in a High Risk Product, the manufacturer of such
* system or application assumes all risk of such use and in doing so agrees to
* indemnify Cypress against all liability.
*/
#include <cstring>
#include <algorithm>
#include <vector>
#include "SclSTAInterface.h"
#include "nsapi.h"
#include "lwipopts.h"
#include "lwip/etharp.h"
#include "lwip/ethip6.h"
#include "rtos.h"
#include "scl_emac.h"
#include "scl_ipc.h"
#include "mbed_wait_api.h"
#define PARAM_LEN (20)
struct network_params_t {
char ip_address[PARAM_LEN];
char netmask[PARAM_LEN];
char gateway[PARAM_LEN];
int connection_status;
};
struct scl_tx_nw_credentials {
nsapi_security_t network_security_type;
int ssid_len;
int pass_len;
const char* network_ssid;
const char* network_passphrase;
} scl_tx_nw_credentials_t;
struct network_params_t network_parameter;
int scl_toerror(scl_result_t res)
{
switch (res) {
case SCL_SUCCESS:
return NSAPI_ERROR_OK;
case SCL_UNSUPPORTED:
return NSAPI_ERROR_UNSUPPORTED;
case SCL_BADARG:
return NSAPI_ERROR_PARAMETER;
case SCL_INVALID_JOIN_STATUS:
return NSAPI_ERROR_NO_CONNECTION;
case SCL_BUFFER_UNAVAILABLE_PERMANENT:
case SCL_BUFFER_UNAVAILABLE_TEMPORARY:
case SCL_RX_BUFFER_ALLOC_FAIL:
case SCL_BUFFER_ALLOC_FAIL:
case SCL_MALLOC_FAILURE:
return NSAPI_ERROR_NO_MEMORY;
case SCL_ACCESS_POINT_NOT_FOUND:
case SCL_NETWORK_NOT_FOUND:
return NSAPI_ERROR_NO_SSID;
case SCL_NOT_AUTHENTICATED:
case SCL_INVALID_KEY:
case SCL_NOT_KEYED:
return NSAPI_ERROR_AUTH_FAILURE;
case SCL_PENDING:
case SCL_JOIN_IN_PROGRESS:
return NSAPI_ERROR_IN_PROGRESS;
case SCL_CONNECTION_LOST:
return NSAPI_ERROR_CONNECTION_LOST;
case SCL_TIMEOUT:
case SCL_EAPOL_KEY_PACKET_M1_TIMEOUT:
case SCL_EAPOL_KEY_PACKET_M3_TIMEOUT:
case SCL_EAPOL_KEY_PACKET_G1_TIMEOUT:
return NSAPI_ERROR_CONNECTION_TIMEOUT;
default:
return -res;
}
}
nsapi_security_t scl_tosecurity(scl_security_t sec)
{
switch (sec) {
case SCL_SECURITY_OPEN:
return NSAPI_SECURITY_NONE;
case SCL_SECURITY_WEP_PSK:
case SCL_SECURITY_WEP_SHARED:
return NSAPI_SECURITY_WEP;
case SCL_SECURITY_WPA_TKIP_PSK:
case SCL_SECURITY_WPA_TKIP_ENT:
return NSAPI_SECURITY_WPA;
case SCL_SECURITY_WPA2_MIXED_PSK:
return NSAPI_SECURITY_WPA_WPA2;
case SCL_SECURITY_WPA2_AES_PSK:
case SCL_SECURITY_WPA2_AES_ENT:
case SCL_SECURITY_WPA2_FBT_PSK:
case SCL_SECURITY_WPA2_FBT_ENT:
return NSAPI_SECURITY_WPA2;
default:
return NSAPI_SECURITY_UNKNOWN;
}
}
scl_security_t scl_fromsecurity(nsapi_security_t sec)
{
switch (sec) {
case NSAPI_SECURITY_NONE:
return SCL_SECURITY_OPEN;
case NSAPI_SECURITY_WEP:
return SCL_SECURITY_WEP_PSK;
case NSAPI_SECURITY_WPA:
return SCL_SECURITY_WPA_MIXED_PSK;
case NSAPI_SECURITY_WPA2:
return SCL_SECURITY_WPA2_AES_PSK;
case NSAPI_SECURITY_WPA_WPA2:
return SCL_SECURITY_WPA2_MIXED_PSK;
default:
return SCL_SECURITY_UNKNOWN;
}
}
SclSTAInterface::SclSTAInterface(SCL_EMAC &emac, OnboardNetworkStack &stack)
: EMACInterface(emac, stack),
_ssid("\0"),
_pass("\0"),
_security(NSAPI_SECURITY_NONE),
_scl_emac(emac)
{
}
nsapi_error_t SclSTAInterface::connect(const char *ssid, const char *pass, nsapi_security_t security, uint8_t channel)
{
int err = set_channel(channel);
if (err) {
return err;
}
err = set_credentials(ssid, pass, security);
if (err) {
return err;
}
return connect();
}
nsapi_error_t SclSTAInterface::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))
) {
return NSAPI_ERROR_PARAMETER;
}
memset(_ssid, 0, sizeof(_ssid));
strncpy(_ssid, ssid, sizeof(_ssid));
memset(_pass, 0, sizeof(_pass));
strncpy(_pass, pass, sizeof(_pass));
_security = security;
return NSAPI_ERROR_OK;
}
nsapi_error_t SclSTAInterface::connect()
{
uint32_t delay_timeout = 0;
scl_result_t ret_val;
nsapi_error_t interface_status;
uint32_t connection_status = 0;
scl_tx_nw_credentials_t.network_ssid = _ssid;
if (strlen(_ssid) < MAX_SSID_LENGTH) {
scl_tx_nw_credentials_t.ssid_len = strlen(_ssid);
}
scl_tx_nw_credentials_t.network_passphrase = _pass;
if (strlen(_pass) < MAX_PASSWORD_LENGTH) {
scl_tx_nw_credentials_t.pass_len = strlen(_pass);
}
scl_tx_nw_credentials_t.network_security_type = _security;
ret_val = scl_send_data(SCL_TX_CONNECT, (char*)&scl_tx_nw_credentials_t, TIMER_DEFAULT_VALUE);
if (ret_val == SCL_SUCCESS) {
SCL_LOG(("wifi provisioning in progress"));
}
network_parameter.connection_status = NSAPI_STATUS_DISCONNECTED;
//Get the network parameter from NP
while ((network_parameter.connection_status != NSAPI_STATUS_GLOBAL_UP) && delay_timeout < NW_CONNECT_TIMEOUT) {
ret_val = scl_get_nw_parameters(&network_parameter);
wait_us(NW_DELAY_TIME);
delay_timeout++;
}
if (delay_timeout >= NW_CONNECT_TIMEOUT || ret_val != SCL_SUCCESS) {
return NSAPI_ERROR_NO_CONNECTION;
}
if (!_scl_emac.powered_up) {
_scl_emac.power_up();
}
if (!_interface) {
nsapi_error_t err = _stack.add_ethernet_interface(_emac, true, &_interface);
if (err != NSAPI_ERROR_OK) {
_interface = NULL;
return err;
}
_interface->attach(_connection_status_cb);
}
if (!scl_wifi_is_ready_to_transceive()) {
scl_emac_wifi_link_state_changed(true);
}
interface_status = _interface->bringup(false,
network_parameter.ip_address,
network_parameter.netmask,
network_parameter.gateway,
DEFAULT_STACK);
scl_send_data(SCL_TX_CONNECTION_STATUS, (char*)&connection_status, TIMER_DEFAULT_VALUE);
return interface_status;
}
void SclSTAInterface::wifi_on()
{
if (!_scl_emac.powered_up) {
_scl_emac.power_up();
}
}
nsapi_error_t SclSTAInterface::disconnect()
{
scl_result_t ret_val;
nsapi_error_t disconnect_status;
ret_val = scl_send_data(SCL_TX_DISCONNECT, (char*)&disconnect_status, TIMER_DEFAULT_VALUE);
if (ret_val == SCL_ERROR) {
return NSAPI_ERROR_TIMEOUT;
}
if (!_interface) {
return NSAPI_STATUS_DISCONNECTED;
}
// bring down
int err = _interface->bringdown();
if (err) {
return err;
}
scl_emac_wifi_link_state_changed(false);
return NSAPI_ERROR_OK;
}
int SclSTAInterface::scan(WiFiAccessPoint *res, unsigned count)
{
/* To Do */
return NSAPI_ERROR_UNSUPPORTED;
}
int8_t SclSTAInterface::get_rssi()
{
int32_t rssi;
scl_result_t res;
if (!_scl_emac.powered_up) {
_scl_emac.power_up();
}
res = (scl_result_t) scl_wifi_get_rssi(&rssi);
if (res == SCL_ERROR) {
return SCL_ERROR;
}
return (int8_t)rssi;
}
int SclSTAInterface::is_interface_connected(void)
{
if (scl_wifi_is_ready_to_transceive() == SCL_SUCCESS) {
return SCL_SUCCESS;
} else {
return SCL_CONNECTION_LOST;
}
}
int SclSTAInterface::get_bssid(uint8_t *bssid)
{
scl_mac_t ap_mac;
scl_result_t res = SCL_SUCCESS;
if (bssid == NULL) {
return SCL_BADARG;
}
memset(&ap_mac, 0, sizeof(ap_mac));
if (scl_wifi_is_ready_to_transceive() == SCL_SUCCESS) {
res = (scl_result_t) scl_wifi_get_bssid(&ap_mac);
if (res == SCL_SUCCESS) {
memcpy(bssid, ap_mac.octet, sizeof(ap_mac.octet));
}
}
else {
return SCL_CONNECTION_LOST;
}
return res;
}
int SclSTAInterface::wifi_set_up(void)
{
int res = SCL_SUCCESS;
res = scl_wifi_set_up();
return res;
}

View File

@ -0,0 +1,183 @@
/*
* (c) (2019-2020), Cypress Semiconductor Corporation. All rights reserved.
*
* This software, including source code, documentation and related materials
* ("Software"), is owned by Cypress Semiconductor Corporation or one of its
* subsidiaries ("Cypress") and is protected by and subject to worldwide patent
* protection (United States and foreign), United States copyright laws and
* international treaty provisions. Therefore, you may use this Software only
* as provided in the license agreement accompanying the software package from
* which you obtained this Software ("EULA").
*
* If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
* non-transferable license to copy, modify, and compile the Software source
* code solely for use in connection with Cypress's integrated circuit products.
* Any reproduction, modification, translation, compilation, or representation
* of this Software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
* reserves the right to make changes to the Software without notice. Cypress
* does not assume any liability arising out of the application or use of the
* Software or any product or circuit described in the Software. Cypress does
* not authorize its products for use in any products where a malfunction or
* failure of the Cypress product may reasonably be expected to result in
* significant property damage, injury or death ("High Risk Product"). By
* including Cypress's product in a High Risk Product, the manufacturer of such
* system or application assumes all risk of such use and in doing so agrees to
* indemnify Cypress against all liability.
*/
#ifndef SCL_STA_INTERFACE_H
#define SCL_STA_INTERFACE_H
/** @file
* Provides SCL interface functions to be used with WiFiInterface or NetworkInterface Objects
*/
#include "netsocket/WiFiInterface.h"
#include "netsocket/EMACInterface.h"
#include "netsocket/OnboardNetworkStack.h"
#include "scl_emac.h"
#include "scl_wifi_api.h"
#include "scl_types.h"
#define MAX_SSID_LENGTH (33)
#define MAX_PASSWORD_LENGTH (64)
/** SclSTAInterface class
* Implementation of the NetworkStack for the SCL
*/
class SclSTAInterface : public WiFiInterface, public EMACInterface {
public:
SclSTAInterface(
SCL_EMAC &emac = SCL_EMAC::get_instance(),
OnboardNetworkStack &stack = OnboardNetworkStack::get_default_instance());
/** Get current instance of the SclSTAInterface
*
* @return pointer to the object of class SclSTAInterface
*/
static SclSTAInterface *get_default_instance();
/** Turn on the WiFi device
*
* @return void
*/
/* Turn on the wifi device*/
void wifi_on();
/** Start the interface
*
* Attempts to connect to a WiFi network. Requires ssid and passphrase to be set.
* If passphrase is invalid, NSAPI_ERROR_AUTH_ERROR is returned.
*
* @return 0 on success, negative error code on failure
*/
nsapi_error_t connect();
/** Start the interface
*
* Attempts to connect to a WiFi network.
*
* @param ssid Name of the network to connect to
* @param pass Security passphrase to connect to the network
* @param security Type of encryption for connection (Default: NSAPI_SECURITY_NONE)
* @param channel This parameter is not supported, setting it to anything else than 0 will result in NSAPI_ERROR_UNSUPPORTED
* @return 0 on success, or error code on failure
*/
nsapi_error_t connect(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE, uint8_t channel = 0);
/** Stop the interface
* @return 0 on success, negative on failure
*/
nsapi_error_t disconnect();
/** Set the WiFi network credentials
*
* @param ssid Name of the network to connect to
* @param pass Security passphrase to connect to the network
* @param security Type of encryption for connection
* (defaults to NSAPI_SECURITY_NONE)
* @return 0 on success, or error code on failure
*/
nsapi_error_t set_credentials(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE);
/** Set the WiFi network channel - NOT SUPPORTED
*
* This function is not supported and will return NSAPI_ERROR_UNSUPPORTED
*
* @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)
{
if (channel != 0) {
return NSAPI_ERROR_UNSUPPORTED;
}
return 0;
}
/** Set blocking status of interface.
* Nonblocking mode unsupported.
*
* @param blocking true if connect is blocking
* @return 0 on success, negative error code on failure
*/
nsapi_error_t set_blocking(bool blocking)
{
if (blocking) {
_blocking = blocking;
return NSAPI_ERROR_OK;
} else {
return NSAPI_ERROR_UNSUPPORTED;
}
}
/** Gets the current radio signal strength for active connection
*
* @return Connection strength in dBm (negative value)
*/
int8_t get_rssi();
/** Scan for available networks
*
* This function will block.
*
* @param ap Pointer to allocated array to store discovered AP
* @param count Size of allocated @a res array, or 0 to only count available AP
* @param timeout Timeout in milliseconds; 0 for no timeout (Default: 0)
* @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);
/** This function is used to know if the device is connected to the network
* @return SCL_SUCCESS if device is connected
*/
int is_interface_connected();
/** Get the BSSID (MAC address of device connected to)
*
* @param bssid pointer to the BSSID value
* @return SCL_SUCCESS if BSSID is obtained successfully
* @return SCL_BADARG if input parameter is NULL
* @return SCL_ERROR if unable to fetch BSSID
*/
int get_bssid(uint8_t *bssid);
/** This function is used to set up the wifi interface after wifi on
* @return SCL_SUCCESS if wifi interface is up successfully
*/
int wifi_set_up(void);
private:
char _ssid[MAX_SSID_LENGTH]; /* The longest possible name (defined in 802.11) +1 for the \0 */
char _pass[MAX_PASSWORD_LENGTH]; /* The longest allowed passphrase + 1 */
nsapi_security_t _security;
SCL_EMAC &_scl_emac;
};
#endif

View File

@ -0,0 +1,39 @@
/*
* (c) (2019-2020), Cypress Semiconductor Corporation. All rights reserved.
*
* This software, including source code, documentation and related materials
* ("Software"), is owned by Cypress Semiconductor Corporation or one of its
* subsidiaries ("Cypress") and is protected by and subject to worldwide patent
* protection (United States and foreign), United States copyright laws and
* international treaty provisions. Therefore, you may use this Software only
* as provided in the license agreement accompanying the software package from
* which you obtained this Software ("EULA").
*
* If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
* non-transferable license to copy, modify, and compile the Software source
* code solely for use in connection with Cypress's integrated circuit products.
* Any reproduction, modification, translation, compilation, or representation
* of this Software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
* reserves the right to make changes to the Software without notice. Cypress
* does not assume any liability arising out of the application or use of the
* Software or any product or circuit described in the Software. Cypress does
* not authorize its products for use in any products where a malfunction or
* failure of the Cypress product may reasonably be expected to result in
* significant property damage, injury or death ("High Risk Product"). By
* including Cypress's product in a High Risk Product, the manufacturer of such
* system or application assumes all risk of such use and in doing so agrees to
* indemnify Cypress against all liability.
*/
#include "SclSTAInterface.h"
WiFiInterface *WiFiInterface::get_target_default_instance()
{
static SclSTAInterface wifi;
return &wifi;
}

View File

@ -0,0 +1,78 @@
/*
* (c) (2019-2020), Cypress Semiconductor Corporation. All rights reserved.
*
* This software, including source code, documentation and related materials
* ("Software"), is owned by Cypress Semiconductor Corporation or one of its
* subsidiaries ("Cypress") and is protected by and subject to worldwide patent
* protection (United States and foreign), United States copyright laws and
* international treaty provisions. Therefore, you may use this Software only
* as provided in the license agreement accompanying the software package from
* which you obtained this Software ("EULA").
*
* If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
* non-transferable license to copy, modify, and compile the Software source
* code solely for use in connection with Cypress's integrated circuit products.
* Any reproduction, modification, translation, compilation, or representation
* of this Software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
* reserves the right to make changes to the Software without notice. Cypress
* does not assume any liability arising out of the application or use of the
* Software or any product or circuit described in the Software. Cypress does
* not authorize its products for use in any products where a malfunction or
* failure of the Cypress product may reasonably be expected to result in
* significant property damage, injury or death ("High Risk Product"). By
* including Cypress's product in a High Risk Product, the manufacturer of such
* system or application assumes all risk of such use and in doing so agrees to
* indemnify Cypress against all liability.
*/
#ifndef INCLUDED_EMAC_EAPOL_H_
#define INCLUDED_EMAC_EAPOL_H_
#ifdef __cplusplus
extern "C"
{
#endif
/******************************************************
* Macros
******************************************************/
/******************************************************
* Constants
******************************************************/
#define EAPOL_PACKET_TYPE (0x888E)
/******************************************************
* Enumerations
******************************************************/
/******************************************************
* Type Definitions
******************************************************/
typedef scl_buffer_t scl_eapol_packet_t;
typedef void (*eapol_packet_handler_t)(scl_buffer_t buffer);
/******************************************************
* Structures
******************************************************/
/******************************************************
* Global Variables
******************************************************/
/******************************************************
* Function Declarations
******************************************************/
scl_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" */
#endif
#endif /* ifndef INCLUDED_EMAC_EAPOL_H_ */

View File

@ -0,0 +1,249 @@
/*
* (c) (2019-2020), Cypress Semiconductor Corporation. All rights reserved.
*
* This software, including source code, documentation and related materials
* ("Software"), is owned by Cypress Semiconductor Corporation or one of its
* subsidiaries ("Cypress") and is protected by and subject to worldwide patent
* protection (United States and foreign), United States copyright laws and
* international treaty provisions. Therefore, you may use this Software only
* as provided in the license agreement accompanying the software package from
* which you obtained this Software ("EULA").
*
* If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
* non-transferable license to copy, modify, and compile the Software source
* code solely for use in connection with Cypress's integrated circuit products.
* Any reproduction, modification, translation, compilation, or representation
* of this Software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
* reserves the right to make changes to the Software without notice. Cypress
* does not assume any liability arising out of the application or use of the
* Software or any product or circuit described in the Software. Cypress does
* not authorize its products for use in any products where a malfunction or
* failure of the Cypress product may reasonably be expected to result in
* significant property damage, injury or death ("High Risk Product"). By
* including Cypress's product in a High Risk Product, the manufacturer of such
* system or application assumes all risk of such use and in doing so agrees to
* indemnify Cypress against all liability.
*/
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "cmsis_os.h"
#include "scl_emac.h"
#include "lwip/etharp.h"
#include "lwip/ethip6.h"
#include "mbed_shared_queues.h"
#include "scl_buffer_api.h"
#include "emac_eapol.h"
#include "cy_result.h"
#include "cy_pdl.h"
#include "scl_ipc.h"
extern "C"
{
eapol_packet_handler_t emac_eapol_packet_handler = NULL;
} // extern "C"
SCL_EMAC::SCL_EMAC(scl_interface_role_t role)
: interface_type(role)
{
}
SCL_EMAC::SCL_EMAC()
: interface_type(SCL_STA_ROLE)
{
}
SCL_EMAC &SCL_EMAC::get_instance()
{
return get_instance(SCL_STA_ROLE);
}
SCL_EMAC &SCL_EMAC::get_instance(scl_interface_role_t role)
{
static SCL_EMAC emac_sta(SCL_STA_ROLE);
static SCL_EMAC emac_ap(SCL_AP_ROLE);
return role == SCL_AP_ROLE ? emac_ap : emac_sta;
}
uint32_t SCL_EMAC::get_mtu_size() const
{
return SCL_PAYLOAD_MTU;
}
uint32_t SCL_EMAC::get_align_preference() const
{
return 0;
}
void SCL_EMAC::add_multicast_group(const uint8_t *addr)
{
memcpy(multicast_addr.octet, addr, sizeof(multicast_addr.octet));
scl_wifi_register_multicast_address(&multicast_addr);
}
void SCL_EMAC::remove_multicast_group(const uint8_t *address)
{
/* To Do */
}
void SCL_EMAC::set_all_multicast(bool all)
{
/* No-op at this stage */
}
void SCL_EMAC::power_down()
{
/* No-op at this stage */
}
bool SCL_EMAC::power_up()
{
if (!powered_up) {
if (scl_wifi_on() != true) {
SCL_LOG(("returning false in scl_wifi_on()\n"));
return false;
}
powered_up = true;
if (link_state && emac_link_state_cb) {
emac_link_state_cb(link_state);
}
}
return true;
}
bool SCL_EMAC::get_hwaddr(uint8_t *addr) const
{
scl_mac_t mac;
scl_result_t res = scl_wifi_get_mac_address(&mac);
if (res == SCL_SUCCESS) {
memcpy(addr, mac.octet, sizeof(mac.octet));
return true;
}
else {
SCL_LOG(("return false in SCL_EMAC::gethwaddr\n"));
return false;
}
}
void SCL_EMAC::set_hwaddr(const uint8_t *addr)
{
/* No-op at this stage */
}
uint8_t SCL_EMAC::get_hwaddr_size() const
{
scl_mac_t mac;
return sizeof(mac.octet);
}
void SCL_EMAC::set_link_input_cb(emac_link_input_cb_t input_cb)
{
emac_link_input_cb = input_cb;
}
void SCL_EMAC::set_link_state_cb(emac_link_state_change_cb_t state_cb)
{
emac_link_state_cb = state_cb;
}
void SCL_EMAC::set_memory_manager(EMACMemoryManager &mem_mngr)
{
memory_manager = &mem_mngr;
}
bool SCL_EMAC::link_out(emac_mem_buf_t *buf)
{
scl_result_t retval;
scl_tx_buf_t scl_tx_data;
scl_tx_data.size = memory_manager->get_total_len(buf);
scl_tx_data.buffer = buf;
if (buf == NULL) {
return false;
}
retval = scl_network_send_ethernet_data(scl_tx_data);
if (retval != SCL_SUCCESS) {
return false;
}
memory_manager->free(buf);
return true;
}
void SCL_EMAC::get_ifname(char *name, uint8_t size) const
{
if (name != NULL) {
memcpy(name, "scl", size);
}
}
void SCL_EMAC::set_activity_cb(mbed::Callback<void(bool)> cb)
{
activity_cb = cb;
}
extern "C"
{
void emac_receive_eapol_packet(scl_buffer_t buffer)
{
if (buffer != NULL) {
if (emac_eapol_packet_handler != NULL) {
emac_eapol_packet_handler(buffer);
} else {
scl_buffer_release(buffer, SCL_NETWORK_RX);
}
}
}
scl_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 SCL_SUCCESS;
}
return SCL_HANDLER_ALREADY_REGISTERED;
}
void emac_unregister_eapol_packet_handler(void)
{
emac_eapol_packet_handler = NULL;
}
void scl_network_process_ethernet_data(scl_buffer_t buffer)
{
emac_mem_buf_t *mem_buf = NULL;
SCL_EMAC &emac = SCL_EMAC::get_instance(SCL_STA_ROLE);
if (!emac.powered_up && !emac.emac_link_input_cb) {
scl_buffer_release(buffer, SCL_NETWORK_RX);
return;
}
mem_buf = buffer;
if (emac.activity_cb) {
emac.activity_cb(false);
}
emac.emac_link_input_cb(mem_buf);
}
void scl_emac_wifi_link_state_changed(bool state_up)
{
SCL_EMAC &emac = SCL_EMAC::get_instance(SCL_STA_ROLE);
emac.link_state = state_up;
if (emac.emac_link_state_cb) {
emac.emac_link_state_cb(state_up);
}
}
} // extern "C"

View File

@ -0,0 +1,189 @@
/*
* (c) (2019-2020), Cypress Semiconductor Corporation. All rights reserved.
*
* This software, including source code, documentation and related materials
* ("Software"), is owned by Cypress Semiconductor Corporation or one of its
* subsidiaries ("Cypress") and is protected by and subject to worldwide patent
* protection (United States and foreign), United States copyright laws and
* international treaty provisions. Therefore, you may use this Software only
* as provided in the license agreement accompanying the software package from
* which you obtained this Software ("EULA").
*
* If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
* non-transferable license to copy, modify, and compile the Software source
* code solely for use in connection with Cypress's integrated circuit products.
* Any reproduction, modification, translation, compilation, or representation
* of this Software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
* reserves the right to make changes to the Software without notice. Cypress
* does not assume any liability arising out of the application or use of the
* Software or any product or circuit described in the Software. Cypress does
* not authorize its products for use in any products where a malfunction or
* failure of the Cypress product may reasonably be expected to result in
* significant property damage, injury or death ("High Risk Product"). By
* including Cypress's product in a High Risk Product, the manufacturer of such
* system or application assumes all risk of such use and in doing so agrees to
* indemnify Cypress against all liability.
*/
#ifndef SCL_EMAC_H_
#define SCL_EMAC_H_
/** @file
* Provides EMAC interface functions to be used with SCL_EMAC Object
*/
#include "EMAC.h"
#include "EMACInterface.h"
#include "WiFiInterface.h"
#include "scl_common.h"
#include "rtos/Semaphore.h"
#include "rtos/Mutex.h"
#include "scl_wifi_api.h"
class SCL_EMAC : public EMAC {
public:
SCL_EMAC();
SCL_EMAC(scl_interface_role_t itype);
static SCL_EMAC &get_instance();
static SCL_EMAC &get_instance(scl_interface_role_t role);
/**
* Return maximum transmission unit
*
* @return MTU in bytes
*/
virtual uint32_t get_mtu_size() const;
/**
* Gets memory buffer alignment preference
*
* Gets preferred memory buffer alignment of the Emac device. IP stack may or may not
* align link out memory buffer chains using the alignment.
*
* @return Memory alignment requirement in bytes
*/
virtual uint32_t get_align_preference() const;
/**
* Return interface name
*
* @param name Pointer to where the name should be written
* @param size Maximum number of character to copy
*/
virtual void get_ifname(char *name, uint8_t size) const;
/**
* Returns size of the underlying interface HW address size.
*
* @return HW address size in bytes
*/
virtual uint8_t get_hwaddr_size() const;
/**
* Return interface-supplied HW address
* Copies HW address to provided memory
* @param addr HW address for underlying interface, it has to be of correct size see @a get_hwaddr_size
* @return true if HW address is available
*/
virtual bool get_hwaddr(uint8_t *addr) const;
/**
* Set HW address for interface
*
* Provided address has to be of correct size, see @a get_hwaddr_size
*
* Called to set the MAC address to actually use - if @a get_hwaddr is provided
* the stack would normally use that, but it could be overridden, eg for test
* purposes.
*
* @param addr Address to be set
*/
virtual void set_hwaddr(const uint8_t *addr);
/**
* Sends the packet over the link
*
* That can not be called from an interrupt context.
*
* @param buf Packet to be send
* @return True if the packet was send successfully, False otherwise
*/
virtual bool link_out(emac_mem_buf_t *buf);
/**
* Initializes the HW
*
* @return True on success, False in case of an error.
*/
virtual bool power_up();
/**
* Deinitializes the HW
*
*/
virtual void power_down();
/**
* Sets a callback that needs to be called for packets received for that interface
*
* @param input_cb Function to be register as a callback
*/
virtual void set_link_input_cb(emac_link_input_cb_t input_cb);
/**
* Sets a callback that needs to be called on link status changes for given interface
*
* @param state_cb Function to be register as a callback
*/
virtual void set_link_state_cb(emac_link_state_change_cb_t state_cb);
/** Add device to a multicast group
*
* @param address A multicast group hardware address
*/
virtual void add_multicast_group(const uint8_t *address);
/** Remove device from a multicast group
*
* @param address A multicast group hardware address
*/
virtual void remove_multicast_group(const uint8_t *address);
/** Request reception of all multicast packets
*
* @param all True to receive all multicasts
* False to receive only multicasts addressed to specified groups
*/
virtual void set_all_multicast(bool all);
/** Sets memory manager that is used to handle memory buffers
*
* @param mem_mngr Pointer to memory manager
*/
virtual void set_memory_manager(EMACMemoryManager &mem_mngr);
/** Set callback to receive EMAC activity events
*
* @param activity_cb The callback for activity events
*/
virtual void set_activity_cb(mbed::Callback<void(bool is_tx_activity)> activity_cb);
emac_link_input_cb_t emac_link_input_cb = NULL; /* Callback for incoming data */
emac_link_state_change_cb_t emac_link_state_cb = NULL;
EMACMemoryManager *memory_manager;
bool powered_up = false;
bool link_state = false;
scl_interface_role_t interface_type;
scl_mac_t multicast_addr;
mbed::Callback<void(bool)> activity_cb;
};
extern "C" void scl_emac_wifi_link_state_changed(bool state_up);
#endif /* SCL_EMAC_H_ */

View File

@ -47,6 +47,9 @@
}, },
"CY8CKIT_062S2_43012": { "CY8CKIT_062S2_43012": {
"thread-stacksize": 896 "thread-stacksize": 896
},
"CYSBSYSKIT_01": {
"thread-stacksize": 896
} }
} }
} }

View File

@ -0,0 +1,9 @@
/*
* This file is used to set the MAC address in NVRAM.
* The MAC address of the Wi-Fi device may be configured in OTP and/or in NVRAM.
* If both OTP and NVRAM contains the MAC address then OTP programmed MAC address will be used.
* PSOC boards are usually programmed with OTP MAC address.
* MAC address is printed during SCL power up
*/
#define NVRAM_GENERATED_MAC_ADDRESS "macaddr=00:A0:50:45:2e:c8"

View File

@ -0,0 +1,217 @@
/*
* (c) (2019-2020), Cypress Semiconductor Corporation. All rights reserved.
*
* This software, including source code, documentation and related materials
* ("Software"), is owned by Cypress Semiconductor Corporation or one of its
* subsidiaries ("Cypress") and is protected by and subject to worldwide patent
* protection (United States and foreign), United States copyright laws and
* international treaty provisions. Therefore, you may use this Software only
* as provided in the license agreement accompanying the software package from
* which you obtained this Software ("EULA").
*
* If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
* non-transferable license to copy, modify, and compile the Software source
* code solely for use in connection with Cypress's integrated circuit products.
* Any reproduction, modification, translation, compilation, or representation
* of this Software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
* reserves the right to make changes to the Software without notice. Cypress
* does not assume any liability arising out of the application or use of the
* Software or any product or circuit described in the Software. Cypress does
* not authorize its products for use in any products where a malfunction or
* failure of the Cypress product may reasonably be expected to result in
* significant property damage, injury or death ("High Risk Product"). By
* including Cypress's product in a High Risk Product, the manufacturer of such
* system or application assumes all risk of such use and in doing so agrees to
* indemnify Cypress against all liability.
*/
/** @file scl_common.h
* Defines common data types used with SCL
*
*/
#include <stdint.h>
#include "cy_result.h"
#ifndef INCLUDED_SCL_COMMON_H_
#define INCLUDED_SCL_COMMON_H_
#ifdef __cplusplus
extern "C"
{
#endif
/******************************************************
* Constants
******************************************************/
#define SCL_LOG_ENABLE false
#define SCL_LOG(x) if (SCL_LOG_ENABLE) \
{ printf x; }
#define CHECK_BUFFER_NULL(buf) if (buf == NULL)\
{ SCL_LOG(("Buffer pointer is null\n")); \
return SCL_BADARG; }
#define MODULE_BASE_CODE (0x0080U)
/* scl_result_t error code format
* |31-18 (14 bit) for module id|17-16 (2 bit) for result type|15-0 for scl error code|
* eg:- for error code 1026, the result of SCL_RESULT_CREATE is 33555458
*/
#define SCL_RESULT_TYPE 0 /**< SCL Result type */
#define SCL_RESULT_CREATE(x) CY_RSLT_CREATE(SCL_RESULT_TYPE, MODULE_BASE_CODE, (x) ) /**< Create a result value from the specified type, module, and result code */
#define SCL_SUCCESS (0)
#define SCL_ERROR (100)
#define SCL_PENDING SCL_RESULT_CREATE(1)
#define SCL_TIMEOUT SCL_RESULT_CREATE(2) /**< Timeout */
#define SCL_BADARG SCL_RESULT_CREATE(5) /**< Bad Arguments */
#define SCL_UNFINISHED SCL_RESULT_CREATE(10) /**< Operation not finished yet (maybe aborted) */
#define SCL_PARTIAL_RESULTS SCL_RESULT_CREATE(1003) /**< Partial results */
#define SCL_INVALID_KEY SCL_RESULT_CREATE(1004) /**< Invalid key */
#define SCL_DOES_NOT_EXIST SCL_RESULT_CREATE(1005) /**< Does not exist */
#define SCL_NOT_AUTHENTICATED SCL_RESULT_CREATE(1006) /**< Not authenticated */
#define SCL_NOT_KEYED SCL_RESULT_CREATE(1007) /**< Not keyed */
#define SCL_IOCTL_FAIL SCL_RESULT_CREATE(1008) /**< IOCTL fail */
#define SCL_BUFFER_UNAVAILABLE_TEMPORARY SCL_RESULT_CREATE(1009) /**< Buffer unavailable temporarily */
#define SCL_BUFFER_UNAVAILABLE_PERMANENT SCL_RESULT_CREATE(1010) /**< Buffer unavailable permanently */
#define SCL_CONNECTION_LOST SCL_RESULT_CREATE(1012) /**< Connection lost */
#define SCL_OUT_OF_EVENT_HANDLER_SPACE SCL_RESULT_CREATE(1013) /**< Cannot add extra event handler */
#define SCL_SEMAPHORE_ERROR SCL_RESULT_CREATE(1014) /**< Error manipulating a semaphore */
#define SCL_FLOW_CONTROLLED SCL_RESULT_CREATE(1015) /**< Packet retrieval cancelled due to flow control */
#define SCL_NO_CREDITS SCL_RESULT_CREATE(1016) /**< Packet retrieval cancelled due to lack of bus credits */
#define SCL_NO_PACKET_TO_SEND SCL_RESULT_CREATE(1017) /**< Packet retrieval cancelled due to no pending packets */
#define SCL_CORE_CLOCK_NOT_ENABLED SCL_RESULT_CREATE(1018) /**< Core disabled due to no clock */
#define SCL_CORE_IN_RESET SCL_RESULT_CREATE(1019) /**< Core disabled - in reset */
#define SCL_UNSUPPORTED SCL_RESULT_CREATE(1020) /**< Unsupported function */
#define SCL_BUS_WRITE_REGISTER_ERROR SCL_RESULT_CREATE(1021) /**< Error writing to WLAN register */
#define SCL_SDIO_BUS_UP_FAIL SCL_RESULT_CREATE(1022) /**< SDIO bus failed to come up */
#define SCL_JOIN_IN_PROGRESS SCL_RESULT_CREATE(1023) /**< Join not finished yet */
#define SCL_NETWORK_NOT_FOUND SCL_RESULT_CREATE(1024) /**< Specified network was not found */
#define SCL_INVALID_JOIN_STATUS SCL_RESULT_CREATE(1025) /**< Join status error */
#define SCL_UNKNOWN_INTERFACE SCL_RESULT_CREATE(1026) /**< Unknown interface specified */
#define SCL_SDIO_RX_FAIL SCL_RESULT_CREATE(1027) /**< Error during SDIO receive */
#define SCL_HWTAG_MISMATCH SCL_RESULT_CREATE(1028) /**< Hardware tag header corrupt */
#define SCL_RX_BUFFER_ALLOC_FAIL SCL_RESULT_CREATE(1029) /**< Failed to allocate a buffer to receive into */
#define SCL_BUS_READ_REGISTER_ERROR SCL_RESULT_CREATE(1030) /**< Error reading a bus hardware register */
#define SCL_THREAD_CREATE_FAILED SCL_RESULT_CREATE(1031) /**< Failed to create a new thread */
#define SCL_QUEUE_ERROR SCL_RESULT_CREATE(1032) /**< Error manipulating a queue */
#define SCL_BUFFER_POINTER_MOVE_ERROR SCL_RESULT_CREATE(1033) /**< Error moving the current pointer of a packet buffer */
#define SCL_BUFFER_SIZE_SET_ERROR SCL_RESULT_CREATE(1034) /**< Error setting size of packet buffer */
#define SCL_THREAD_STACK_NULL SCL_RESULT_CREATE(1035) /**< Null stack pointer passed when non null was reqired */
#define SCL_THREAD_DELETE_FAIL SCL_RESULT_CREATE(1036) /**< Error deleting a thread */
#define SCL_SLEEP_ERROR SCL_RESULT_CREATE(1037) /**< Error sleeping a thread */
#define SCL_BUFFER_ALLOC_FAIL SCL_RESULT_CREATE(1038) /**< Failed to allocate a packet buffer */
#define SCL_NO_PACKET_TO_RECEIVE SCL_RESULT_CREATE(1039) /**< No Packets waiting to be received */
#define SCL_INTERFACE_NOT_UP SCL_RESULT_CREATE(1040) /**< Requested interface is not active */
#define SCL_DELAY_TOO_LONG SCL_RESULT_CREATE(1041) /**< Requested delay is too long */
#define SCL_INVALID_DUTY_CYCLE SCL_RESULT_CREATE(1042) /**< Duty cycle is outside limit 0 to 100 */
#define SCL_PMK_WRONG_LENGTH SCL_RESULT_CREATE(1043) /**< Returned pmk was the wrong length */
#define SCL_UNKNOWN_SECURITY_TYPE SCL_RESULT_CREATE(1044) /**< AP security type was unknown */
#define SCL_WEP_NOT_ALLOWED SCL_RESULT_CREATE(1045) /**< AP not allowed to use WEP - it is not secure - use Open instead */
#define SCL_WPA_KEYLEN_BAD SCL_RESULT_CREATE(1046) /**< WPA / WPA2 key length must be between 8 & 64 bytes */
#define SCL_FILTER_NOT_FOUND SCL_RESULT_CREATE(1047) /**< Specified filter id not found */
#define SCL_SPI_ID_READ_FAIL SCL_RESULT_CREATE(1048) /**< Failed to read 0xfeedbead SPI id from chip */
#define SCL_SPI_SIZE_MISMATCH SCL_RESULT_CREATE(1049) /**< Mismatch in sizes between SPI header and SDPCM header */
#define SCL_ADDRESS_ALREADY_REGISTERED SCL_RESULT_CREATE(1050) /**< Attempt to register a multicast address twice */
#define SCL_SDIO_RETRIES_EXCEEDED SCL_RESULT_CREATE(1051) /**< SDIO transfer failed too many times. */
#define SCL_NULL_PTR_ARG SCL_RESULT_CREATE(1052) /**< Null Pointer argument passed to function. */
#define SCL_THREAD_FINISH_FAIL SCL_RESULT_CREATE(1053) /**< Error deleting a thread */
#define SCL_WAIT_ABORTED SCL_RESULT_CREATE(1054) /**< Semaphore/mutex wait has been aborted */
#define SCL_SET_BLOCK_ACK_WINDOW_FAIL SCL_RESULT_CREATE(1055) /**< Failed to set block ack window */
#define SCL_DELAY_TOO_SHORT SCL_RESULT_CREATE(1056) /**< Requested delay is too short */
#define SCL_INVALID_INTERFACE SCL_RESULT_CREATE(1057) /**< Invalid interface provided */
#define SCL_WEP_KEYLEN_BAD SCL_RESULT_CREATE(1058) /**< WEP / WEP_SHARED key length must be 5 or 13 bytes */
#define SCL_HANDLER_ALREADY_REGISTERED SCL_RESULT_CREATE(1059) /**< EAPOL handler already registered */
#define SCL_AP_ALREADY_UP SCL_RESULT_CREATE(1060) /**< Soft AP or P2P group owner already up */
#define SCL_EAPOL_KEY_PACKET_M1_TIMEOUT SCL_RESULT_CREATE(1061) /**< Timeout occurred while waiting for EAPOL packet M1 from AP */
#define SCL_EAPOL_KEY_PACKET_M3_TIMEOUT SCL_RESULT_CREATE(1062) /**< Timeout occurred while waiting for EAPOL packet M3 from APwhich may indicate incorrect WPA2/WPA passphrase */
#define SCL_EAPOL_KEY_PACKET_G1_TIMEOUT SCL_RESULT_CREATE(1063) /**< Timeout occurred while waiting for EAPOL packet G1 from AP */
#define SCL_EAPOL_KEY_FAILURE SCL_RESULT_CREATE(1064) /**< Unknown failure occurred during the EAPOL key handshake */
#define SCL_MALLOC_FAILURE SCL_RESULT_CREATE(1065) /**< Memory allocation failure */
#define SCL_ACCESS_POINT_NOT_FOUND SCL_RESULT_CREATE(1066) /**< Access point not found */
#define SCL_RTOS_ERROR SCL_RESULT_CREATE(1067) /**< RTOS operation failed */
#define SCL_CLM_BLOB_DLOAD_ERROR SCL_RESULT_CREATE(1068) /**< CLM blob download failed */
#define SCL_HAL_ERROR SCL_RESULT_CREATE(1069) /**< SCL HAL Error */
#define SCL_RTOS_STATIC_MEM_LIMIT SCL_RESULT_CREATE(1070) /**< Exceeding the RTOS static objects memory */
/* Below constants are used to allocate the buffer pool by the application */
#define BDC_HEADER_WITH_PAD 6 /**< BDC Header with padding 4 + 2 */
/**
* The maximum size in bytes of the data part of an Ethernet frame
*/
#define SCL_PAYLOAD_MTU (1500)
/******************************************************
* Type Definitions
******************************************************/
typedef void *scl_buffer_t;
typedef uint32_t scl_result_t;
/******************************************************
* Structures and Enumerations
******************************************************/
typedef enum
{
SCL_FALSE = 0,
SCL_TRUE = 1
} scl_bool_t;
typedef enum
{
SCL_INVALID_ROLE = 0,
SCL_STA_ROLE = 1, /**< STA or Client Interface */
SCL_AP_ROLE = 2, /**< softAP Interface */
SCL_P2P_ROLE = 3 /**< P2P Interface */
} scl_interface_role_t;
typedef enum
{
SCL_RX_DATA = 0,
SCL_RX_TEST_MSG = 1,
SCL_RX_GET_BUFFER = 2,
SCL_RX_GET_CONNECTION_STATUS = 3
} scl_ipc_rx_t;
typedef enum
{
SCL_TX_TEST_MSG = 1,
SCL_TX_WIFI_INIT = 2,
SCL_TX_CONFIG_PARAMETERS = 3,
SCL_TX_GET_MAC = 4,
SCL_TX_REGISTER_MULTICAST_ADDRESS = 5,
SCL_TX_SEND_OUT = 6,
SCL_TX_TRANSCEIVE_READY = 7,
SCL_TX_WIFI_ON = 8,
SCL_TX_WIFI_SET_UP = 9,
SCL_TX_WIFI_NW_PARAM = 10,
SCL_TX_WIFI_GET_RSSI = 11,
SCL_TX_WIFI_GET_BSSID = 12,
SCL_TX_CONNECT = 13,
SCL_TX_DISCONNECT = 14,
SCL_TX_CONNECTION_STATUS = 15
} scl_ipc_tx_t;
/**
* Structure for storing a MAC address (Wi-Fi Media Access Control address).
*/
typedef struct
{
uint8_t octet[6]; /**< Unique 6-byte MAC address */
} scl_mac_t;
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* ifndef INCLUDED_SCL_COMMON_H_ */

View File

@ -0,0 +1,113 @@
/*
* (c) (2019-2020), Cypress Semiconductor Corporation. All rights reserved.
*
* This software, including source code, documentation and related materials
* ("Software"), is owned by Cypress Semiconductor Corporation or one of its
* subsidiaries ("Cypress") and is protected by and subject to worldwide patent
* protection (United States and foreign), United States copyright laws and
* international treaty provisions. Therefore, you may use this Software only
* as provided in the license agreement accompanying the software package from
* which you obtained this Software ("EULA").
*
* If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
* non-transferable license to copy, modify, and compile the Software source
* code solely for use in connection with Cypress's integrated circuit products.
* Any reproduction, modification, translation, compilation, or representation
* of this Software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
* reserves the right to make changes to the Software without notice. Cypress
* does not assume any liability arising out of the application or use of the
* Software or any product or circuit described in the Software. Cypress does
* not authorize its products for use in any products where a malfunction or
* failure of the Cypress product may reasonably be expected to result in
* significant property damage, injury or death ("High Risk Product"). By
* including Cypress's product in a High Risk Product, the manufacturer of such
* system or application assumes all risk of such use and in doing so agrees to
* indemnify Cypress against all liability.
*/
/** @file
* Provides SCL Functionality to communicate with WiFi Chip
*/
#include "scl_common.h"
#include "cy_device.h"
#include "cy_sysint.h"
#include "cy_ipc_drv.h"
#include "scl_wifi_api.h"
#include "ip4_addr.h"
#ifndef INCLUDED_SCL_IPC_H
#define INCLUDED_SCL_IPC_H
#ifdef __cplusplus
extern "C"
{
#endif
/******************************************************
* Macros
******************************************************/
#define REG_IPC_STRUCT_DATA0(base) (((IPC_STRUCT_V2_Type*)(base))->DATA0)
#define TIMER_DEFAULT_VALUE (100)
#define WIFI_ON_TIMEOUT (5000)
#define NW_CONNECT_TIMEOUT (30)
#define NW_DISCONNECT_TIMEOUT (60000)
#define NW_DELAY_TIME (3000000)
/******************************************************
* Variables
******************************************************/
extern struct network_params_t network_params;
/******************************************************
* Function declarations
******************************************************/
/** @addtogroup communication SCL communication API
* APIs for communicating with NP
* @{
*/
/**
* Initializes the SCL Thread and necessary artifacts
*
* @return SCL_SUCCESS on successful intialization
* SCL_ERROR otherwise
*/
extern scl_result_t scl_init(void);
/**
* Send the SCL data and respective command to NP
* @param index Index of the command
* @param buffer Data to be sent
* @param timeout Wait time for IPC to be released by NP
*
* @return SCL_SUCCESS on successful communication within given time
* SCL_ERROR on Timeout
*/
extern scl_result_t scl_send_data(int index, char *buffer, uint32_t timeout);
/**
* Terminate the SCL Thread and disable the interrupts
*
* @return SCL_SUCCESS on successful communication within given time
* SCL_ERROR on Timeout
*/
extern scl_result_t scl_end(void);
/**
* Get the network parameters like IP Address, Netmask and Gateway from NP
* @param network_params_t structure pointer
* @return SCL_SUCCESS on successful communication within given time
* SCL_ERROR on Timeout
*/
extern scl_result_t scl_get_nw_parameters(struct network_params_t *nw_param);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* ifndef INCLUDED_SCL_IPC_H */

View File

@ -0,0 +1,132 @@
/*
* (c) (2019-2020), Cypress Semiconductor Corporation. All rights reserved.
*
* This software, including source code, documentation and related materials
* ("Software"), is owned by Cypress Semiconductor Corporation or one of its
* subsidiaries ("Cypress") and is protected by and subject to worldwide patent
* protection (United States and foreign), United States copyright laws and
* international treaty provisions. Therefore, you may use this Software only
* as provided in the license agreement accompanying the software package from
* which you obtained this Software ("EULA").
*
* If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
* non-transferable license to copy, modify, and compile the Software source
* code solely for use in connection with Cypress's integrated circuit products.
* Any reproduction, modification, translation, compilation, or representation
* of this Software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
* reserves the right to make changes to the Software without notice. Cypress
* does not assume any liability arising out of the application or use of the
* Software or any product or circuit described in the Software. Cypress does
* not authorize its products for use in any products where a malfunction or
* failure of the Cypress product may reasonably be expected to result in
* significant property damage, injury or death ("High Risk Product"). By
* including Cypress's product in a High Risk Product, the manufacturer of such
* system or application assumes all risk of such use and in doing so agrees to
* indemnify Cypress against all liability.
*/
/** @file scl_types.h
* Defines common data types used with SCL
*
*/
#include <stdint.h>
#include "cy_result.h"
#ifndef INCLUDED_SCL_TYPES_H_
#define INCLUDED_SCL_TYPES_H_
#ifdef __cplusplus
extern "C"
{
#endif
/******************************************************
* Macros
******************************************************/
#define SSID_NAME_SIZE (32) /**< SSID Length */
#define WEP_ENABLED 0x0001 /**< Flag to enable WEP Security */
#define TKIP_ENABLED 0x0002 /**< Flag to enable TKIP Encryption */
#define AES_ENABLED 0x0004 /**< Flag to enable AES Encryption */
#define SHARED_ENABLED 0x00008000 /**< Flag to enable Shared key Security */
#define WPA_SECURITY 0x00200000 /**< Flag to enable WPA Security */
#define WPA2_SECURITY 0x00400000 /**< Flag to enable WPA2 Security */
#define WPA3_SECURITY 0x01000000 /**< Flag to enable WPA3 PSK Security */
#define ENTERPRISE_ENABLED 0x02000000 /**< Flag to enable Enterprise Security */
#define WPS_ENABLED 0x10000000 /**< Flag to enable WPS Security */
#define IBSS_ENABLED 0x20000000 /**< Flag to enable IBSS mode */
#define FBT_ENABLED 0x40000000 /**< Flag to enable FBT */
#define NO_POWERSAVE_MODE (0) /**< No Powersave mode */
#define PM1_POWERSAVE_MODE (1) /**< Powersave mode on specified interface without regard for throughput reduction */
#define PM2_POWERSAVE_MODE (2) /**< Powersave mode on specified interface with High throughput */
/**
* Suppress unused parameter warning
*/
#define UNUSED_PARAMETER(x) ( (void)(x) )
/**
* Suppress unused variable warning
*/
#define UNUSED_VARIABLE(x) ( (void)(x) )
/**
* Suppress unused variable warning occurring due to an assert which is disabled in release mode
*/
#define REFERENCE_DEBUG_ONLY_VARIABLE(x) ( (void)(x) )
/******************************************************
* Constants
******************************************************/
/******************************************************
* Structures and Enumerations
******************************************************/
/**
* Enumeration of Wi-Fi security modes
*/
typedef enum
{
SCL_SECURITY_OPEN = 0, /**< Open security */
SCL_SECURITY_WEP_PSK = WEP_ENABLED, /**< WEP PSK Security with open authentication */
SCL_SECURITY_WEP_SHARED = (WEP_ENABLED | SHARED_ENABLED), /**< WEP PSK Security with shared authentication */
SCL_SECURITY_WPA_TKIP_PSK = (WPA_SECURITY | TKIP_ENABLED), /**< WPA PSK Security with TKIP */
SCL_SECURITY_WPA_AES_PSK = (WPA_SECURITY | AES_ENABLED), /**< WPA PSK Security with AES */
SCL_SECURITY_WPA_MIXED_PSK = (WPA_SECURITY | AES_ENABLED | TKIP_ENABLED), /**< WPA PSK Security with AES & TKIP */
SCL_SECURITY_WPA2_AES_PSK = (WPA2_SECURITY | AES_ENABLED), /**< WPA2 PSK Security with AES */
SCL_SECURITY_WPA2_TKIP_PSK = (WPA2_SECURITY | TKIP_ENABLED), /**< WPA2 PSK Security with TKIP */
SCL_SECURITY_WPA2_MIXED_PSK = (WPA2_SECURITY | AES_ENABLED | TKIP_ENABLED), /**< WPA2 PSK Security with AES & TKIP */
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_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 */
SCL_SECURITY_WPA_MIXED_ENT = (ENTERPRISE_ENABLED | WPA_SECURITY | AES_ENABLED | TKIP_ENABLED), /**< WPA Enterprise Security with AES & TKIP */
SCL_SECURITY_WPA2_TKIP_ENT = (ENTERPRISE_ENABLED | WPA2_SECURITY | TKIP_ENABLED), /**< WPA2 Enterprise Security with TKIP */
SCL_SECURITY_WPA2_AES_ENT = (ENTERPRISE_ENABLED | WPA2_SECURITY | AES_ENABLED), /**< WPA2 Enterprise Security with AES */
SCL_SECURITY_WPA2_MIXED_ENT = (ENTERPRISE_ENABLED | WPA2_SECURITY | AES_ENABLED | TKIP_ENABLED), /**< WPA2 Enterprise Security with AES & TKIP */
SCL_SECURITY_WPA2_FBT_ENT = (ENTERPRISE_ENABLED | WPA2_SECURITY | AES_ENABLED | FBT_ENABLED), /**< WPA2 Enterprise Security with AES & FBT */
SCL_SECURITY_IBSS_OPEN = (IBSS_ENABLED), /**< Open security on IBSS ad-hoc network */
SCL_SECURITY_WPS_OPEN = (WPS_ENABLED), /**< WPS with open security */
SCL_SECURITY_WPS_SECURE = (WPS_ENABLED | AES_ENABLED), /**< WPS with AES security */
SCL_SECURITY_UNKNOWN = -1, /**< May be returned by scan function if security is unknown. Do not pass this to the join function! */
SCL_SECURITY_FORCE_32_BIT = 0x7fffffff /**< Exists only to force scl_security_t type to 32 bits */
} scl_security_t;
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* ifndef INCLUDED_SCL_TYPES_H_ */

View File

@ -0,0 +1,168 @@
/*
* (c) (2019-2020), Cypress Semiconductor Corporation. All rights reserved.
*
* This software, including source code, documentation and related materials
* ("Software"), is owned by Cypress Semiconductor Corporation or one of its
* subsidiaries ("Cypress") and is protected by and subject to worldwide patent
* protection (United States and foreign), United States copyright laws and
* international treaty provisions. Therefore, you may use this Software only
* as provided in the license agreement accompanying the software package from
* which you obtained this Software ("EULA").
*
* If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
* non-transferable license to copy, modify, and compile the Software source
* code solely for use in connection with Cypress's integrated circuit products.
* Any reproduction, modification, translation, compilation, or representation
* of this Software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
* reserves the right to make changes to the Software without notice. Cypress
* does not assume any liability arising out of the application or use of the
* Software or any product or circuit described in the Software. Cypress does
* not authorize its products for use in any products where a malfunction or
* failure of the Cypress product may reasonably be expected to result in
* significant property damage, injury or death ("High Risk Product"). By
* including Cypress's product in a High Risk Product, the manufacturer of such
* system or application assumes all risk of such use and in doing so agrees to
* indemnify Cypress against all liability.
*/
/** @file
* Prototypes of functions for controlling the Wi-Fi system
*
* This file provides prototypes for end-user functions which allow
* actions such as scanning for Wi-Fi networks, joining Wi-Fi
* networks, getting the MAC address, etc
*
*/
#include <stdbool.h>
#include "scl_common.h"
#ifndef INCLUDED_SCL_WIFI_API_H
#define INCLUDED_SCL_WIFI_API_H
#ifdef __cplusplus
extern "C"
{
#endif
typedef struct scl_tx_buf{
scl_buffer_t buffer;
uint32_t size;
}scl_tx_buf_t;
/******************************************************
* Function declarations
******************************************************/
/** @addtogroup wifi SCL Wi-Fi API
* APIs for controlling the Wi-Fi system
* @{
*/
/** @addtogroup wifimanagement SCL Wi-Fi Management API
* @ingroup wifi
* Initialisation and other management functions for SCL system
* @{
*/
/**
* Turn on the Wi-Fi device
*
* Initialise Wi-Fi platform
* Program various WiFi parameters and modes
* This API should be called before using any scl_wifi_api's
* @return true if initialization is successful, false otherwise
*/
extern bool scl_wifi_on(void);
/** Brings up the Wi-Fi core
*
* @return SCL_SUCCESS or Error code
*/
extern scl_result_t scl_wifi_set_up(void);
/** Retrieves the current Media Access Control (MAC) address
* (or Ethernet hardware address) of the 802.11 device
*
* @param mac Pointer to a variable that the current MAC address will be written to
*
* @return SCL_SUCCESS or Error code
*/
extern scl_result_t scl_wifi_get_mac_address(scl_mac_t *mac);
/** Get the BSSID of the interface
* This API should be used after the device is connected to a network
* @param bssid Returns the BSSID address (mac address) if associated
*
* @return SCL_SUCCESS or Error code
*/
extern scl_result_t scl_wifi_get_bssid(scl_mac_t *bssid);
/** Registers interest in a multicast address
*
* Once a multicast address has been registered, all packets detected on the
* medium destined for that address are forwarded to the host.
* Otherwise they are ignored.
*
* @param mac Ethernet MAC address
*
* @return SCL_SUCCESS if the address was registered successfully
* Error code if the address was not registered
*/
extern scl_result_t scl_wifi_register_multicast_address(scl_mac_t *mac);
/** Determines if a particular interface is ready to transceive ethernet packets
* This function has to be called after the connection is established otherwise it returns error code
*
* @return SCL_SUCCESS if the interface is ready to transceive ethernet packets
* SCL_NOTFOUND no AP with a matching SSID was found
* SCL_NOT_AUTHENTICATED Matching AP was found but it won't let you authenticate.
* This can occur if this device is in the block list on the AP.
* SCL_NOT_KEYED Device has authenticated and associated but has not completed the key exchange.
* This can occur if the passphrase is incorrect.
* Error code if the interface is not ready to transceive ethernet packets
*/
extern scl_result_t scl_wifi_is_ready_to_transceive(void);
/** To send an ethernet frame to SCL (called by the Network Stack)
*
* This function takes ethernet data from the network stack and transmits over the wireless network.
* This function returns immediately after the packet has been queued for transmit,
* NOT after it has been transmitted. Packet buffers passed to the SCL
* are released inside the SCL once they have been transmitted.
*
* @param buffer Handle of the packet buffer to be sent.
*
* @return SCL_SUCCESS or Error code
*
*/
extern scl_result_t scl_network_send_ethernet_data(scl_tx_buf_t buffer);
/** Retrieve the latest RSSI value
* This API has to be called after the device is connected to a network
* @param rssi The location where the RSSI value will be stored
*
* @return SCL_SUCCESS if the RSSI was successfully retrieved
* Error code if the RSSI was not retrieved
*/
extern scl_result_t scl_wifi_get_rssi(int32_t *rssi);
/** Retrieve the RX data packet
*
* @param pointer to rx buffer
*
* @return void
*
*/
extern void scl_network_process_ethernet_data(scl_buffer_t buffer);
extern void scl_emac_wifi_link_state_changed(bool state_up);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* ifndef INCLUDED_SCL_WIFI_API_H */

View File

@ -0,0 +1,399 @@
/*
* (c) (2019-2020), Cypress Semiconductor Corporation. All rights reserved.
*
* This software, including source code, documentation and related materials
* ("Software"), is owned by Cypress Semiconductor Corporation or one of its
* subsidiaries ("Cypress") and is protected by and subject to worldwide patent
* protection (United States and foreign), United States copyright laws and
* international treaty provisions. Therefore, you may use this Software only
* as provided in the license agreement accompanying the software package from
* which you obtained this Software ("EULA").
*
* If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
* non-transferable license to copy, modify, and compile the Software source
* code solely for use in connection with Cypress's integrated circuit products.
* Any reproduction, modification, translation, compilation, or representation
* of this Software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
* reserves the right to make changes to the Software without notice. Cypress
* does not assume any liability arising out of the application or use of the
* Software or any product or circuit described in the Software. Cypress does
* not authorize its products for use in any products where a malfunction or
* failure of the Cypress product may reasonably be expected to result in
* significant property damage, injury or death ("High Risk Product"). By
* including Cypress's product in a High Risk Product, the manufacturer of such
* system or application assumes all risk of such use and in doing so agrees to
* indemnify Cypress against all liability.
*/
/** @file
* Provides SCL Functionality to communicate with WiFi Chip
*/
#include "scl_ipc.h"
#include "scl_buffer_api.h"
#include "cyabs_rtos.h"
#include "mbed_wait_api.h"
#include "string.h"
#include "nsapi_types.h"
/******************************************************
** Macros
*******************************************************/
#define SCL_THREAD_STACK_SIZE (1000)
#define SCL_THREAD_PRIORITY (CY_RTOS_PRIORITY_HIGH)
#define SCL_INTR_SRC (cpuss_interrupts_ipc_4_IRQn)
#define SCL_INTR_PRI (1)
#define SCL_RX_CHANNEL (4)
#define SCL_CHANNEL_NOTIFY_INTR ((1 << SCL_RX_CHANNEL) << 16)
#define SCL_NOTIFY (1 << SCL_TX_CHANNEL)
#define SCL_LOCK_ACQUIRE_STATUS (0x80000000)
#define SCL_TX_CHANNEL (3)
#define SCL_RELEASE (0)
#define DELAY_TIME (1000)
#define SEMAPHORE_MAXCOUNT (1)
#define SEMAPHORE_INITCOUNT (0)
/******************************************************
** Function Declarations
*******************************************************/
static void scl_isr(void);
static void scl_config(void);
static void scl_rx_handler(void);
static scl_result_t scl_thread_init(void);
scl_result_t scl_get_nw_parameters(struct network_params_t *nw_param);
scl_result_t scl_send_data(int index, char *buffer, uint32_t timeout);
scl_result_t scl_end(void);
scl_result_t scl_init(void);
/******************************************************
* Variables Definitions
*****************************************************/
/* Structure of scl thread info
* scl_thread_quit_flag: flag used to determine if thread is to be quit
* scl_inited: flag used to determine if thread is started
* scl_thread: variable for thread handle
* scl_thread_stack_start: pointer to start of thread stack
* scl_thread_stack_size: size of thread stack
* scl_thread_priority: priority of thread
* scl_rx_ready: semaphore for blocking the thread
*/
struct scl_thread_info_t {
volatile scl_bool_t scl_inited;
volatile scl_bool_t scl_thread_quit_flag;
void *scl_thread_stack_start;
cy_thread_t scl_thread;
cy_semaphore_t scl_rx_ready;
uint32_t scl_thread_stack_size;
cy_thread_priority_t scl_thread_priority;
};
struct scl_thread_info_t g_scl_thread_info;
/******************************************************
* Function Definitions
******************************************************/
/*******************************************************************************
* Function Name: scl_isr
********************************************************************************
* Summary:
* 1. ISR for the recevier channel interrupt
*
* Parameters:
*
* Return:
*
*******************************************************************************/
static void scl_isr(void)
{
IPC_INTR_STRUCT_Type *scl_rx_intr = NULL;
scl_rx_intr = Cy_IPC_Drv_GetIntrBaseAddr(SCL_RX_CHANNEL);
if (REG_IPC_INTR_STRUCT_INTR_MASKED(scl_rx_intr) & SCL_CHANNEL_NOTIFY_INTR) {
REG_IPC_INTR_STRUCT_INTR(scl_rx_intr) |= SCL_CHANNEL_NOTIFY_INTR;
if (g_scl_thread_info.scl_inited == SCL_TRUE) {
cy_rtos_set_semaphore(&g_scl_thread_info.scl_rx_ready, true);
}
}
}
/*******************************************************************************
* Function Name: scl_config
********************************************************************************
* Summary:
* 1. Configuring the interrupt channel
*
* Parameters:
*
* Return:
*
*******************************************************************************/
static void scl_config(void)
{
IPC_INTR_STRUCT_Type *scl_rx_intr = NULL;
cy_stc_sysint_t intrCfg =
{
.intrSrc = SCL_INTR_SRC,
.intrPriority = SCL_INTR_PRI
};
scl_rx_intr = Cy_IPC_Drv_GetIntrBaseAddr(SCL_RX_CHANNEL);
REG_IPC_INTR_STRUCT_INTR_MASK(scl_rx_intr) |= SCL_CHANNEL_NOTIFY_INTR;
Cy_SysInt_Init(&intrCfg, &scl_isr);
NVIC_EnableIRQ(intrCfg.intrSrc);
}
/*******************************************************************************
* Function Name: scl_thread_init
********************************************************************************
* Summary:
* 1. Intialises the scl_rx_handler thread and semaphores
*
* Parameters:
*
* Return:
* SCL_SUCCESS - On successful initialization of thread
* SCL_ERROR - An error occurred during intialization of thread
*******************************************************************************/
static scl_result_t scl_thread_init(void)
{
cy_rslt_t retval,tmp = 0;
memset(&g_scl_thread_info, 0, sizeof(g_scl_thread_info));
g_scl_thread_info.scl_thread_stack_start = (uint8_t*) malloc (SCL_THREAD_STACK_SIZE);;
g_scl_thread_info.scl_thread_stack_size = (uint32_t) SCL_THREAD_STACK_SIZE;
g_scl_thread_info.scl_thread_priority = (cy_thread_priority_t) SCL_THREAD_PRIORITY;
if (g_scl_thread_info.scl_inited != SCL_TRUE) {
retval = cy_rtos_init_semaphore(&g_scl_thread_info.scl_rx_ready, SEMAPHORE_MAXCOUNT, SEMAPHORE_INITCOUNT);
if (retval != SCL_SUCCESS) {
return SCL_ERROR;
}
retval = cy_rtos_create_thread(&g_scl_thread_info.scl_thread, (cy_thread_entry_fn_t) scl_rx_handler,
"SCL_thread", g_scl_thread_info.scl_thread_stack_start,
g_scl_thread_info.scl_thread_stack_size,
g_scl_thread_info.scl_thread_priority,(uint32_t) tmp);
if (retval != SCL_SUCCESS) {
return SCL_ERROR;
}
g_scl_thread_info.scl_inited = SCL_TRUE;
}
else {
return SCL_ERROR;
}
return SCL_SUCCESS;
}
/*******************************************************************************
* Function Name: scl_init
********************************************************************************
* Summary:
* 1. Intializing the scl thread and interrupts
*
* Parameters:
*
* Return:
* SCL_SUCCESS - On successful initialization
* SCL_ERROR - An error occured during intialization
*******************************************************************************/
scl_result_t scl_init(void)
{
scl_result_t retval = SCL_SUCCESS;
uint32_t configuration_parameters = 0;
configuration_parameters = MBED_CONF_TARGET_NP_CLOUD_DISABLE;
configuration_parameters = configuration_parameters << 1;
configuration_parameters |= MBED_CONF_TARGET_NP_WIFI_ENABLE;
//SCL_LOG("configuration_parameters = %lu\n", configuration_parameters);
scl_config();
if (g_scl_thread_info.scl_inited != SCL_TRUE) {
retval = scl_thread_init();
if (retval != SCL_SUCCESS) {
SCL_LOG(("Thread init failed\n"));
return SCL_ERROR;
}
else {
retval = scl_send_data(SCL_TX_CONFIG_PARAMETERS, (char*) &configuration_parameters ,TIMER_DEFAULT_VALUE);
return retval;
}
}
return SCL_SUCCESS;
}
/*******************************************************************************
* Function Name: scl_send_data
********************************************************************************
* Summary:
* 1. send the data
*
* Parameters:
* index - integer value to indicate which API is using scl
* buffer - pointer to buffer to be transferred
* timeout (in ms) - The time to wait for the IPC to be released
* Return:
* SCL_SUCCESS - On successful transfer of data
* SCL_ERROR - An error occured while transmitting data
*******************************************************************************/
scl_result_t scl_send_data(int index, char* buffer, uint32_t timeout)
{
uint32_t acquire_state;
IPC_STRUCT_Type *scl_send = NULL;
uint32_t delay_timeout;
SCL_LOG(("scl_send_data index = %d\n",index));
scl_send = Cy_IPC_Drv_GetIpcBaseAddress(SCL_TX_CHANNEL);
CHECK_BUFFER_NULL(buffer);
if (!(REG_IPC_STRUCT_LOCK_STATUS(scl_send) & SCL_LOCK_ACQUIRE_STATUS)) {
acquire_state = REG_IPC_STRUCT_ACQUIRE(scl_send);
if (!(acquire_state & SCL_LOCK_ACQUIRE_STATUS)) {
SCL_LOG(("IPC Channel 3 Acquired Failed\r\n"));
return SCL_ERROR;
}
REG_IPC_STRUCT_DATA0(scl_send) = index;
REG_IPC_STRUCT_DATA1(scl_send) = (uint32_t) buffer;
REG_IPC_STRUCT_NOTIFY(scl_send) = SCL_NOTIFY;
delay_timeout = 0;
while ((REG_IPC_STRUCT_LOCK_STATUS(scl_send) & SCL_LOCK_ACQUIRE_STATUS) && delay_timeout <= timeout) {
wait_us(DELAY_TIME);
delay_timeout++;
}
if (delay_timeout > timeout) {
REG_IPC_STRUCT_RELEASE(scl_send) = SCL_RELEASE;
delay_timeout = 0;
return SCL_ERROR;
}
else {
return SCL_SUCCESS;
}
}
else {
SCL_LOG(("unable to acquire lock\n"));
return SCL_ERROR;
}
}
/*******************************************************************************
* Function Name: scl_end
********************************************************************************
* Summary:
* 1. API to stop the SCL
*
* Parameters:
*
* Return:
* SCL_SUCCESS - If channel is not locked
* SCL_ERROR - If the channel is locked
*******************************************************************************/
scl_result_t scl_end(void)
{
scl_result_t retval = SCL_ERROR;
if (g_scl_thread_info.scl_inited == SCL_TRUE) {
retval = (scl_result_t) cy_rtos_terminate_thread(&g_scl_thread_info.scl_thread);
if (retval == SCL_SUCCESS) {
retval = (scl_result_t) cy_rtos_join_thread(&g_scl_thread_info.scl_thread);
if (retval == SCL_SUCCESS) {
retval = (scl_result_t) cy_rtos_deinit_semaphore(&g_scl_thread_info.scl_rx_ready);
if (retval == SCL_SUCCESS) {
g_scl_thread_info.scl_inited = SCL_FALSE;
}
}
}
}
return retval;
}
/*******************************************************************************
* Function Name: scl_rx_handler
********************************************************************************
* Summary:
* 1. Thread to handle recevied buffer
*
* Parameters:
*
* Return:
*
*******************************************************************************/
static void scl_rx_handler(void)
{
char *buffer = NULL;
nsapi_connection_status_t connection_status;
uint32_t index;
IPC_STRUCT_Type *scl_receive = NULL;
scl_buffer_t cp_buffer;
scl_buffer_t scl_buffer;
uint32_t rx_ipc_size;
struct rx_ipc_info {
uint32_t size;
int* buf_alloc;
}*rx_cp = NULL;
SCL_LOG(("Starting CP Rx thread\r\n"));
scl_receive = Cy_IPC_Drv_GetIpcBaseAddress(SCL_RX_CHANNEL);
while (SCL_TRUE) {
cy_rtos_get_semaphore(&g_scl_thread_info.scl_rx_ready, CY_RTOS_NEVER_TIMEOUT, SCL_FALSE);
index = (uint32_t)REG_IPC_STRUCT_DATA0(scl_receive);
SCL_LOG(("scl_rx_handler index = %lu\n", index));
switch (index) {
case SCL_RX_DATA:
{
rx_cp = (struct rx_ipc_info*) REG_IPC_STRUCT_DATA1(scl_receive);
scl_buffer = rx_cp->buf_alloc;
REG_IPC_STRUCT_RELEASE(scl_receive) = SCL_RELEASE;
SCL_LOG(("scl_buffer = %p\n",scl_buffer));
scl_network_process_ethernet_data(scl_buffer);
break;
}
case SCL_RX_TEST_MSG:
{
buffer = (char*) REG_IPC_STRUCT_DATA1(scl_receive);
SCL_LOG(("%s\r\n", (char*) buffer));
REG_IPC_STRUCT_RELEASE(scl_receive) = SCL_RELEASE;
break;
}
case SCL_RX_GET_BUFFER:
{
rx_ipc_size = (uint32_t) REG_IPC_STRUCT_DATA1(scl_receive);
scl_host_buffer_get(&cp_buffer, SCL_NETWORK_RX, rx_ipc_size, SCL_FALSE );
REG_IPC_STRUCT_DATA1(scl_receive) = (uint32_t)cp_buffer;
REG_IPC_STRUCT_RELEASE(scl_receive) = SCL_RELEASE;
break;
}
case SCL_RX_GET_CONNECTION_STATUS:
{
connection_status = (nsapi_connection_status_t) REG_IPC_STRUCT_DATA1(scl_receive);
if (connection_status == NSAPI_STATUS_GLOBAL_UP) {
scl_emac_wifi_link_state_changed(true);
}
else {
scl_emac_wifi_link_state_changed(false);
}
SCL_LOG(("connection status = %d\n",connection_status));
break;
}
default:
{
SCL_LOG(("incorrect IPC from NP\n"));
REG_IPC_STRUCT_RELEASE(scl_receive) = SCL_RELEASE;
break;
}
}
}
}
/*******************************************************************************
* Function Name: scl_get_nw_parameters
********************************************************************************
* Summary:
* Function to get the network parameter from NP
*
* Parameters:
*
* Return:
*
*******************************************************************************/
scl_result_t scl_get_nw_parameters(struct network_params_t *nw_param)
{
scl_result_t status;
status = scl_send_data(SCL_TX_WIFI_NW_PARAM, (char*)nw_param, TIMER_DEFAULT_VALUE);
return status;
}

View File

@ -0,0 +1,143 @@
/*
* (c) (2019-2020), Cypress Semiconductor Corporation. All rights reserved.
*
* This software, including source code, documentation and related materials
* ("Software"), is owned by Cypress Semiconductor Corporation or one of its
* subsidiaries ("Cypress") and is protected by and subject to worldwide patent
* protection (United States and foreign), United States copyright laws and
* international treaty provisions. Therefore, you may use this Software only
* as provided in the license agreement accompanying the software package from
* which you obtained this Software ("EULA").
*
* If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
* non-transferable license to copy, modify, and compile the Software source
* code solely for use in connection with Cypress's integrated circuit products.
* Any reproduction, modification, translation, compilation, or representation
* of this Software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
* reserves the right to make changes to the Software without notice. Cypress
* does not assume any liability arising out of the application or use of the
* Software or any product or circuit described in the Software. Cypress does
* not authorize its products for use in any products where a malfunction or
* failure of the Cypress product may reasonably be expected to result in
* significant property damage, injury or death ("High Risk Product"). By
* including Cypress's product in a High Risk Product, the manufacturer of such
* system or application assumes all risk of such use and in doing so agrees to
* indemnify Cypress against all liability.
*/
/** @file
* Provides prototypes / declarations for common APSTA functionality
*/
#ifndef _SCL_INTERNAL_BUFFER_API_H_
#define _SCL_INTERNAL_BUFFER_API_H_
#include "scl_types.h"
#include "scl_common.h"
#include <stdlib.h>
#include "cy_utils.h"
#include "memp.h"
#include "pbuf.h"
#ifdef __cplusplus
extern "C"
{
#endif
/******************************************************
* Constants
******************************************************/
#define SDIO_BLOCK_SIZE (64U)
/******************************************************
* Macros
******************************************************/
/******************************************************
* Structures & enums
******************************************************/
/**
* Indicates transmit/receive direction that the packet buffer has
* been used for. This is needed if tx/rx pools are separate.
*/
typedef enum
{
SCL_NETWORK_TX = 0, /**< Transmit direction */
SCL_NETWORK_RX = 1 /**< Recieve direction */
} scl_buffer_dir_t;
/******************************************************
* Function prototypes
******************************************************/
/** Allocates a packet buffer
* Attempts to allocate a packet buffer of the size requested. It can do this
* by allocating a pre-existing packet from a pool, using a static buffer,
* or by dynamically allocating memory.
*
* @param buffer : A pointer which receives the allocated packet buffer handle
* @param direction : Indicates transmit/receive direction that the packet buffer is
* used for. This may be needed if tx/rx pools are separate.
* @param size : The number of bytes to allocate.
* @param wait : Whether to wait for a packet buffer to be available
*
* @return : SCL_SUCCESS or error code
*
*/
scl_result_t scl_host_buffer_get(scl_buffer_t *buffer, scl_buffer_dir_t direction,
uint16_t size, uint32_t wait);
/** Releases a packet buffer
*
* Implemented in the port layer interface, which will be specific to the
* buffering scheme in use.
* This function is used by SCL to indicate that it no longer requires
* a packet buffer. The buffer can then be released back into a pool for
* reuse, or the dynamically allocated memory can be freed, according to
* how the packet was allocated.
* Returns void since SCL cannot do anything about failures
*
* @param buffer : The handle of the packet buffer to be released
* @param direction : Indicates transmit/receive direction that the packet buffer has
* been used for. This might be needed if tx/rx pools are separate.
*
*/
void scl_buffer_release(scl_buffer_t buffer, scl_buffer_dir_t direction);
/** Retrieves the current pointer of a packet buffer
*
* Implemented in the port layer interface which is specific to the
* buffering scheme in use.
* Since packet buffers usually need to be created with space at the
* front for additional headers, this function allows SCL to get
* the current 'front' location pointer.
*
* @param buffer : The handle of the packet buffer whose pointer is to be retrieved
*
* @return : The packet buffer's current pointer.
*/
uint8_t *scl_buffer_get_current_piece_data_pointer(scl_buffer_t buffer);
/** Retrieves the size of a packet buffer
*
* Implemented in the port layer interface which is specific to the
* buffering scheme in use.
* Since packet buffers usually need to be created with space at the
* front for additional headers, the memory block used to contain a packet buffer
* will often be larger than the current size of the packet buffer data.
* This function allows SCL to retrieve the current size of a packet buffer's data.
*
* @param buffer : The handle of the packet buffer whose size is to be retrieved
*
* @return : The size of the packet buffer.
*/
uint16_t scl_buffer_get_current_piece_size(scl_buffer_t buffer);
#ifdef __cplusplus
} /*extern "C" */
#endif
#endif /* ifndef _SCL_INTERNAL_BUFFER_API_H_ */

View File

@ -0,0 +1,162 @@
/*
* (c) (2019-2020), Cypress Semiconductor Corporation. All rights reserved.
*
* This software, including source code, documentation and related materials
* ("Software"), is owned by Cypress Semiconductor Corporation or one of its
* subsidiaries ("Cypress") and is protected by and subject to worldwide patent
* protection (United States and foreign), United States copyright laws and
* international treaty provisions. Therefore, you may use this Software only
* as provided in the license agreement accompanying the software package from
* which you obtained this Software ("EULA").
*
* If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
* non-transferable license to copy, modify, and compile the Software source
* code solely for use in connection with Cypress's integrated circuit products.
* Any reproduction, modification, translation, compilation, or representation
* of this Software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
* reserves the right to make changes to the Software without notice. Cypress
* does not assume any liability arising out of the application or use of the
* Software or any product or circuit described in the Software. Cypress does
* not authorize its products for use in any products where a malfunction or
* failure of the Cypress product may reasonably be expected to result in
* significant property damage, injury or death ("High Risk Product"). By
* including Cypress's product in a High Risk Product, the manufacturer of such
* system or application assumes all risk of such use and in doing so agrees to
* indemnify Cypress against all liability.
*/
#include "scl_buffer_api.h"
/******************************************************
** @cond Constants
*******************************************************/
/******************************************************
** Enumerations
*******************************************************/
/******************************************************
** Function Declarations
*******************************************************/
/******************************************************
* Variables Definitions
*****************************************************/
/******************************************************
* Function Definitions
******************************************************/
/** Allocates a packet buffer
*
* Implemented in the port layer interface which is specific to the
* buffering scheme in use.
* Attempts to allocate a packet buffer of the size requested. It can do this
* by allocating a pre-existing packet from a pool, using a static buffer,
* or by dynamically allocating memory. The method of allocation does not
* concern SCL, however it must match the way the network stack expects packet
* buffers to be allocated.
*
* @param buffer : A pointer which receives the allocated packet buffer handle
* @param direction : Indicates transmit/receive direction that the packet buffer is
* used for. This may be needed if tx/rx pools are separate.
* @param size : The number of bytes to allocate.
* @param wait : Whether to wait for a packet buffer to be available
*
* @return : SCL_SUCCESS or error code
*
*/
scl_result_t scl_host_buffer_get(scl_buffer_t *buffer, scl_buffer_dir_t direction,
uint16_t size, uint32_t wait)
{
UNUSED_PARAMETER( direction );
struct pbuf *p = NULL;
if ( ( direction == SCL_NETWORK_TX) && ( size <= PBUF_POOL_BUFSIZE ) )
{
p = pbuf_alloc(PBUF_RAW, size, PBUF_POOL);
}
else
{
p = pbuf_alloc(PBUF_RAW, size+SDIO_BLOCK_SIZE, PBUF_RAM);
if ( p != NULL )
{
p->len = size;
p->tot_len -= SDIO_BLOCK_SIZE;
}
}
if (p != NULL )
{
*buffer = p;
return SCL_SUCCESS;
}
else
{
return SCL_BUFFER_ALLOC_FAIL;
}
}
/** Releases a packet buffer
*
* Implemented in the port layer interface, which will be specific to the
* buffering scheme in use.
* This function is used by SCL to indicate that it no longer requires
* a packet buffer. The buffer can then be released back into a pool for
* reuse, or the dynamically allocated memory can be freed, according to
* how the packet was allocated.
* Returns void since SCL cannot do anything about failures
*
* @param buffer : The handle of the packet buffer to be released
* @param direction : Indicates transmit/receive direction that the packet buffer has
* been used for. This might be needed if tx/rx pools are separate.
*
*/
void scl_buffer_release(scl_buffer_t buffer, scl_buffer_dir_t direction)
{
UNUSED_PARAMETER( direction );
(void) pbuf_free( (struct pbuf *)buffer );
}
/** Retrieves the current pointer of a packet buffer
*
* Implemented in the port layer interface which is specific to the
* buffering scheme in use.
* Since packet buffers usually need to be created with space at the
* front for additional headers, this function allows SCL to get
* the current 'front' location pointer.
*
* @param buffer : The handle of the packet buffer whose pointer is to be retrieved
*
* @return : The packet buffer's current pointer.
*/
uint8_t *scl_buffer_get_current_piece_data_pointer(scl_buffer_t buffer)
{
CY_ASSERT(buffer != NULL);
struct pbuf *pbuffer= (struct pbuf*) buffer;
return (uint8_t*) pbuffer->payload;
}
/** Retrieves the size of a packet buffer
*
* Implemented in the port layer interface which is specific to the
* buffering scheme in use.
* Since packet buffers usually need to be created with space at the
* front for additional headers, the memory block used to contain a packet buffer
* will often be larger than the current size of the packet buffer data.
* This function allows SCL to retrieve the current size of a packet buffer's data.
*
* @param buffer : The handle of the packet buffer whose size is to be retrieved
*
* @return : The size of the packet buffer.
*/
uint16_t scl_buffer_get_current_piece_size(scl_buffer_t buffer)
{
CY_ASSERT(buffer != NULL);
struct pbuf *pbuffer = (struct pbuf*) buffer;
return (uint16_t) pbuffer->len;
}

View File

@ -0,0 +1,181 @@
/*
* (c) (2019-2020), Cypress Semiconductor Corporation. All rights reserved.
*
* This software, including source code, documentation and related materials
* ("Software"), is owned by Cypress Semiconductor Corporation or one of its
* subsidiaries ("Cypress") and is protected by and subject to worldwide patent
* protection (United States and foreign), United States copyright laws and
* international treaty provisions. Therefore, you may use this Software only
* as provided in the license agreement accompanying the software package from
* which you obtained this Software ("EULA").
*
* If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
* non-transferable license to copy, modify, and compile the Software source
* code solely for use in connection with Cypress's integrated circuit products.
* Any reproduction, modification, translation, compilation, or representation
* of this Software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
* reserves the right to make changes to the Software without notice. Cypress
* does not assume any liability arising out of the application or use of the
* Software or any product or circuit described in the Software. Cypress does
* not authorize its products for use in any products where a malfunction or
* failure of the Cypress product may reasonably be expected to result in
* significant property damage, injury or death ("High Risk Product"). By
* including Cypress's product in a High Risk Product, the manufacturer of such
* system or application assumes all risk of such use and in doing so agrees to
* indemnify Cypress against all liability.
*/
#include "scl_wifi_api.h"
#include "scl_ipc.h"
/******************************************************
* Variables Definitions
*****************************************************/
typedef struct {
scl_mac_t *mac;
uint32_t retval;
}scl_mac;
/******************************************************
* Function Definitions
******************************************************/
scl_result_t scl_wifi_is_ready_to_transceive(void)
{
scl_result_t result = SCL_SUCCESS;
scl_result_t retval = SCL_SUCCESS;
result = scl_send_data(SCL_TX_TRANSCEIVE_READY, (char*)&retval, TIMER_DEFAULT_VALUE);
if (result == SCL_ERROR) {
SCL_LOG(("Ready to tranceive error\n"));
return SCL_ERROR;
}
else {
return retval;
}
}
bool scl_wifi_on(void)
{
bool retval = false;
scl_result_t result = SCL_SUCCESS;
result = scl_send_data(SCL_TX_WIFI_ON, (char*)&retval, WIFI_ON_TIMEOUT);
if (result == SCL_ERROR) {
SCL_LOG(("wifi_on Error\n"));
return false;
}
else {
return retval;
}
}
scl_result_t scl_wifi_set_up(void)
{
scl_result_t retval = SCL_SUCCESS;
scl_result_t result = SCL_SUCCESS;
result = scl_send_data(SCL_TX_WIFI_SET_UP, (char*)&retval, TIMER_DEFAULT_VALUE);
if (result == SCL_SUCCESS) {
return retval;
}
else {
SCL_LOG(("Wifi set up error\n"));
return SCL_ERROR;
}
}
scl_result_t scl_wifi_get_mac_address(scl_mac_t *mac)
{
scl_mac scl_mac_data;
scl_result_t scl_retval = SCL_SUCCESS;
scl_mac_data.mac = mac;
scl_mac_data.retval = SCL_SUCCESS;
if (mac == NULL) {
return SCL_BADARG;
}
scl_retval = scl_send_data(SCL_TX_GET_MAC, (char*)&scl_mac_data, TIMER_DEFAULT_VALUE);
if (scl_retval == SCL_SUCCESS) {
return scl_mac_data.retval;
}
else {
SCL_LOG(("Get MAC address error\n"));
return SCL_ERROR;
}
}
scl_result_t scl_wifi_get_bssid(scl_mac_t *bssid)
{
struct scl_bssid {
scl_mac_t* bssid;
uint32_t retval;
} scl_bssid_t;
scl_result_t scl_retval = SCL_SUCCESS;
scl_bssid_t.bssid = bssid;
scl_bssid_t.retval = 0;
if (bssid == NULL) {
return SCL_BADARG;
}
scl_retval = scl_send_data(SCL_TX_WIFI_GET_BSSID, (char*)&scl_bssid_t, TIMER_DEFAULT_VALUE);
if (scl_retval == SCL_SUCCESS) {
return scl_bssid_t.retval;
}
else {
SCL_LOG(("get bssid error\n"));
return SCL_ERROR;
}
}
scl_result_t scl_wifi_register_multicast_address(scl_mac_t *mac)
{
scl_mac scl_mac_t;
scl_mac_t.mac = mac;
scl_mac_t.retval = 0;
scl_result_t scl_retval = SCL_SUCCESS;
if (mac == NULL) {
return SCL_BADARG;
}
scl_retval = scl_send_data(SCL_TX_REGISTER_MULTICAST_ADDRESS, (char*)&scl_mac_t, TIMER_DEFAULT_VALUE);
if(scl_retval != SCL_SUCCESS){
SCL_LOG(("Register Multicast Address IPC Error"));
return SCL_ERROR;
}
return (scl_mac_t.retval);
}
scl_result_t scl_network_send_ethernet_data(scl_tx_buf_t scl_buffer)
{
scl_result_t retval = SCL_SUCCESS;
if (scl_buffer.buffer == NULL) {
return SCL_BADARG;
}
retval = scl_send_data(SCL_TX_SEND_OUT, (char*)&scl_buffer, TIMER_DEFAULT_VALUE);
return retval;
}
scl_result_t scl_wifi_get_rssi(int32_t *rssi)
{
struct tx_param {
uint32_t retval;
int32_t *get_rssi;
}tx_param_t;
scl_result_t scl_retval = SCL_SUCCESS;
if (rssi == NULL) {
return SCL_BADARG;
}
tx_param_t.get_rssi = rssi;
scl_retval = scl_send_data(SCL_TX_WIFI_GET_RSSI, (char*) &tx_param_t, TIMER_DEFAULT_VALUE);
if (scl_retval == SCL_SUCCESS) {
return tx_param_t.retval;
}
else {
SCL_LOG(("get rssi error\n"));
return SCL_ERROR;
}
}