diff options
author | Damien George <damien.p.george@gmail.com> | 2015-02-21 19:52:07 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-02-21 19:52:07 +0000 |
commit | 49c2ad4fb417b8f0a9d815ff3295fb1af94965f7 (patch) | |
tree | c8509c73c23216f937a7aaad7b2257e1c5d6a7b5 /drivers/cc3100 | |
parent | 36e2845e3616de8de96741e9608fbb65ccd8091d (diff) | |
download | micropython-49c2ad4fb417b8f0a9d815ff3295fb1af94965f7.tar.gz micropython-49c2ad4fb417b8f0a9d815ff3295fb1af94965f7.zip |
cc3200: Move CC3100 driver from cc3200/simplelink to drivers/cc3100.
This commit will not build, it exists just to track changes.
Diffstat (limited to 'drivers/cc3100')
25 files changed, 15287 insertions, 0 deletions
diff --git a/drivers/cc3100/inc/device.h b/drivers/cc3100/inc/device.h new file mode 100644 index 0000000000..3f505c94d6 --- /dev/null +++ b/drivers/cc3100/inc/device.h @@ -0,0 +1,635 @@ +/* + * device.h - CC31xx/CC32xx Host Driver Implementation + * + * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +*/ + +#ifndef __DEVICE_H__ +#define __DEVICE_H__ + +/*****************************************************************************/ +/* Include files */ +/*****************************************************************************/ +#include "simplelink.h" + +#ifdef __cplusplus +extern "C" { +#endif + + + +/*! + + \addtogroup device + @{ + +*/ + +/*****************************************************************************/ +/* Macro declarations */ +/*****************************************************************************/ + + +/* SL internal Error codes */ + +/* Receive this error in case there are no resources to issue the command + If possible, increase the number of MAX_CUNCURENT_ACTIONS (result in memory increase) + If not, try again later */ +#define SL_POOL_IS_EMPTY (-2000) + +/* Receive this error in case a given length for RX buffer was too small. + Receive payload was bigger than the given buffer size. Therefore, payload is cut according to receive size + Recommend to increase buffer size */ +#define SL_ESMALLBUF (-2001) + +/* Receive this error in case zero length is supplied to a "get" API + Recommend to supply length according to requested information (view options defines for help) */ +#define SL_EZEROLEN (-2002) + +/* User supplied invalid parameter */ +#define SL_INVALPARAM (-2003) + +/* End of SL internal Error codes */ + + + +/*****************************************************************************/ +/* Errors returned from the general error async event */ +/*****************************************************************************/ + +/* Send types */ +typedef enum +{ + SL_ERR_SENDER_HEALTH_MON, + SL_ERR_SENDER_CLI_UART, + SL_ERR_SENDER_SUPPLICANT, + SL_ERR_SENDER_NETWORK_STACK, + SL_ERR_SENDER_WLAN_DRV_IF, + SL_ERR_SENDER_WILINK, + SL_ERR_SENDER_INIT_APP, + SL_ERR_SENDER_NETX, + SL_ERR_SENDER_HOST_APD, + SL_ERR_SENDER_MDNS, + SL_ERR_SENDER_HTTP_SERVER, + SL_ERR_SENDER_DHCP_SERVER, + SL_ERR_SENDER_DHCP_CLIENT, + SL_ERR_DISPATCHER, + SL_ERR_NUM_SENDER_LAST=0xFF +}SlErrorSender_e; + + +/* Error codes */ +#define SL_ERROR_STATIC_ADDR_SUBNET_ERROR (-60) /* network stack error*/ +#define SL_ERROR_ILLEGAL_CHANNEL (-61) /* supplicant error */ +#define SL_ERROR_SUPPLICANT_ERROR (-72) /* init error code */ +#define SL_ERROR_HOSTAPD_INIT_FAIL (-73) /* init error code */ +#define SL_ERROR_HOSTAPD_INIT_IF_FAIL (-74) /* init error code */ +#define SL_ERROR_WLAN_DRV_INIT_FAIL (-75) /* init error code */ +#define SL_ERROR_WLAN_DRV_START_FAIL (-76) /* wlan start error */ +#define SL_ERROR_FS_FILE_TABLE_LOAD_FAILED (-77) /* init file system failed */ +#define SL_ERROR_PREFERRED_NETWORKS_FILE_LOAD_FAILED (-78) /* init file system failed */ +#define SL_ERROR_HOSTAPD_BSSID_VALIDATION_ERROR (-79) /* Ap configurations BSSID error */ +#define SL_ERROR_HOSTAPD_FAILED_TO_SETUP_INTERFACE (-80) /* Ap configurations interface error */ +#define SL_ERROR_MDNS_ENABLE_FAIL (-81) /* mDNS enable failed */ +#define SL_ERROR_HTTP_SERVER_ENABLE_FAILED (-82) /* HTTP server enable failed */ +#define SL_ERROR_DHCP_SERVER_ENABLE_FAILED (-83) /* DHCP server enable failed */ +#define SL_ERROR_PREFERRED_NETWORK_LIST_FULL (-93) /* supplicant error */ +#define SL_ERROR_PREFERRED_NETWORKS_FILE_WRITE_FAILED (-94) /* supplicant error */ +#define SL_ERROR_DHCP_CLIENT_RENEW_FAILED (-100) /* DHCP client error */ +/* WLAN Connection management status */ +#define SL_ERROR_CON_MGMT_STATUS_UNSPECIFIED (-102) +#define SL_ERROR_CON_MGMT_STATUS_AUTH_REJECT (-103) +#define SL_ERROR_CON_MGMT_STATUS_ASSOC_REJECT (-104) +#define SL_ERROR_CON_MGMT_STATUS_SECURITY_FAILURE (-105) +#define SL_ERROR_CON_MGMT_STATUS_AP_DEAUTHENTICATE (-106) +#define SL_ERROR_CON_MGMT_STATUS_AP_DISASSOCIATE (-107) +#define SL_ERROR_CON_MGMT_STATUS_ROAMING_TRIGGER (-108) +#define SL_ERROR_CON_MGMT_STATUS_DISCONNECT_DURING_CONNECT (-109) +#define SL_ERROR_CON_MGMT_STATUS_SG_RESELECT (-110) +#define SL_ERROR_CON_MGMT_STATUS_ROC_FAILURE (-111) +#define SL_ERROR_CON_MGMT_STATUS_MIC_FAILURE (-112) +/* end of WLAN connection management error statuses */ +#define SL_ERROR_WAKELOCK_ERROR_PREFIX (-115) /* Wake lock expired */ +#define SL_ERROR_LENGTH_ERROR_PREFIX (-116) /* Uart header length error */ +#define SL_ERROR_MDNS_CREATE_FAIL (-121) /* mDNS create failed */ +#define SL_ERROR_GENERAL_ERROR (-127) + + + +#define SL_DEVICE_GENERAL_CONFIGURATION (1) +#define SL_DEVICE_GENERAL_CONFIGURATION_DATE_TIME (11) +#define SL_DEVICE_GENERAL_VERSION (12) +#define SL_DEVICE_STATUS (2) + +/* + Declare the different event group classifications + The SimpleLink device send asynchronous events. Each event has a group + classification according to its nature. +*/ +/* SL_EVENT_CLASS_WLAN connection user events */ +#define SL_WLAN_CONNECT_EVENT (1) +#define SL_WLAN_DISCONNECT_EVENT (2) +/* WLAN Smart Config user events */ +#define SL_WLAN_SMART_CONFIG_COMPLETE_EVENT (3) +#define SL_WLAN_SMART_CONFIG_STOP_EVENT (4) +/* WLAN AP user events */ +#define SL_WLAN_STA_CONNECTED_EVENT (5) +#define SL_WLAN_STA_DISCONNECTED_EVENT (6) +/* WLAN P2P user events */ +#define SL_WLAN_P2P_DEV_FOUND_EVENT (7) +#define SL_WLAN_P2P_NEG_REQ_RECEIVED_EVENT (8) +#define SL_WLAN_CONNECTION_FAILED_EVENT (9) +/* SL_EVENT_CLASS_DEVICE user events */ +#define SL_DEVICE_FATAL_ERROR_EVENT (1) +/* SL_EVENT_CLASS_BSD user events */ +#define SL_SOCKET_TX_FAILED_EVENT (1) +#define SL_SOCKET_ASYNC_EVENT (2) +/* SL_EVENT_CLASS_NETAPP user events */ +#define SL_NETAPP_IPV4_IPACQUIRED_EVENT (1) +#define SL_NETAPP_IPV6_IPACQUIRED_EVENT (2) +#define SL_NETAPP_IP_LEASED_EVENT (3) +#define SL_NETAPP_IP_RELEASED_EVENT (4) + +/* Server Events */ +#define SL_NETAPP_HTTPGETTOKENVALUE_EVENT (1) +#define SL_NETAPP_HTTPPOSTTOKENVALUE_EVENT (2) + + +/* + Declare the different event group classifications for sl_DevGet + for getting status indications + */ + +/* Events list to mask/unmask*/ +#define SL_EVENT_CLASS_GLOBAL (0) +#define SL_EVENT_CLASS_DEVICE (1) +#define SL_EVENT_CLASS_WLAN (2) +#define SL_EVENT_CLASS_BSD (3) +#define SL_EVENT_CLASS_NETAPP (4) +#define SL_EVENT_CLASS_NETCFG (5) +#define SL_EVENT_CLASS_FS (6) + + +/****************** DEVICE CLASS status ****************/ +#define EVENT_DROPPED_DEVICE_ASYNC_GENERAL_ERROR (0x00000001L) +#define STATUS_DEVICE_SMART_CONFIG_ACTIVE (0x80000000L) + +/****************** WLAN CLASS status ****************/ +#define EVENT_DROPPED_WLAN_WLANASYNCONNECTEDRESPONSE (0x00000001L) +#define EVENT_DROPPED_WLAN_WLANASYNCDISCONNECTEDRESPONSE (0x00000002L) +#define EVENT_DROPPED_WLAN_STA_CONNECTED (0x00000004L) +#define EVENT_DROPPED_WLAN_STA_DISCONNECTED (0x00000008L) +#define STATUS_WLAN_STA_CONNECTED (0x80000000L) + +/****************** NETAPP CLASS status ****************/ +#define EVENT_DROPPED_NETAPP_IPACQUIRED (0x00000001L) +#define EVENT_DROPPED_NETAPP_IPACQUIRED_V6 (0x00000002L) +#define EVENT_DROPPED_NETAPP_IP_LEASED (0x00000004L) +#define EVENT_DROPPED_NETAPP_IP_RELEASED (0x00000008L) + +/****************** BSD CLASS status ****************/ +#define EVENT_DROPPED_SOCKET_TXFAILEDASYNCRESPONSE (0x00000001L) + +/****************** FS CLASS ****************/ + + + +/*****************************************************************************/ +/* Structure/Enum declarations */ +/*****************************************************************************/ + +#ifdef SL_IF_TYPE_UART +typedef struct +{ + _u32 BaudRate; + _u8 FlowControlEnable; + _u8 CommPort; +} SlUartIfParams_t; +#endif + +typedef struct +{ + _u32 ChipId; + _u32 FwVersion[4]; + _u8 PhyVersion[4]; +}_SlPartialVersion; + +typedef struct +{ + _SlPartialVersion ChipFwAndPhyVersion; + _u32 NwpVersion[4]; + _u16 RomVersion; + _u16 Padding; +}SlVersionFull; + +typedef struct +{ + _i8 status; + SlErrorSender_e sender; +}sl_DeviceReport; + +typedef union +{ + sl_DeviceReport deviceEvent; +} _SlDeviceEventData_u; + +typedef struct +{ + _u32 Event; + _SlDeviceEventData_u EventData; +} SlDeviceEvent_t; + +typedef struct +{ + /* time */ + _u32 sl_tm_sec; + _u32 sl_tm_min; + _u32 sl_tm_hour; + /* date */ + _u32 sl_tm_day; /* 1-31 */ + _u32 sl_tm_mon; /* 1-12 */ + _u32 sl_tm_year; /* YYYY 4 digits */ + _u32 sl_tm_week_day; /* not required */ + _u32 sl_tm_year_day; /* not required */ + _u32 reserved[3]; +}SlDateTime_t; + + +/******************************************************************************/ +/* Type declarations */ +/******************************************************************************/ +typedef void (*P_INIT_CALLBACK)(_u32 Status); + +/*****************************************************************************/ +/* Function prototypes */ +/*****************************************************************************/ + +/*! + \brief Start the SimpleLink device + + This function initialize the communication interface, set the enable pin + of the device, and call to the init complete callback. + + \param[in] pIfHdl Opened Interface Object. In case the interface + must be opened outside the SimpleLink Driver, the + user might give the handler to be used in \n + any access of the communication interface with the + device (UART/SPI). \n + The SimpleLink driver will open an interface port + only if this parameter is null! \n + \param[in] pDevName The name of the device to open. Could be used when + the pIfHdl is null, to transfer information to the + open interface function \n + This pointer could be used to pass additional information to + sl_IfOpen in case it is required (e.g. UART com port name) + \param[in] pInitCallBack Pointer to function that would be called + on completion of the initialization process.\n + If this parameter is NULL the function is + blocked until the device initialization + is completed, otherwise the function returns + immediately. + + \return Returns the current active role (STA/AP/P2P) or an error code: + - ROLE_STA, ROLE_AP, ROLE_P2P in case of success, + otherwise in failure one of the following is return: + - ROLE_STA_ERR (Failure to load MAC/PHY in STA role) + - ROLE_AP_ERR (Failure to load MAC/PHY in AP role) + - ROLE_P2P_ERR (Failure to load MAC/PHY in P2P role) + + + \sa sl_Stop + + \note belongs to \ref basic_api + + \warning This function must be called before any other SimpleLink API is used, or after sl_Stop is called for reinit the device + \par Example: + \code + An example for open interface without callback routine. The interface name and handler are + handled by the sl_IfOpen routine: + + if( sl_Start(NULL, NULL, NULL) < 0 ) + { + LOG("Error opening interface to device\n"); + } + \endcode +*/ +#if _SL_INCLUDE_FUNC(sl_Start) +_i16 sl_Start(const void* pIfHdl, _i8* pDevName, const P_INIT_CALLBACK pInitCallBack); +#endif + +/*! + \brief Stop the SimpleLink device + + This function clears the enable pin of the device, closes the communication \n + interface and invokes the stop complete callback + + \param[in] timeout Stop timeout in msec. Should be used to give the device time to finish \n + any transmission/reception that is not completed when the function was called. \n + Additional options: + - 0 Enter to hibernate immediately \n + - 0xFFFF Host waits for device's response before \n + hibernating, without timeout protection \n + - 0 < Timeout[msec] < 0xFFFF Host waits for device's response before \n + hibernating, with a defined timeout protection \n + This timeout defines the max time to wait. The NWP \n + response can be sent earlier than this timeout. + + \return On success, zero is returned. On error, -1 is returned + + \sa sl_Start + + \note This API will shutdown the device and invoke the "i/f close" function regardless \n + if it was opened implicitly or explicitly. \n + It is up to the platform interface library to properly handle interface close \n + routine \n + belongs to \ref basic_api \n + \warning +*/ +#if _SL_INCLUDE_FUNC(sl_Stop) +_i16 sl_Stop(_u16 timeout); +#endif + + +/*! + \brief Internal function for setting device configurations + + \return On success, zero is returned. On error, -1 is + returned + + \param[in] DeviceSetId configuration id + \param[in] Option configurations option + \param[in] ConfigLen configurations len + \param[in] pValues configurations values + + \sa + \note + \warning + \par Examples: + \code + Setting device time and date example: + + SlDateTime_t dateTime= {0}; + dateTime.sl_tm_day = (_u32)23; // Day of month (DD format) range 1-13 + dateTime.sl_tm_mon = (_u32)6; // Month (MM format) in the range of 1-12 + dateTime.sl_tm_year = (_u32)2014; // Year (YYYY format) + dateTime.sl_tm_hour = (_u32)17; // Hours in the range of 0-23 + dateTime.sl_tm_min = (_u32)55; // Minutes in the range of 0-59 + dateTime.sl_tm_sec = (_u32)22; // Seconds in the range of 0-59 + sl_DevSet(SL_DEVICE_GENERAL_CONFIGURATION, + SL_DEVICE_GENERAL_CONFIGURATION_DATE_TIME, + sizeof(SlDateTime_t), + (_u8 *)(&dateTime)); + + \endcode +*/ +#if _SL_INCLUDE_FUNC(sl_DevSet) +_i32 sl_DevSet(_u8 DeviceSetId ,_u8 Option,_u8 ConfigLen, _u8 *pValues); +#endif + +/*! + \brief Internal function for getting device configurations + \return On success, zero is returned. On error, -1 is + returned + \param[in] DeviceGetId configuration id - example SL_DEVICE_STATUS + \param[out] pOption Get configurations option, example for get status options + - SL_EVENT_CLASS_GLOBAL + - SL_EVENT_CLASS_DEVICE + - SL_EVENT_CLASS_WLAN + - SL_EVENT_CLASS_BSD + - SL_EVENT_CLASS_NETAPP + - SL_EVENT_CLASS_NETCFG + - SL_EVENT_CLASS_FS + \param[out] pConfigLen The length of the allocated memory as input, when the + function complete, the value of this parameter would be + the len that actually read from the device.\n + If the device return length that is longer from the input + value, the function will cut the end of the returned structure + and will return SL_ESMALLBUF + \param[out] pValues Get configurations values + \sa + \note + \warning + \par Examples: + \code + Example for getting WLAN class status: + _u32 statusWlan; + _u8 pConfigOpt; + _u8 pConfigLen; + pConfigOpt = SL_EVENT_CLASS_WLAN; + sl_DevGet(SL_DEVICE_STATUS,&pConfigOpt,&pConfigLen,(_u8 *)(&statusWlan)); + Example for getting version: + SlVersionFull ver; + pConfigOpt = SL_DEVICE_GENERAL_VERSION; + sl_DevGet(SL_DEVICE_GENERAL_CONFIGURATION,&pConfigOpt,&pConfigLen,(_u8 *)(&ver)); + printf("CHIP %d\nMAC 31.%d.%d.%d.%d\nPHY %d.%d.%d.%d\nNWP %d.%d.%d.%d\nROM %d\nHOST %d.%d.%d.%d\n", + ver.ChipFwAndPhyVersion.ChipId, + ver.ChipFwAndPhyVersion.FwVersion[0],ver.ChipFwAndPhyVersion.FwVersion[1], + ver.ChipFwAndPhyVersion.FwVersion[2],ver.ChipFwAndPhyVersion.FwVersion[3], + ver.ChipFwAndPhyVersion.PhyVersion[0],ver.ChipFwAndPhyVersion.PhyVersion[1], + ver.ChipFwAndPhyVersion.PhyVersion[2],ver.ChipFwAndPhyVersion.PhyVersion[3], + ver.NwpVersion[0],ver.NwpVersion[1],ver.NwpVersion[2],ver.NwpVersion[3], + ver.RomVersion, + SL_MAJOR_VERSION_NUM,SL_MINOR_VERSION_NUM,SL_VERSION_NUM,SL_SUB_VERSION_NUM); + + \endcode + \code + Getting Device time and date example: + + SlDateTime_t dateTime = {0}; + _i8 configLen = sizeof(SlDateTime_t); + _i8 configOpt = SL_DEVICE_GENERAL_CONFIGURATION_DATE_TIME; + sl_DevGet(SL_DEVICE_GENERAL_CONFIGURATION,&configOpt, &configLen,(_u8 *)(&dateTime)); + + printf("Day %d,Mon %d,Year %d,Hour %,Min %d,Sec %d\n",dateTime.sl_tm_day,dateTime.sl_tm_mon,dateTime.sl_tm_year + dateTime.sl_tm_hour,dateTime.sl_tm_min,dateTime.sl_tm_sec); + \endcode +*/ +#if _SL_INCLUDE_FUNC(sl_DevGet) +_i32 sl_DevGet(_u8 DeviceGetId, _u8 *pOption,_u8 *pConfigLen, _u8 *pValues); +#endif + + +/*! + \brief Set asynchronous event mask + + Mask asynchronous events from the device. Masked events do not + generate asynchronous messages from the device. + By default - all events are active + + \param[in] EventClass The classification groups that the + mask is referred to. Need to be one of + the following: + - SL_EVENT_CLASS_GLOBAL + - SL_EVENT_CLASS_DEVICE + - SL_EVENT_CLASS_WLAN + - SL_EVENT_CLASS_BSD + - SL_EVENT_CLASS_NETAPP + - SL_EVENT_CLASS_NETCFG + - SL_EVENT_CLASS_FS + + + \param[in] Mask Event Mask bitmap. Valid mask are (per group): + - SL_EVENT_CLASS_WLAN user events + - SL_WLAN_CONNECT_EVENT + - SL_WLAN_DISCONNECT_EVENT + - SL_EVENT_CLASS_DEVICE user events + - SL_DEVICE_FATAL_ERROR_EVENT + - SL_EVENT_CLASS_BSD user events + - SL_SOCKET_TX_FAILED_EVENT + - SL_SOCKET_ASYNC_EVENT + - SL_EVENT_CLASS_NETAPP user events + - SL_NETAPP_IPV4_IPACQUIRED_EVENT + - SL_NETAPP_IPV6_IPACQUIRED_EVENT + + \return On success, zero is returned. On error, -1 is returned + + \sa sl_EventMaskGet + + \note belongs to \ref ext_api + + \warning + \par Example: + \code + + An example of masking connection/disconnection async events from WLAN class: + sl_EventMaskSet(SL_EVENT_CLASS_WLAN, (SL_WLAN_CONNECT_EVENT | SL_WLAN_DISCONNECT_EVENT) ); + + \endcode +*/ +#if _SL_INCLUDE_FUNC(sl_EventMaskSet) +_i16 sl_EventMaskSet(_u8 EventClass , _u32 Mask); +#endif + +/*! + \brief Get current event mask of the device + + return the events bit mask from the device. In case that event is + masked, the device is not sending this event. + + \param[in] EventClass The classification groups that the + mask is referred to. Need to be one of + the following: + - SL_EVENT_CLASS_GLOBAL + - SL_EVENT_CLASS_DEVICE + - SL_EVENT_CLASS_WLAN + - SL_EVENT_CLASS_BSD + - SL_EVENT_CLASS_NETAPP + - SL_EVENT_CLASS_NETCFG + - SL_EVENT_CLASS_FS + + \param[out] pMask Pointer to Mask bitmap where the + value should be stored. Bitmasks are the same as in \ref sl_EventMaskSet + + \return On success, zero is returned. On error, -1 is returned + + \sa sl_EventMaskSet + + \note belongs to \ref ext_api + + \warning + \par Example: + \code + + An example of getting an event mask for WLAN class + _u32 maskWlan; + sl_StatusGet(SL_EVENT_CLASS_WLAN,&maskWlan); + + \endcode +*/ +#if _SL_INCLUDE_FUNC(sl_EventMaskGet) +_i16 sl_EventMaskGet(_u8 EventClass, _u32 *pMask); +#endif + + +/*! + \brief the simple link task entry + + \Param + This function must be called from the main loop or from dedicated thread in + the following cases: + - Non-Os Platform - should be called from the mail loop + - Multi Threaded Platform when the user does not implement the external spawn functions - + should be called from dedicated thread allocated to the simplelink driver. + In this mode the function never return. + + \return None + + \sa sl_Stop + + \note belongs to \ref basic_api + + \warning This function must be called from a thread that is start running before + any call to other simple link API +*/ +#if _SL_INCLUDE_FUNC(sl_Task) +void sl_Task(void); +#endif + + +/*! + \brief Setting the internal uart mode + + \param[in] pUartParams Pointer to the uart configuration parameter set: + baudrate - up to 711 Kbps + flow control - enable/disable + comm port - the comm port number + + \return On success zero is returned, otherwise - Failed. + + \sa sl_Stop + + \note belongs to \ref basic_api + + \warning This function must consider the host uart capability +*/ +#ifdef SL_IF_TYPE_UART +#if _SL_INCLUDE_FUNC(sl_UartSetMode) +_i16 sl_UartSetMode(const SlUartIfParams_t* pUartParams); +#endif +#endif + +/*! + + Close the Doxygen group. + @} + + */ + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __DEVICE_H__ */ + + diff --git a/drivers/cc3100/inc/driver.h b/drivers/cc3100/inc/driver.h new file mode 100644 index 0000000000..9aa3b729a2 --- /dev/null +++ b/drivers/cc3100/inc/driver.h @@ -0,0 +1,220 @@ +/* + * driver.h - CC31xx/CC32xx Host Driver Implementation + * + * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +*/ + +#ifndef __DRIVER_INT_H__ +#define __DRIVER_INT_H__ + + +/*****************************************************************************/ +/* Macro declarations */ +/*****************************************************************************/ + +#ifndef CPU_FREQ_IN_MHZ + #define CPU_FREQ_IN_MHZ (200) +#endif +#define USEC_DELAY (50) + +/*****************************************************************************/ +/* Structure/Enum declarations */ +/*****************************************************************************/ + +typedef struct +{ + _SlOpcode_t Opcode; + _SlArgSize_t TxDescLen; + _SlArgSize_t RxDescLen; +}_SlCmdCtrl_t; + +typedef struct +{ + _u16 TxPayloadLen; + _u16 RxPayloadLen; + _u16 ActualRxPayloadLen; + _u8 *pTxPayload; + _u8 *pRxPayload; +}_SlCmdExt_t; + + +typedef struct _SlArgsData_t +{ + _u8 *pArgs; + _u8 *pData; +} _SlArgsData_t; + + +typedef struct _SlPoolObj_t +{ + _SlSyncObj_t SyncObj; + _u8 *pRespArgs; + _u8 ActionID; + _u8 AdditionalData; /* use for socketID and one bit which indicate supprt IPV6 or not (1=support, 0 otherwise) */ + _u8 NextIndex; + +} _SlPoolObj_t; + + +typedef enum +{ + SOCKET_0, + SOCKET_1, + SOCKET_2, + SOCKET_3, + SOCKET_4, + SOCKET_5, + SOCKET_6, + SOCKET_7, + MAX_SOCKET_ENUM_IDX, + ACCEPT_ID = MAX_SOCKET_ENUM_IDX, + CONNECT_ID, + SELECT_ID, + GETHOSYBYNAME_ID, + GETHOSYBYSERVICE_ID, + PING_ID, + START_STOP_ID, + RECV_ID +}_SlActionID_e; + +typedef struct _SlActionLookup_t +{ + _u8 ActionID; + _u16 ActionAsyncOpcode; + _SlSpawnEntryFunc_t AsyncEventHandler; + +} _SlActionLookup_t; + + +typedef struct +{ + _u8 TxPoolCnt; + _SlLockObj_t TxLockObj; + _SlSyncObj_t TxSyncObj; +}_SlFlowContCB_t; + +typedef enum +{ + RECV_RESP_CLASS, + CMD_RESP_CLASS, + ASYNC_EVT_CLASS, + DUMMY_MSG_CLASS +}_SlRxMsgClass_e; + +typedef struct +{ + _u8 *pAsyncBuf; /* place to write pointer to buffer with CmdResp's Header + Arguments */ + _u8 ActionIndex; + _SlSpawnEntryFunc_t AsyncEvtHandler; /* place to write pointer to AsyncEvent handler (calc-ed by Opcode) */ + _SlRxMsgClass_e RxMsgClass; /* type of Rx message */ +} AsyncExt_t; + +typedef _u8 _SlSd_t; + +typedef struct +{ + _SlCmdCtrl_t *pCmdCtrl; + _u8 *pTxRxDescBuff; + _SlCmdExt_t *pCmdExt; + AsyncExt_t AsyncExt; +}_SlFunctionParams_t; + + +typedef struct +{ + _SlFd_t FD; + _SlLockObj_t GlobalLockObj; + _SlCommandHeader_t TempProtocolHeader; + P_INIT_CALLBACK pInitCallback; + + _SlPoolObj_t ObjPool[MAX_CONCURRENT_ACTIONS]; + _u8 FreePoolIdx; + _u8 PendingPoolIdx; + _u8 ActivePoolIdx; + _u32 ActiveActionsBitmap; + _SlLockObj_t ProtectionLockObj; + + _SlSyncObj_t CmdSyncObj; + _u8 IsCmdRespWaited; + + _SlFlowContCB_t FlowContCB; + + _u8 TxSeqNum; + _volatile _u8 RxIrqCnt; + _u8 RxDoneCnt; + _u8 SocketNonBlocking; + _u8 SocketTXFailure; + _u8 RelayFlagsViaRxPayload; + /* for stack reduction the parameters are globals */ + _SlFunctionParams_t FunctionParams; + +}_SlDriverCb_t; + + + +extern _SlDriverCb_t* g_pCB; +extern P_SL_DEV_PING_CALLBACK pPingCallBackFunc; + +/*****************************************************************************/ +/* Function prototypes */ +/*****************************************************************************/ +extern void _SlDrvDriverCBInit(void); +extern void _SlDrvDriverCBDeinit(void); +extern void _SlDrvRxIrqHandler(void *pValue); +extern _SlReturnVal_t _SlDrvCmdOp(_SlCmdCtrl_t *pCmdCtrl , void* pTxRxDescBuff , _SlCmdExt_t* pCmdExt); +extern _SlReturnVal_t _SlDrvCmdSend(_SlCmdCtrl_t *pCmdCtrl , void* pTxRxDescBuff , _SlCmdExt_t* pCmdExt); +extern _SlReturnVal_t _SlDrvDataReadOp(_SlSd_t Sd, _SlCmdCtrl_t *pCmdCtrl , void* pTxRxDescBuff , _SlCmdExt_t* pCmdExt); +extern _SlReturnVal_t _SlDrvDataWriteOp(_SlSd_t Sd, _SlCmdCtrl_t *pCmdCtrl , void* pTxRxDescBuff , _SlCmdExt_t* pCmdExt); +extern _i16 _SlDrvBasicCmd(_SlOpcode_t Opcode); + +extern void _sl_HandleAsync_InitComplete(void *pVoidBuf); +extern void _sl_HandleAsync_Connect(void *pVoidBuf); +extern void _sl_HandleAsync_Accept(void *pVoidBuf); +extern void _sl_HandleAsync_Select(void *pVoidBuf); +extern void _sl_HandleAsync_DnsGetHostByName(void *pVoidBuf); +extern void _sl_HandleAsync_DnsGetHostByService(void *pVoidBuf); +extern void _sl_HandleAsync_DnsGetHostByAddr(void *pVoidBuf); +extern void _sl_HandleAsync_PingResponse(void *pVoidBuf); +extern void _SlDrvNetAppEventHandler(void *pArgs); +extern void _SlDrvDeviceEventHandler(void *pArgs); +extern void _sl_HandleAsync_Stop(void *pVoidBuf); +extern _i16 _SlDrvWaitForPoolObj(_u32 ActionID, _u8 SocketID); +extern void _SlDrvReleasePoolObj(_u8 pObj); +extern void _SlDrvObjInit(void); + +#define _SL_PROTOCOL_ALIGN_SIZE(msgLen) (((msgLen)+3) & (~3)) +#define _SL_IS_PROTOCOL_ALIGNED_SIZE(msgLen) (!((msgLen) & 3)) +#define _SL_PROTOCOL_CALC_LEN(pCmdCtrl,pCmdExt) ((pCmdExt) ? \ + (_SL_PROTOCOL_ALIGN_SIZE(pCmdCtrl->TxDescLen) + _SL_PROTOCOL_ALIGN_SIZE(pCmdExt->TxPayloadLen)) : \ + (_SL_PROTOCOL_ALIGN_SIZE(pCmdCtrl->TxDescLen))) +#endif /* __DRIVER_INT_H__ */ diff --git a/drivers/cc3100/inc/flowcont.h b/drivers/cc3100/inc/flowcont.h new file mode 100644 index 0000000000..3dcc130d83 --- /dev/null +++ b/drivers/cc3100/inc/flowcont.h @@ -0,0 +1,61 @@ +/* + * flowcont.h - CC31xx/CC32xx Host Driver Implementation + * + * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +*/ + +#ifndef __FLOWCONT_H__ +#define __FLOWCONT_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +/*****************************************************************************/ +/* Macro declarations */ +/*****************************************************************************/ +#define FLOW_CONT_MIN 1 + +/*****************************************************************************/ +/* Function prototypes */ +/*****************************************************************************/ +extern void _SlDrvFlowContInit(void); +extern void _SlDrvFlowContDeinit(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __FLOWCONT_H__ */ + diff --git a/drivers/cc3100/inc/fs.h b/drivers/cc3100/inc/fs.h new file mode 100644 index 0000000000..094b038138 --- /dev/null +++ b/drivers/cc3100/inc/fs.h @@ -0,0 +1,380 @@ +/* + * fs.h - CC31xx/CC32xx Host Driver Implementation + * + * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +*/ + +#ifndef __FS_H__ +#define __FS_H__ + +/*****************************************************************************/ +/* Include files */ +/*****************************************************************************/ + +#include "simplelink.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/*! + + \addtogroup FileSystem + @{ + +*/ + +/*****************************************************************************/ +/* Macro declarations */ +/*****************************************************************************/ + +/* FS error codes */ +#define SL_FS_OK (0) +#define SL_FS_ERR_EMPTY_SFLASH (-67) +#define SL_FS_ERR_FILE_IS_NOT_SECURE_AND_SIGN (-66) +#define SL_FS_ERASING_FLASH (-65) +#define SL_FS_FILE_HAS_NOT_BEEN_CLOSE_CORRECTLY (-64) +#define SL_FS_WRONG_SIGNATURE (-63) +#define SL_FS_WRONG_SIGNATURE_OR_CERTIFIC_NAME_LENGTH (-62) +#define SL_FS_NOT_16_ALIGNED (-61) +#define SL_FS_CERT_CHAIN_ERROR (-60) +#define SL_FS_FILE_NAME_EXIST (-59) +#define SL_FS_SECURITY_BUF_ALREADY_ALLOC (-58) +#define SL_FS_SECURE_FILE_MUST_BE_COMMIT (-57) +#define SL_FS_ERR_INCORRECT_OFFSET_ALIGNMENT (-56) +#define SL_FS_ERR_FAILED_READ_NVMEM_HEADER (-55) +#define SL_FS_WRONG_FILE_NAME (-54) +#define SL_FS_FILE_SYSTEM_IS_LOCKED (-53) +#define SL_FS_SECURITY_ALLERT (-52) +#define SL_FS_FILE_UNVALID_FILE_SIZE (-51) +#define SL_FS_ERR_TOKEN_IS_NOT_VALID (-50) +#define SL_FS_NO_DEVICE_IS_LOADED (-49) +#define SL_FS_DATA_ADDRESS_SHOUD_BE_IN_DATA_RAM (-48) +#define SL_FS_DATA_IS_NOT_ALIGNED (-47) +#define SL_FS_ERR_OVERLAP_DETECTION_THRESHHOLD (-46) +#define SL_FS_FILE_HAS_RESERVED_NV_INDEX (-45) +#define SL_FS_ERR_MAX_FS_FILES_IS_LARGER (-44) +#define SL_FS_ERR_MAX_FS_FILES_IS_SMALLER (-43) +#define SL_FS_FILE_MAX_SIZE_EXCEEDED (-42) +#define SL_FS_INVALID_BUFFER_FOR_READ (-41) +#define SL_FS_INVALID_BUFFER_FOR_WRITE (-40) +#define SL_FS_ERR_FILE_IMAGE_IS_CORRUPTED (-39) +#define SL_FS_ERR_SIZE_OF_FILE_EXT_EXCEEDED (-38) +#define SL_FS_WARNING_FILE_NAME_NOT_KEPT (-37) +#define SL_FS_ERR_DEVICE_IS_NOT_FORMATTED (-36) +#define SL_FS_ERR_FAILED_WRITE_NVMEM_HEADER (-35) +#define SL_FS_ERR_NO_AVAILABLE_NV_INDEX (-34) +#define SL_FS_ERR_FAILED_TO_ALLOCATE_MEM (-33) +#define SL_FS_ERR_FAILED_TO_READ_INTEGRITY_HEADER_2 (-32) +#define SL_FS_ERR_FAILED_TO_READ_INTEGRITY_HEADER_1 (-31) +#define SL_FS_ERR_NO_AVAILABLE_BLOCKS (-30) +#define SL_FS_ERR_FILE_MAX_SIZE_BIGGER_THAN_EXISTING_FILE (-29) +#define SL_FS_ERR_FILE_EXISTS_ON_DIFFERENT_DEVICE_ID (-28) +#define SL_FS_ERR_INVALID_ACCESS_TYPE (-27) +#define SL_FS_ERR_FILE_ALREADY_EXISTS (-26) +#define SL_FS_ERR_PROGRAM (-25) +#define SL_FS_ERR_NO_ENTRIES_AVAILABLE (-24) +#define SL_FS_ERR_FILE_ACCESS_IS_DIFFERENT (-23) +#define SL_FS_ERR_BAD_FILE_MODE (-22) +#define SL_FS_ERR_FAILED_READ_NVFILE (-21) +#define SL_FS_ERR_FAILED_INIT_STORAGE (-20) +#define SL_FS_ERR_CONTINUE_WRITE_MUST_BE_MOD_4 (-19) +#define SL_FS_ERR_FAILED_LOAD_FILE (-18) +#define SL_FS_ERR_INVALID_HANDLE (-17) +#define SL_FS_ERR_FAILED_TO_WRITE (-16) +#define SL_FS_ERR_OFFSET_OUT_OF_RANGE (-15) +#define SL_FS_ERR_ALLOC (-14) +#define SL_FS_ERR_READ_DATA_LENGTH (-13) +#define SL_FS_ERR_INVALID_FILE_ID (-12) +#define SL_FS_ERR_FILE_NOT_EXISTS (-11) +#define SL_FS_ERR_EMPTY_ERROR (-10) +#define SL_FS_ERR_INVALID_ARGS (-9) +#define SL_FS_ERR_FAILED_TO_CREATE_FILE (-8) +#define SL_FS_ERR_FS_ALREADY_LOADED (-7) +#define SL_FS_ERR_UNKNOWN (-6) +#define SL_FS_ERR_FAILED_TO_CREATE_LOCK_OBJ (-5) +#define SL_FS_ERR_DEVICE_NOT_LOADED (-4) +#define SL_FS_ERR_INVALID_MAGIC_NUM (-3) +#define SL_FS_ERR_FAILED_TO_READ (-2) +#define SL_FS_ERR_NOT_SUPPORTED (-1) +/* end of error codes */ + +#define _FS_MODE_ACCESS_RESERVED_OFFSET (24) +#define _FS_MODE_ACCESS_RESERVED_MASK (0xFF) +#define _FS_MODE_ACCESS_FLAGS_OFFSET (16) +#define _FS_MODE_ACCESS_FLAGS_MASK (0xFF) +#define _FS_MODE_ACCESS_OFFSET (12) +#define _FS_MODE_ACCESS_MASK (0xF) +#define _FS_MODE_OPEN_SIZE_GRAN_OFFSET (8) +#define _FS_MODE_OPEN_SIZE_GRAN_MASK (0xF) +#define _FS_MODE_OPEN_SIZE_OFFSET (0) +#define _FS_MODE_OPEN_SIZE_MASK (0xFF) +#define MAX_MODE_SIZE (0xFF) +#define _FS_MODE(Access, SizeGran, Size,Flags) (_u32)(((_u32)((Access) & _FS_MODE_ACCESS_MASK)<<_FS_MODE_ACCESS_OFFSET) | \ + ((_u32)((SizeGran) & _FS_MODE_OPEN_SIZE_GRAN_MASK)<<_FS_MODE_OPEN_SIZE_GRAN_OFFSET) | \ + ((_u32)((Size) & _FS_MODE_OPEN_SIZE_MASK)<<_FS_MODE_OPEN_SIZE_OFFSET) | \ + ((_u32)((Flags) & _FS_MODE_ACCESS_FLAGS_MASK)<<_FS_MODE_ACCESS_FLAGS_OFFSET)) + + +/* sl_FsOpen options */ +/* Open for Read */ +#define FS_MODE_OPEN_READ _FS_MODE(_FS_MODE_OPEN_READ,0,0,0) +/* Open for Write (in case file exist) */ +#define FS_MODE_OPEN_WRITE _FS_MODE(_FS_MODE_OPEN_WRITE,0,0,0) +/* Open for Creating a new file */ +#define FS_MODE_OPEN_CREATE(maxSizeInBytes,accessModeFlags) _sl_GetCreateFsMode(maxSizeInBytes,accessModeFlags) + +/*****************************************************************************/ +/* Structure/Enum declarations */ +/*****************************************************************************/ +typedef struct +{ + _u16 flags; + _u32 FileLen; + _u32 AllocatedLen; + _u32 Token[4]; +}SlFsFileInfo_t; + +typedef enum +{ + _FS_MODE_OPEN_READ = 0, + _FS_MODE_OPEN_WRITE, + _FS_MODE_OPEN_CREATE, + _FS_MODE_OPEN_WRITE_CREATE_IF_NOT_EXIST +}SlFsFileOpenAccessType_e; + +typedef enum +{ + _FS_FILE_OPEN_FLAG_COMMIT = 0x1, /* MIRROR - for fail safe */ + _FS_FILE_OPEN_FLAG_SECURE = 0x2, /* SECURE */ + _FS_FILE_OPEN_FLAG_NO_SIGNATURE_TEST = 0x4, /* Relevant to secure file only */ + _FS_FILE_OPEN_FLAG_STATIC = 0x8, /* Relevant to secure file only */ + _FS_FILE_OPEN_FLAG_VENDOR = 0x10, /* Relevant to secure file only */ + _FS_FILE_PUBLIC_WRITE = 0x20, /* Relevant to secure file only, the file can be opened for write without Token */ + _FS_FILE_PUBLIC_READ = 0x40 /* Relevant to secure file only, the file can be opened for read without Token */ +}SlFileOpenFlags_e; + +typedef enum +{ + _FS_MODE_SIZE_GRAN_256B = 0, /* MAX_SIZE = 64K */ + _FS_MODE_SIZE_GRAN_1KB, /* MAX_SIZE = 256K */ + _FS_MODE_SIZE_GRAN_4KB, /* MAX_SZIE = 1M */ + _FS_MODE_SIZE_GRAN_16KB, /* MAX_SIZE = 4M */ + _FS_MODE_SIZE_GRAN_64KB, /* MAX_SIZE = 16M */ + _FS_MAX_MODE_SIZE_GRAN +}_SlFsFileOpenMaxSizeGran_e; + +/*****************************************************************************/ +/* Internal Function prototypes */ +/*****************************************************************************/ +_u32 _sl_GetCreateFsMode(_u32 maxSizeInBytes,_u32 accessFlags); + +/*****************************************************************************/ +/* Function prototypes */ +/*****************************************************************************/ + +/*! + \brief open file for read or write from/to storage device + + \param[in] pFileName File Name buffer pointer + \param[in] AccessModeAndMaxSize Options: As described below + \param[in] pToken Reserved for future use. Use NULL for this field + \param[out] pFileHandle Pointing on the file and used for read and write commands to the file + + AccessModeAndMaxSize possible input \n + FS_MODE_OPEN_READ - Read a file \n + FS_MODE_OPEN_WRITE - Open for write for an existing file \n + FS_MODE_OPEN_CREATE(maxSizeInBytes,accessModeFlags) - Open for creating a new file. Max file size is defined in bytes. \n + For optimal FS size, use max size in 4K-512 bytes steps (e.g. 3584,7680,117760) \n + Several access modes bits can be combined together from SlFileOpenFlags_e enum + + \return On success, zero is returned. On error, an error code is returned + + \sa sl_FsRead sl_FsWrite sl_FsClose + \note belongs to \ref basic_api + \warning + \par Example: + \code + char* DeviceFileName = "MyFile.txt"; + unsigned long MaxSize = 63 * 1024; //62.5K is max file size + long DeviceFileHandle = -1; + long RetVal; //negative retval is an error + unsigned long Offset = 0; + unsigned char InputBuffer[100]; + + // Create a file and write data. The file in this example is secured, without signature and with a fail safe commit + RetVal = sl_FsOpen((unsigned char *)DeviceFileName, + FS_MODE_OPEN_CREATE(MaxSize , _FS_FILE_OPEN_FLAG_NO_SIGNATURE_TEST | _FS_FILE_OPEN_FLAG_COMMIT ), + NULL, &DeviceFileHandle); + + Offset = 0; + //Preferred in secure file that the Offset and the length will be aligned to 16 bytes. + RetVal = sl_FsWrite( DeviceFileHandle, Offset, (unsigned char *)"HelloWorld", strlen("HelloWorld")); + + RetVal = sl_FsClose(DeviceFileHandle, NULL, NULL , 0); + + // open the same file for read, using the Token we got from the creation procedure above + RetVal = sl_FsOpen((unsigned char *)DeviceFileName, + FS_MODE_OPEN_READ, + NULL, &DeviceFileHandle); + + Offset = 0; + RetVal = sl_FsRead( DeviceFileHandle, Offset, (unsigned char *)InputBuffer, strlen("HelloWorld")); + + RetVal = sl_FsClose(DeviceFileHandle, NULL, NULL , 0); + + \endcode +*/ +#if _SL_INCLUDE_FUNC(sl_FsOpen) +_i32 sl_FsOpen(_u8 *pFileName,_u32 AccessModeAndMaxSize,_u32 *pToken,_i32 *pFileHandle); +#endif + +/*! + \brief close file in storage device + + \param[in] FileHdl Pointer to the file (assigned from sl_FsOpen) + \param[in] pCeritificateFileName Reserved for future use. Use NULL. + \param[in] pSignature Reserved for future use. Use NULL. + \param[in] SignatureLen Reserved for future use. Use 0. + + + \return On success, zero is returned. On error, an error code is returned + + \sa sl_FsRead sl_FsWrite sl_FsOpen + \note Call the fs_Close with signature = 'A' signature len = 1 for activating an abort action + \warning + \par Example: + \code + sl_FsClose(FileHandle,0,0,0); + \endcode +*/ +#if _SL_INCLUDE_FUNC(sl_FsClose) +_i16 sl_FsClose(_i32 FileHdl,_u8* pCeritificateFileName,_u8* pSignature,_u32 SignatureLen); +#endif + +/*! + \brief Read block of data from a file in storage device + + \param[in] FileHdl Pointer to the file (assigned from sl_FsOpen) + \param[in] Offset Offset to specific read block + \param[out] pData Pointer for the received data + \param[in] Len Length of the received data + + \return On success, returns the number of read bytes. On error, negative number is returned + + \sa sl_FsClose sl_FsWrite sl_FsOpen + \note belongs to \ref basic_api + \warning + \par Example: + \code + Status = sl_FsRead(FileHandle, 0, &readBuff[0], readSize); + \endcode +*/ +#if _SL_INCLUDE_FUNC(sl_FsRead) +_i32 sl_FsRead(_i32 FileHdl,_u32 Offset ,_u8* pData,_u32 Len); +#endif + +/*! + \brief write block of data to a file in storage device + + \param[in] FileHdl Pointer to the file (assigned from sl_FsOpen) + \param[in] Offset Offset to specific block to be written + \param[in] pData Pointer the transmitted data to the storage device + \param[in] Len Length of the transmitted data + + \return On success, returns the number of written bytes. On error, an error code is returned + + \sa + \note belongs to \ref basic_api + \warning + \par Example: + \code + Status = sl_FsWrite(FileHandle, 0, &buff[0], readSize); + \endcode +*/ +#if _SL_INCLUDE_FUNC(sl_FsWrite) +_i32 sl_FsWrite(_i32 FileHdl,_u32 Offset,_u8* pData,_u32 Len); +#endif + +/*! + \brief get info on a file + + \param[in] pFileName File name + \param[in] Token Reserved for future use. Use 0 + \param[out] pFsFileInfo Returns the File's Information: flags,file size, allocated size and Tokens + + \return On success, zero is returned. On error, an error code is returned + + \sa sl_FsOpen + \note belongs to \ref basic_api + \warning + \par Example: + \code + Status = sl_FsGetInfo("FileName.html",0,&FsFileInfo); + \endcode +*/ +#if _SL_INCLUDE_FUNC(sl_FsGetInfo) +_i16 sl_FsGetInfo(_u8 *pFileName,_u32 Token,SlFsFileInfo_t* pFsFileInfo); +#endif + +/*! + \brief Delete specific file from a storage or all files from a storage (format) + + \param[in] pFileName File Name + \param[in] Token Reserved for future use. Use 0 + \return On success, zero is returned. On error, an error code is returned + + \sa + \note belongs to \ref basic_api + \warning + \par Example: + \code + Status = sl_FsDel("FileName.html",0); + \endcode +*/ +#if _SL_INCLUDE_FUNC(sl_FsDel) +_i16 sl_FsDel(_u8 *pFileName,_u32 Token); +#endif +/*! + + Close the Doxygen group. + @} + + */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __FS_H__ */ + diff --git a/drivers/cc3100/inc/netapp.h b/drivers/cc3100/inc/netapp.h new file mode 100644 index 0000000000..f14fd21a1a --- /dev/null +++ b/drivers/cc3100/inc/netapp.h @@ -0,0 +1,845 @@ +/* + * netapp.h - CC31xx/CC32xx Host Driver Implementation + * + * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +*/ + +#ifndef __NETAPP_H__ +#define __NETAPP_H__ + +/*****************************************************************************/ +/* Include files */ +/*****************************************************************************/ + +#include "simplelink.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +/*! + + \addtogroup netapp + @{ + +*/ + +/*****************************************************************************/ +/* Macro declarations */ +/*****************************************************************************/ + +/*ERROR code*/ +#define SL_ERROR_NETAPP_RX_BUFFER_LENGTH_ERROR (-230) + +/* Http Server interface */ +#define MAX_INPUT_STRING (64) /* because of WPA */ + +#define MAX_AUTH_NAME_LEN (20) +#define MAX_AUTH_PASSWORD_LEN (20) +#define MAX_AUTH_REALM_LEN (20) + +#define MAX_DEVICE_URN_LEN (15+1) +#define MAX_DOMAIN_NAME_LEN (24+1) + +#define MAX_ACTION_LEN (30) +/* Important: in case the max len is changed, make sure the struct sl_NetAppHttpServerSendToken_t in protocol.h is padded correctly! */ +#define MAX_TOKEN_NAME_LEN (20) +#define MAX_TOKEN_VALUE_LEN MAX_INPUT_STRING + +#define NETAPP_MAX_SERVICE_TEXT_SIZE (256) +#define NETAPP_MAX_SERVICE_NAME_SIZE (60) +#define NETAPP_MAX_SERVICE_HOST_NAME_SIZE (64) + + +/* Server Responses */ +#define SL_NETAPP_RESPONSE_NONE (0) +#define SL_NETAPP_HTTPSETTOKENVALUE (1) + +#define SL_NETAPP_FAMILY_MASK (0x80) + +/* mDNS types */ +#define SL_NET_APP_MASK_IPP_TYPE_OF_SERVICE (0x00000001) +#define SL_NET_APP_MASK_DEVICE_INFO_TYPE_OF_SERVICE (0x00000002) +#define SL_NET_APP_MASK_HTTP_TYPE_OF_SERVICE (0x00000004) +#define SL_NET_APP_MASK_HTTPS_TYPE_OF_SERVICE (0x00000008) +#define SL_NET_APP_MASK_WORKSATION_TYPE_OF_SERVICE (0x00000010) +#define SL_NET_APP_MASK_GUID_TYPE_OF_SERVICE (0x00000020) +#define SL_NET_APP_MASK_H323_TYPE_OF_SERVICE (0x00000040) +#define SL_NET_APP_MASK_NTP_TYPE_OF_SERVICE (0x00000080) +#define SL_NET_APP_MASK_OBJECITVE_TYPE_OF_SERVICE (0x00000100) +#define SL_NET_APP_MASK_RDP_TYPE_OF_SERVICE (0x00000200) +#define SL_NET_APP_MASK_REMOTE_TYPE_OF_SERVICE (0x00000400) +#define SL_NET_APP_MASK_RTSP_TYPE_OF_SERVICE (0x00000800) +#define SL_NET_APP_MASK_SIP_TYPE_OF_SERVICE (0x00001000) +#define SL_NET_APP_MASK_SMB_TYPE_OF_SERVICE (0x00002000) +#define SL_NET_APP_MASK_SOAP_TYPE_OF_SERVICE (0x00004000) +#define SL_NET_APP_MASK_SSH_TYPE_OF_SERVICE (0x00008000) +#define SL_NET_APP_MASK_TELNET_TYPE_OF_SERVICE (0x00010000) +#define SL_NET_APP_MASK_TFTP_TYPE_OF_SERVICE (0x00020000) +#define SL_NET_APP_MASK_XMPP_CLIENT_TYPE_OF_SERVICE (0x00040000) +#define SL_NET_APP_MASK_RAOP_TYPE_OF_SERVICE (0x00080000) +#define SL_NET_APP_MASK_ALL_TYPE_OF_SERVICE (0xFFFFFFFF) + +/********************************************************************************************************/ +/* sl_NetAppDnsGetHostByName error codes */ + +#define SL_NET_APP_DNS_QUERY_NO_RESPONSE (-159) /* DNS query failed, no response */ +#define SL_NET_APP_DNS_NO_SERVER (-161) /* No DNS server was specified */ +#define SL_NET_APP_DNS_PARAM_ERROR (-162) /* mDNS parameters error */ +#define SL_NET_APP_DNS_QUERY_FAILED (-163) /* DNS query failed; no DNS server sent an 'answer' */ +#define SL_NET_APP_DNS_INTERNAL_1 (-164) +#define SL_NET_APP_DNS_INTERNAL_2 (-165) +#define SL_NET_APP_DNS_MALFORMED_PACKET (-166) /* Improperly formed or corrupted DNS packet received */ +#define SL_NET_APP_DNS_INTERNAL_3 (-167) +#define SL_NET_APP_DNS_INTERNAL_4 (-168) +#define SL_NET_APP_DNS_INTERNAL_5 (-169) +#define SL_NET_APP_DNS_INTERNAL_6 (-170) +#define SL_NET_APP_DNS_INTERNAL_7 (-171) +#define SL_NET_APP_DNS_INTERNAL_8 (-172) +#define SL_NET_APP_DNS_INTERNAL_9 (-173) +#define SL_NET_APP_DNS_MISMATCHED_RESPONSE (-174) /* Server response type does not match the query request*/ +#define SL_NET_APP_DNS_INTERNAL_10 (-175) +#define SL_NET_APP_DNS_INTERNAL_11 (-176) +#define SL_NET_APP_DNS_NO_ANSWER (-177) /* No response for one-shot query */ +#define SL_NET_APP_DNS_NO_KNOWN_ANSWER (-178) /* No known answer for query */ +#define SL_NET_APP_DNS_NAME_MISMATCH (-179) /* Illegal service name according to the RFC */ +#define SL_NET_APP_DNS_NOT_STARTED (-180) /* mDNS is not running */ +#define SL_NET_APP_DNS_HOST_NAME_ERROR (-181) /* Host name error. Host name format is not allowed according to RFC 1033,1034,1035, 6763 */ +#define SL_NET_APP_DNS_NO_MORE_ENTRIES (-182) /* No more entries be found. */ + +#define SL_NET_APP_DNS_MAX_SERVICES_ERROR (-200) /* Maximum advertise services are already configured */ +#define SL_NET_APP_DNS_IDENTICAL_SERVICES_ERROR (-201) /* Trying to register a service that is already exists */ +#define SL_NET_APP_DNS_NOT_EXISTED_SERVICE_ERROR (-203) /* Trying to delete service that does not existed */ +#define SL_NET_APP_DNS_ERROR_SERVICE_NAME_ERROR (-204) /* Illegal service name according to the RFC */ +#define SL_NET_APP_DNS_RX_PACKET_ALLOCATION_ERROR (-205) /* Retry request */ +#define SL_NET_APP_DNS_BUFFER_SIZE_ERROR (-206) /* List size buffer is bigger than internally allowed in the NWP */ +#define SL_NET_APP_DNS_NET_APP_SET_ERROR (-207) /* Illegal length of one of the mDNS Set functions */ +#define SL_NET_APP_DNS_GET_SERVICE_LIST_FLAG_ERROR (-208) +#define SL_NET_APP_DNS_NO_CONFIGURATION_ERROR (-209) + +/* Set Dev name error codes (NETAPP_SET_GET_DEV_CONF_OPT_DEVICE_URN) */ +#define SL_ERROR_DEVICE_NAME_LEN_ERR (-117) +#define SL_ERROR_DEVICE_NAME_INVALID (-118) +/* Set domain name error codes (NETAPP_SET_GET_DEV_CONF_OPT_DOMAIN_NAME) */ +#define SL_ERROR_DOMAIN_NAME_LEN_ERR (-119) +#define SL_ERROR_DOMAIN_NAME_INVALID (-120) + +/********************************************************************************************************/ + +/* NetApp application IDs */ +#define SL_NET_APP_HTTP_SERVER_ID (1) +#define SL_NET_APP_DHCP_SERVER_ID (2) +#define SL_NET_APP_MDNS_ID (4) +#define SL_NET_APP_DNS_SERVER_ID (8) +#define SL_NET_APP_DEVICE_CONFIG_ID (16) +/* NetApp application set/get options */ +#define NETAPP_SET_DHCP_SRV_BASIC_OPT (0) +/* HTTP server set/get options */ +#define NETAPP_SET_GET_HTTP_OPT_PORT_NUMBER (0) +#define NETAPP_SET_GET_HTTP_OPT_AUTH_CHECK (1) +#define NETAPP_SET_GET_HTTP_OPT_AUTH_NAME (2) +#define NETAPP_SET_GET_HTTP_OPT_AUTH_PASSWORD (3) +#define NETAPP_SET_GET_HTTP_OPT_AUTH_REALM (4) +#define NETAPP_SET_GET_HTTP_OPT_ROM_PAGES_ACCESS (5) + +#define NETAPP_SET_GET_MDNS_CONT_QUERY_OPT (1) +#define NETAPP_SET_GET_MDNS_QEVETN_MASK_OPT (2) +#define NETAPP_SET_GET_MDNS_TIMING_PARAMS_OPT (3) + +/* DNS server set/get options */ +#define NETAPP_SET_GET_DNS_OPT_DOMAIN_NAME (0) + +/* Device Config set/get options */ +#define NETAPP_SET_GET_DEV_CONF_OPT_DEVICE_URN (0) +#define NETAPP_SET_GET_DEV_CONF_OPT_DOMAIN_NAME (1) + + +/*****************************************************************************/ +/* Structure/Enum declarations */ +/*****************************************************************************/ + +typedef struct +{ + _u32 PacketsSent; + _u32 PacketsReceived; + _u16 MinRoundTime; + _u16 MaxRoundTime; + _u16 AvgRoundTime; + _u32 TestTime; +}SlPingReport_t; + +typedef struct +{ + _u32 PingIntervalTime; /* delay between pings, in milliseconds */ + _u16 PingSize; /* ping packet size in bytes */ + _u16 PingRequestTimeout; /* timeout time for every ping in milliseconds */ + _u32 TotalNumberOfAttempts; /* max number of ping requests. 0 - forever */ + _u32 Flags; /* flag - 0 report only when finished, 1 - return response for every ping, 2 - stop after 1 successful ping. */ + _u32 Ip; /* IPv4 address or IPv6 first 4 bytes */ + _u32 Ip1OrPaadding; + _u32 Ip2OrPaadding; + _u32 Ip3OrPaadding; +}SlPingStartCommand_t; + +typedef struct _slHttpServerString_t +{ + _u8 len; + _u8 *data; +} slHttpServerString_t; + +typedef struct _slHttpServerData_t +{ + _u8 value_len; + _u8 name_len; + _u8 *token_value; + _u8 *token_name; +} slHttpServerData_t; + +typedef struct _slHttpServerPostData_t +{ + slHttpServerString_t action; + slHttpServerString_t token_name; + slHttpServerString_t token_value; +}slHttpServerPostData_t; + +typedef union +{ + slHttpServerString_t httpTokenName; /* SL_NETAPP_HTTPGETTOKENVALUE */ + slHttpServerPostData_t httpPostData; /* SL_NETAPP_HTTPPOSTTOKENVALUE */ +} SlHttpServerEventData_u; + +typedef union +{ + slHttpServerString_t token_value; +} SlHttpServerResponsedata_u; + +typedef struct +{ + _u32 Event; + SlHttpServerEventData_u EventData; +}SlHttpServerEvent_t; + +typedef struct +{ + _u32 Response; + SlHttpServerResponsedata_u ResponseData; +}SlHttpServerResponse_t; + + +typedef struct +{ + _u32 lease_time; + _u32 ipv4_addr_start; + _u32 ipv4_addr_last; +}SlNetAppDhcpServerBasicOpt_t; + +/*mDNS parameters*/ +typedef enum +{ + SL_NET_APP_FULL_SERVICE_WITH_TEXT_IPV4_TYPE = 1, + SL_NET_APP_FULL_SERVICE_IPV4_TYPE, + SL_NET_APP_SHORT_SERVICE_IPV4_TYPE + +} SlNetAppGetServiceListType_e; + +typedef struct +{ + _u32 service_ipv4; + _u16 service_port; + _u16 Reserved; +}SlNetAppGetShortServiceIpv4List_t; + +typedef struct +{ + _u32 service_ipv4; + _u16 service_port; + _u16 Reserved; + _u8 service_name[NETAPP_MAX_SERVICE_NAME_SIZE]; + _u8 service_host[NETAPP_MAX_SERVICE_HOST_NAME_SIZE]; +}SlNetAppGetFullServiceIpv4List_t; + +typedef struct +{ + _u32 service_ipv4; + _u16 service_port; + _u16 Reserved; + _u8 service_name[NETAPP_MAX_SERVICE_NAME_SIZE]; + _u8 service_host[NETAPP_MAX_SERVICE_HOST_NAME_SIZE]; + _u8 service_text[NETAPP_MAX_SERVICE_TEXT_SIZE]; +}SlNetAppGetFullServiceWithTextIpv4List_t; + +typedef struct +{ + /*The below parameters are used to configure the advertise times and interval + For example: + If: + Period is set to T + Repetitions are set to P + Telescopic factor is K=2 + The transmission shall be: + advertise P times + wait T + advertise P times + wait 4 * T + advertise P time + wait 16 * T ... (till max time reached / configuration changed / query issued) + */ + _u32 t; /* Number of ticks for the initial period. Default is 100 ticks for 1 second. */ + _u32 p; /* Number of repetitions. Default value is 1 */ + _u32 k; /* Telescopic factor. Default value is 2. */ + _u32 RetransInterval;/* Announcing retransmission interval */ + _u32 Maxinterval; /* Announcing max period interval */ + _u32 max_time; /* Announcing max time */ +}SlNetAppServiceAdvertiseTimingParameters_t; + +/*****************************************************************************/ +/* Types declarations */ +/*****************************************************************************/ +typedef void (*P_SL_DEV_PING_CALLBACK)(SlPingReport_t*); + +/*****************************************************************************/ +/* Function prototypes */ +/*****************************************************************************/ + + +/*! + \brief Starts a network application + + Gets and starts network application for the current WLAN mode + + \param[in] AppBitMap application bitmap, could be one or combination of the following: \n + - SL_NET_APP_HTTP_SERVER_ID + - SL_NET_APP_DHCP_SERVER_ID + - SL_NET_APP_MDNS_ID + + \return On error, negative number is returned + + \sa Stop one or more the above started applications using sl_NetAppStop + \note This command activates the application for the current WLAN mode (AP or STA) + \warning + \par Example: + \code + For example: Starting internal HTTP server + DHCP server: + sl_NetAppStart(SL_NET_APP_HTTP_SERVER_ID | SL_NET_APP_DHCP_SERVER_ID) + + \endcode +*/ +#if _SL_INCLUDE_FUNC(sl_NetAppStart) +_i16 sl_NetAppStart(_u32 AppBitMap); +#endif +/*! + \brief Stops a network application + + Gets and stops network application for the current WLAN mode + + \param[in] AppBitMap application id, could be one of the following: \n + - SL_NET_APP_HTTP_SERVER_ID + - SL_NET_APP_DHCP_SERVER_ID + - SL_NET_APP_MDNS_ID + + \return On error, negative number is returned + + \sa + \note This command disables the application for the current active WLAN mode (AP or STA) + \warning + \par Example: + \code + + For example: Stopping internal HTTP server: + sl_NetAppStop(SL_NET_APP_HTTP_SERVER_ID); + + \endcode +*/ +#if _SL_INCLUDE_FUNC(sl_NetAppStop) +_i16 sl_NetAppStop(_u32 AppBitMap); +#endif + +/*! + \brief Get host IP by name + + Obtain the IP Address of machine on network, by machine name. + + \param[in] hostname host name + \param[in] usNameLen name length + \param[out] out_ip_addr This parameter is filled in with + host IP address. In case that host name is not + resolved, out_ip_addr is zero. + \param[in] family protocol family + + \return On success, 0 is returned. + On error, negative is returned + SL_POOL_IS_EMPTY may be return in case there are no resources in the system + In this case try again later or increase MAX_CONCURRENT_ACTIONS + Possible DNS error codes: + - SL_NET_APP_DNS_QUERY_NO_RESPONSE + - SL_NET_APP_DNS_NO_SERVER + - SL_NET_APP_DNS_QUERY_FAILED + - SL_NET_APP_DNS_MALFORMED_PACKET + - SL_NET_APP_DNS_MISMATCHED_RESPONSE + + \sa + \note Only one sl_NetAppDnsGetHostByName can be handled at a time. + Calling this API while the same command is called from another thread, may result + in one of the two scenarios: + 1. The command will wait (internal) until the previous command finish, and then be executed. + 2. There are not enough resources and POOL_IS_EMPTY error will return. + In this case, MAX_CONCURRENT_ACTIONS can be increased (result in memory increase) or try + again later to issue the command. + \warning + \par Example: + \code + _u32 DestinationIP; + sl_NetAppDnsGetHostByName("www.google.com", strlen("www.google.com"), &DestinationIP,SL_AF_INET); + + Addr.sin_family = SL_AF_INET; + Addr.sin_port = sl_Htons(80); + Addr.sin_addr.s_addr = sl_Htonl(DestinationIP); + AddrSize = sizeof(SlSockAddrIn_t); + SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0); + \endcode +*/ +#if _SL_INCLUDE_FUNC(sl_NetAppDnsGetHostByName) +_i16 sl_NetAppDnsGetHostByName(_i8 * hostname, _u16 usNameLen, _u32* out_ip_addr,_u8 family ); +#endif + +/*! + \brief Return service attributes like IP address, port and text according to service name + \par + The user sets a service name Full/Part (see example below), and should get: + - IP of service + - The port of service + - The text of service + + Hence it can make a connection to the specific service and use it. + It is similar to get host by name method. + It is done by a single shot query with PTR type on the service name. + The command that is sent is from constant parameters and variables parameters. + + \param[in] pService Service name can be full or partial. \n + Example for full service name: + 1. PC1._ipp._tcp.local + 2. PC2_server._ftp._tcp.local \n + . + Example for partial service name: + 1. _ipp._tcp.local + 2. _ftp._tcp.local + + \param[in] ServiceLen The length of the service name (in_pService). + \param[in] Family IPv4 or IPv6 (SL_AF_INET , SL_AF_INET6). + \param[out] pAddr Contains the IP address of the service. + \param[out] pPort Contains the port of the service. + \param[out] pTextLen Has 2 options. One as Input field and the other one as output: + - Input: \n + Contains the max length of the text that the user wants to get.\n + It means that if the text len of service is bigger that its value than + the text is cut to inout_TextLen value. + - Output: \n + Contain the length of the text that is returned. Can be full text or part of the text (see above). + + \param[out] pOut_pText Contains the text of the service full or partial + + \return On success, zero is returned + SL_POOL_IS_EMPTY may be return in case there are no resources in the system + In this case try again later or increase MAX_CONCURRENT_ACTIONS + In case No service is found error SL_NET_APP_DNS_NO_ANSWER will be returned + + \note The returns attributes belongs to the first service found. + There may be other services with the same service name that will response to the query. + The results of these responses are saved in the peer cache of the Device and should be read by another API. + + Only one sl_NetAppDnsGetHostByService can be handled at a time. + Calling this API while the same command is called from another thread, may result + in one of the two scenarios: + 1. The command will wait (internal) until the previous command finish, and then be executed. + 2. There are not enough resources and SL_POOL_IS_EMPTY error will return. + In this case, MAX_CONCURRENT_ACTIONS can be increased (result in memory increase) or try + again later to issue the command. + + \warning Text length can be 120 bytes only +*/ +#if _SL_INCLUDE_FUNC(sl_NetAppDnsGetHostByService) +_i32 sl_NetAppDnsGetHostByService(_i8 *pServiceName, /* string containing all (or only part): name + subtype + service */ + _u8 ServiceLen, + _u8 Family, /* 4-IPv4 , 16-IPv6 */ + _u32 pAddr[], + _u32 *pPort, + _u16 *pTextLen, /* in: max len , out: actual len */ + _i8 *pText + ); + +#endif + +/*! + \brief Get service List + Insert into out pBuffer a list of peer's services that are the NWP. + The list is in a form of service struct. The user should chose the type + of the service struct like: + - Full service parameters with text. + - Full service parameters. + - Short service parameters (port and IP only) especially for tiny hosts. + + The different types of struct are made to give the + Possibility to save memory in the host + + + The user also chose how many max services to get and start point index + NWP peer cache. + For example: + 1. Get max of 3 full services from index 0.Up to 3 full services + from index 0 are inserted into pBuffer (services that are in indexes 0,1,2). + 2. Get max of 4 full services from index 3.Up to 4 full services + from index 3 are inserted into pBuffer (services that are in indexes 3,4,5,6). + 3. Get max of 2 int services from index 6.Up to 2 int services + from index 6 are inserted into pBuffer (services that are in indexes 6,7). + + See below - command parameters. + + \param[in] indexOffset - The start index in the peer cache that from it the first service is returned. + \param[in] MaxServiceCount - The Max services that can be returned if existed or if not exceed the max index + in the peer cache + \param[in] Flags - an ENUM number that means which service struct to use (means which types of service to fill) + - use SlNetAppGetFullServiceWithTextIpv4List_t + - use SlNetAppGetFullServiceIpv4List_t + - use SlNetAppGetShortServiceIpv4List_t + + \param[out] Buffer - The Services are inserted into this buffer. In the struct form according to the bit that is set in the Flags + input parameter. + + \return ServiceFoundCount - The number of the services that were inserted into the buffer. zero means no service is found + negative number means an error + \sa sl_NetAppMDNSRegisterService + \note + \warning + if the out pBuffer size is bigger than an RX packet(1480), than + an error is returned because there + is no place in the RX packet. + The size is a multiply of MaxServiceCount and size of service struct(that is set + according to flag value). +*/ + +#if _SL_INCLUDE_FUNC(sl_NetAppGetServiceList) +_i16 sl_NetAppGetServiceList(_u8 IndexOffest, + _u8 MaxServiceCount, + _u8 Flags, + _i8 *pBuffer, + _u32 RxBufferLength + ); + +#endif + +/*! + \brief Unregister mDNS service + This function deletes the mDNS service from the mDNS package and the database. + + The mDNS service that is to be unregistered is a service that the application no longer wishes to provide. \n + The service name should be the full service name according to RFC + of the DNS-SD - meaning the value in name field in the SRV answer. + + Examples for service names: + 1. PC1._ipp._tcp.local + 2. PC2_server._ftp._tcp.local + + \param[in] pServiceName Full service name. \n + Example for service name: + 1. PC1._ipp._tcp.local + 2. PC2_server._ftp._tcp.local + \param[in] ServiceLen The length of the service. + \return On success, zero is returned + \sa sl_NetAppMDNSRegisterService + \note + \warning + The size of the service length should be smaller than 255. +*/ +#if _SL_INCLUDE_FUNC(sl_NetAppMDNSUnRegisterService) +_i16 sl_NetAppMDNSUnRegisterService(const _i8 *pServiceName,_u8 ServiceNameLen); +#endif + +/*! + \brief Register a new mDNS service + \par + This function registers a new mDNS service to the mDNS package and the DB. + + This registered service is a service offered by the application. + The service name should be full service name according to RFC + of the DNS-SD - meaning the value in name field in the SRV answer. + Example for service name: + 1. PC1._ipp._tcp.local + 2. PC2_server._ftp._tcp.local + + If the option is_unique is set, mDNS probes the service name to make sure + it is unique before starting to announce the service on the network. + Instance is the instance portion of the service name. + + \param[in] ServiceLen The length of the service. + \param[in] TextLen The length of the service should be smaller than 64. + \param[in] port The port on this target host port. + \param[in] TTL The TTL of the service + \param[in] Options bitwise parameters: \n + - bit 0 - service is unique (means that the service needs to be unique) + - bit 31 - for internal use if the service should be added or deleted (set means ADD). + - bit 1-30 for future. + + \param[in] pServiceName The service name. + Example for service name: \n + 1. PC1._ipp._tcp.local + 2. PC2_server._ftp._tcp.local + + \param[in] pText The description of the service. + should be as mentioned in the RFC + (according to type of the service IPP,FTP...) + + \return On success, zero is returned + Possible error codes: + - Maximum advertise services are already configured. + Delete another existed service that is registered and then register again the new service + - Trying to register a service that is already exists + - Trying to delete service that does not existed + - Illegal service name according to the RFC + - Retry request + - Illegal length of one of the mDNS Set functions + - mDNS is not operational as the device has no IP.Connect the device to an AP to get an IP address. + - mDNS parameters error + - mDNS internal cache error + - mDNS internal error + - Adding a service is not allowed as it is already exist (duplicate service) + - mDNS is not running + - Host name error. Host name format is not allowed according to RFC 1033,1034,1035, 6763 + - List size buffer is bigger than internally allowed in the NWP (API get service list), + change the APIs’ parameters to decrease the size of the list + + + \sa sl_NetAppMDNSUnRegisterService + + \warning 1) Temporary - there is an allocation on stack of internal buffer. + Its size is NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH. \n + It means that the sum of the text length and service name length cannot be bigger than + NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH.\n + If it is - An error is returned. \n + 2) According to now from certain constraints the variables parameters are set in the + attribute part (contain constant parameters) +*/ +#if _SL_INCLUDE_FUNC(sl_NetAppMDNSRegisterService) +_i16 sl_NetAppMDNSRegisterService( const _i8* pServiceName, + _u8 ServiceNameLen, + const _i8* pText, + _u8 TextLen, + _u16 Port, + _u32 TTL, + _u32 Options); +#endif + +/*! + \brief send ICMP ECHO_REQUEST to network hosts + + Ping uses the ICMP protocol's mandatory ECHO_REQUEST + + \param[in] pPingParams Pointer to the ping request structure: \n + - if flags parameter is set to 0, ping will report back once all requested pings are done (as defined by TotalNumberOfAttempts). \n + - if flags parameter is set to 1, ping will report back after every ping, for TotalNumberOfAttempts. + - if flags parameter is set to 2, ping will stop after the first successful ping, and report back for the successful ping, as well as any preceding failed ones. + For stopping an ongoing ping activity, set parameters IP address to 0 + + \param[in] family SL_AF_INET or SL_AF_INET6 + \param[out] pReport Ping pReport + \param[out] pCallback Callback function upon completion. + If callback is NULL, the API is blocked until data arrives + + + \return On success, zero is returned. On error, -1 is returned + SL_POOL_IS_EMPTY may be return in case there are no resources in the system + In this case try again later or increase MAX_CONCURRENT_ACTIONS + + \sa sl_NetAppPingReport + \note Only one sl_NetAppPingStart can be handled at a time. + Calling this API while the same command is called from another thread, may result + in one of the two scenarios: + 1. The command will wait (internal) until the previous command finish, and then be executed. + 2. There are not enough resources and SL_POOL_IS_EMPTY error will return. + In this case, MAX_CONCURRENT_ACTIONS can be increased (result in memory increase) or try + again later to issue the command. + \warning + \par Example: + \code + + An example of sending 20 ping requests and reporting results to a callback routine when + all requests are sent: + + // callback routine + void pingRes(SlPingReport_t* pReport) + { + // handle ping results + } + + // ping activation + void PingTest() + { + SlPingReport_t report; + SlPingStartCommand_t pingCommand; + + pingCommand.Ip = SL_IPV4_VAL(10,1,1,200); // destination IP address is 10.1.1.200 + pingCommand.PingSize = 150; // size of ping, in bytes + pingCommand.PingIntervalTime = 100; // delay between pings, in milliseconds + pingCommand.PingRequestTimeout = 1000; // timeout for every ping in milliseconds + pingCommand.TotalNumberOfAttempts = 20; // max number of ping requests. 0 - forever + pingCommand.Flags = 0; // report only when finished + + sl_NetAppPingStart( &pingCommand, SL_AF_INET, &report, pingRes ) ; + } + + \endcode +*/ +#if _SL_INCLUDE_FUNC(sl_NetAppPingStart) +_i16 sl_NetAppPingStart(SlPingStartCommand_t* pPingParams,_u8 family,SlPingReport_t *pReport,const P_SL_DEV_PING_CALLBACK pPingCallback); +#endif + +/*! + \brief Internal function for setting network application configurations + + \return On success, zero is returned. On error, -1 is + returned + + \param[in] AppId Application id, could be one of the following: \n + - SL_NET_APP_HTTP_SERVER_ID + - SL_NET_APP_DHCP_SERVER_ID + - SL_NET_APP_DHCP_SERVER_ID + + \param[in] SetOptions set option, could be one of the following: \n + NETAPP_SET_BASIC_OPT + + \param[in] OptionLen option structure length + + \param[in] pOptionValues pointer to the option structure + \sa + \note + \warning + \par + \code + Set DHCP Server (AP mode) parameters example: + + SlNetAppDhcpServerBasicOpt_t dhcpParams; + _u8 outLen = sizeof(SlNetAppDhcpServerBasicOpt_t); + dhcpParams.lease_time = 4096; // lease time (in seconds) of the IP Address + dhcpParams.ipv4_addr_start = SL_IPV4_VAL(192,168,1,10); // first IP Address for allocation. IP Address should be set as Hex number - i.e. 0A0B0C01 for (10.11.12.1) + dhcpParams.ipv4_addr_last = SL_IPV4_VAL(192,168,1,16); // last IP Address for allocation. IP Address should be set as Hex number - i.e. 0A0B0C01 for (10.11.12.1) + sl_NetAppStop(SL_NET_APP_DHCP_SERVER_ID); // Stop DHCP server before settings + sl_NetAppSet(SL_NET_APP_DHCP_SERVER_ID, NETAPP_SET_DHCP_SRV_BASIC_OPT, outLen, (_u8* )&dhcpParams); // set parameters + sl_NetAppStart(SL_NET_APP_DHCP_SERVER_ID); // Start DHCP server with new settings + \endcode + \code + Set Device URN name example: + + Device name, maximum length of 33 characters + Device name affects URN name, own SSID name in AP mode, and WPS file "device name" in WPS I.E (STA-WPS / P2P) + In case no device URN name set, the default name is "mysimplelink" + Allowed characters in device name are: 'a - z' , 'A - Z' , '0-9' and '-' + + _u8 *my_device = "MY-SIMPLELINK-DEV"; + sl_NetAppSet (SL_NET_APP_DEVICE_CONFIG_ID, NETAPP_SET_GET_DEV_CONF_OPT_DEVICE_URN, strlen(my_device), (_u8 *) my_device); + \endcode + +*/ +#if _SL_INCLUDE_FUNC(sl_NetAppSet) +_i32 sl_NetAppSet(_u8 AppId ,_u8 Option,_u8 OptionLen, _u8 *pOptionValue); +#endif + +/*! + \brief Internal function for getting network applications configurations + + \return On success, zero is returned. On error, -1 is + returned + + \param[in] AppId Application id, could be one of the following: \n + - SL_NET_APP_HTTP_SERVER_ID + - SL_NET_APP_DHCP_SERVER_ID + + \param[in] Options Get option, could be one of the following: \n + NETAPP_SET_BASIC_OPT + + \param[in] OptionLen The length of the allocated memory as input, when the + function complete, the value of this parameter would be + the len that actually read from the device. + If the device return length that is longer from the input + value, the function will cut the end of the returned structure + and will return ESMALLBUF + + \param[out] pValues pointer to the option structure which will be filled with the response from the device + + \sa + \note + \warning + \par + \code + Get DHCP Server parameters example: + + SlNetAppDhcpServerBasicOpt_t dhcpParams; + _u8 outLen = sizeof(SlNetAppDhcpServerBasicOpt_t); + sl_NetAppGet(SL_NET_APP_DHCP_SERVER_ID, NETAPP_SET_DHCP_SRV_BASIC_OPT, &outLen, (_u8* )&dhcpParams); + + printf("DHCP Start IP %d.%d.%d.%d End IP %d.%d.%d.%d Lease time seconds %d\n", + SL_IPV4_BYTE(dhcpParams.ipv4_addr_start,3),SL_IPV4_BYTE(dhcpParams.ipv4_addr_start,2), + SL_IPV4_BYTE(dhcpParams.ipv4_addr_start,1),SL_IPV4_BYTE(dhcpParams.ipv4_addr_start,0), + SL_IPV4_BYTE(dhcpParams.ipv4_addr_last,3),SL_IPV4_BYTE(dhcpParams.ipv4_addr_last,2), + SL_IPV4_BYTE(dhcpParams.ipv4_addr_last,1),SL_IPV4_BYTE(dhcpParams.ipv4_addr_last,0), + dhcpParams.lease_time); + \endcode + \code + Get Device URN name example: + Maximum length of 33 characters of device name. + Device name affects URN name, own SSID name in AP mode, and WPS file "device name" in WPS I.E (STA-WPS / P2P) + in case no device URN name set, the default name is "mysimplelink" + + _u8 my_device_name[35]; + sl_NetAppGet (SL_NET_APP_DEVICE_CONFIG_ID, NETAPP_SET_GET_DEV_CONF_OPT_DEVICE_URN, strlen(my_device_name), (_u8 *)my_device_name); + \endcode +*/ +#if _SL_INCLUDE_FUNC(sl_NetAppGet) +_i32 sl_NetAppGet(_u8 AppId, _u8 Option,_u8 *pOptionLen, _u8 *pOptionValue); +#endif + + + +/*! + + Close the Doxygen group. + @} + + */ + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __NETAPP_H__ */ + diff --git a/drivers/cc3100/inc/netcfg.h b/drivers/cc3100/inc/netcfg.h new file mode 100644 index 0000000000..8014f062a1 --- /dev/null +++ b/drivers/cc3100/inc/netcfg.h @@ -0,0 +1,281 @@ +/* + * netcfg.h - CC31xx/CC32xx Host Driver Implementation + * + * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +*/ + +#ifndef __NETCFG_H__ +#define __NETCFG_H__ + +/*****************************************************************************/ +/* Include files */ +/*****************************************************************************/ +#include "simplelink.h" + +#ifdef __cplusplus +extern "C" { +#endif + + + +/*! + + \addtogroup netcfg + @{ + +*/ + + +/*****************************************************************************/ +/* Macro declarations */ +/*****************************************************************************/ + +#define SL_MAC_ADDR_LEN (6) +#define SL_IPV4_VAL(add_3,add_2,add_1,add_0) ((((_u32)add_3 << 24) & 0xFF000000) | (((_u32)add_2 << 16) & 0xFF0000) | (((_u32)add_1 << 8) & 0xFF00) | ((_u32)add_0 & 0xFF) ) +#define SL_IPV4_BYTE(val,index) ( (val >> (index*8)) & 0xFF ) + +#define IPCONFIG_MODE_DISABLE_IPV4 (0) +#define IPCONFIG_MODE_ENABLE_IPV4 (1) + +/*****************************************************************************/ +/* Structure/Enum declarations */ +/*****************************************************************************/ +typedef enum +{ + SL_MAC_ADDRESS_SET = 1, + SL_MAC_ADDRESS_GET = 2, + SL_IPV4_STA_P2P_CL_GET_INFO = 3, + SL_IPV4_STA_P2P_CL_DHCP_ENABLE = 4, + SL_IPV4_STA_P2P_CL_STATIC_ENABLE = 5, + SL_IPV4_AP_P2P_GO_GET_INFO = 6, + SL_IPV4_AP_P2P_GO_STATIC_ENABLE = 7, + SL_SET_HOST_RX_AGGR = 8, + MAX_SETTINGS = 0xFF +}Sl_NetCfg_e; + + +typedef struct +{ + _u32 ipV4; + _u32 ipV4Mask; + _u32 ipV4Gateway; + _u32 ipV4DnsServer; +}SlNetCfgIpV4Args_t; + + +/*****************************************************************************/ +/* Function prototypes */ +/*****************************************************************************/ + +/*! + \brief Internal function for setting network configurations + + \return On success, zero is returned. On error, -1 is + returned + + \param[in] ConfigId configuration id + \param[in] ConfigOpt configurations option + \param[in] ConfigLen configurations len + \param[in] pValues configurations values + + \sa + \note + \warning + + \par Examples: + \code + SL_MAC_ADDRESS_SET: + + Setting MAC address to the Device. + The new MAC address will override the default MAC address and it be saved in the FileSystem. + Requires restarting the device for updating this setting. + + _u8 MAC_Address[6]; + MAC_Address[0] = 0x8; + MAC_Address[1] = 0x0; + MAC_Address[2] = 0x28; + MAC_Address[3] = 0x22; + MAC_Address[4] = 0x69; + MAC_Address[5] = 0x31; + sl_NetCfgSet(SL_MAC_ADDRESS_SET,1,SL_MAC_ADDR_LEN,(_u8 *)newMacAddress); + sl_Stop(0); + sl_Start(NULL,NULL,NULL); + \endcode + + \code + SL_IPV4_STA_P2P_CL_STATIC_ENABLE: + + Setting a static IP address to the device working in STA mode or P2P client. + The IP address will be stored in the FileSystem. + In order to disable the static IP and get the address assigned from DHCP one should use SL_STA_P2P_CL_IPV4_DHCP_SET + + SlNetCfgIpV4Args_t ipV4; + ipV4.ipV4 = (_u32)SL_IPV4_VAL(10,1,1,201); // _u32 IP address + ipV4.ipV4Mask = (_u32)SL_IPV4_VAL(255,255,255,0); // _u32 Subnet mask for this STA/P2P + ipV4.ipV4Gateway = (_u32)SL_IPV4_VAL(10,1,1,1); // _u32 Default gateway address + ipV4.ipV4DnsServer = (_u32)SL_IPV4_VAL(8,16,32,64); // _u32 DNS server address + + sl_NetCfgSet(SL_IPV4_STA_P2P_CL_STATIC_ENABLE,IPCONFIG_MODE_ENABLE_IPV4,sizeof(SlNetCfgIpV4Args_t),(_u8 *)&ipV4); + sl_Stop(0); + sl_Start(NULL,NULL,NULL); + \endcode + + \code + SL_IPV4_STA_P2P_CL_DHCP_ENABLE: + + Setting IP address by DHCP to FileSystem using WLAN sta mode or P2P client. + This should be done once if using Serial Flash. + This is the system's default mode for acquiring an IP address after WLAN connection. + _u8 val = 1; + sl_NetCfgSet(SL_IPV4_STA_P2P_CL_DHCP_ENABLE,IPCONFIG_MODE_ENABLE_IPV4,1,&val); + sl_Stop(0); + sl_Start(NULL,NULL,NULL); + \endcode + + \code + SL_IPV4_AP_P2P_GO_STATIC_ENABLE: + + Setting a static IP address to the device working in AP mode or P2P go. + The IP address will be stored in the FileSystem. Requires restart. + + SlNetCfgIpV4Args_t ipV4; + ipV4.ipV4 = (_u32)SL_IPV4_VAL(10,1,1,201); // _u32 IP address + ipV4.ipV4Mask = (_u32)SL_IPV4_VAL(255,255,255,0); // _u32 Subnet mask for this AP/P2P + ipV4.ipV4Gateway = (_u32)SL_IPV4_VAL(10,1,1,1); // _u32 Default gateway address + ipV4.ipV4DnsServer = (_u32)SL_IPV4_VAL(8,16,32,64); // _u32 DNS server address + + sl_NetCfgSet(SL_IPV4_AP_P2P_GO_STATIC_ENABLE,IPCONFIG_MODE_ENABLE_IPV4,sizeof(SlNetCfgIpV4Args_t),(_u8 *)&ipV4); + sl_Stop(0); + sl_Start(NULL,NULL,NULL); + \endcode + + +*/ +#if _SL_INCLUDE_FUNC(sl_NetCfgSet) +_i32 sl_NetCfgSet(_u8 ConfigId ,_u8 ConfigOpt, _u8 ConfigLen, _u8 *pValues); +#endif + + +/*! + \brief Internal function for getting network configurations + + \return On success, zero is returned. On error, -1 is + returned + + \param[in] ConfigId configuration id + + \param[out] pConfigOpt Get configurations option + + \param[out] pConfigLen The length of the allocated memory as input, when the + function complete, the value of this parameter would be + the len that actually read from the device.\n + If the device return length that is longer from the input + value, the function will cut the end of the returned structure + and will return ESMALLBUF + + \param[out] pValues - get configurations values + + \sa + \note + \warning + \par Examples: + \code + SL_MAC_ADDRESS_GET: + + Get the device MAC address. + The returned MAC address is taken from FileSystem first. If the MAC address was not set by SL_MAC_ADDRESS_SET, the default MAC address + is retrieved from HW. + + _u8 macAddressVal[SL_MAC_ADDR_LEN]; + _u8 macAddressLen = SL_MAC_ADDR_LEN; + sl_NetCfgGet(SL_MAC_ADDRESS_GET,NULL,&macAddressLen,(_u8 *)macAddressVal); + + \endcode + + \code + SL_IPV4_STA_P2P_CL_GET_INFO: + + Get IP address from WLAN station or P2P client. A DHCP flag is returned to indicate if the IP address is static or from DHCP. + + _u8 len = sizeof(SlNetCfgIpV4Args_t); + _u8 dhcpIsOn = 0; + SlNetCfgIpV4Args_t ipV4 = {0}; + sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&dhcpIsOn,&len,(_u8 *)&ipV4); + + printf("DHCP is %s IP %d.%d.%d.%d MASK %d.%d.%d.%d GW %d.%d.%d.%d DNS %d.%d.%d.%d\n", + (dhcpIsOn > 0) ? "ON" : "OFF", + SL_IPV4_BYTE(ipV4.ipV4,3),SL_IPV4_BYTE(ipV4.ipV4,2),SL_IPV4_BYTE(ipV4.ipV4,1),SL_IPV4_BYTE(ipV4.ipV4,0), + SL_IPV4_BYTE(ipV4.ipV4Mask,3),SL_IPV4_BYTE(ipV4.ipV4Mask,2),SL_IPV4_BYTE(ipV4.ipV4Mask,1),SL_IPV4_BYTE(ipV4.ipV4Mask,0), + SL_IPV4_BYTE(ipV4.ipV4Gateway,3),SL_IPV4_BYTE(ipV4.ipV4Gateway,2),SL_IPV4_BYTE(ipV4.ipV4Gateway,1),SL_IPV4_BYTE(ipV4.ipV4Gateway,0), + SL_IPV4_BYTE(ipV4.ipV4DnsServer,3),SL_IPV4_BYTE(ipV4.ipV4DnsServer,2),SL_IPV4_BYTE(ipV4.ipV4DnsServer,1),SL_IPV4_BYTE(ipV4.ipV4DnsServer,0)); + + \endcode + + \code + SL_IPV4_AP_P2P_GO_GET_INFO: + + Get static IP address for AP or P2P go. + + _u8 len = sizeof(SlNetCfgIpV4Args_t); + _u8 dhcpIsOn = 0; // this flag is meaningless on AP/P2P go. + SlNetCfgIpV4Args_t ipV4 = {0}; + sl_NetCfgGet(SL_IPV4_AP_P2P_GO_GET_INFO,&dhcpIsOn,&len,(_u8 *)&ipV4); + + printf("IP %d.%d.%d.%d MASK %d.%d.%d.%d GW %d.%d.%d.%d DNS %d.%d.%d.%d\n", + SL_IPV4_BYTE(ipV4.ipV4,3),SL_IPV4_BYTE(ipV4.ipV4,2),SL_IPV4_BYTE(ipV4.ipV4,1),SL_IPV4_BYTE(ipV4.ipV4,0), + SL_IPV4_BYTE(ipV4.ipV4Mask,3),SL_IPV4_BYTE(ipV4.ipV4Mask,2),SL_IPV4_BYTE(ipV4.ipV4Mask,1),SL_IPV4_BYTE(ipV4.ipV4Mask,0), + SL_IPV4_BYTE(ipV4.ipV4Gateway,3),SL_IPV4_BYTE(ipV4.ipV4Gateway,2),SL_IPV4_BYTE(ipV4.ipV4Gateway,1),SL_IPV4_BYTE(ipV4.ipV4Gateway,0), + SL_IPV4_BYTE(ipV4.ipV4DnsServer,3),SL_IPV4_BYTE(ipV4.ipV4DnsServer,2),SL_IPV4_BYTE(ipV4.ipV4DnsServer,1),SL_IPV4_BYTE(ipV4.ipV4DnsServer,0)); + + \endcode + + +*/ +#if _SL_INCLUDE_FUNC(sl_NetCfgGet) +_i32 sl_NetCfgGet(_u8 ConfigId ,_u8 *pConfigOpt, _u8 *pConfigLen, _u8 *pValues); +#endif + +/*! + + Close the Doxygen group. + @} + + */ + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __NETCFG_H__ */ + diff --git a/drivers/cc3100/inc/nonos.h b/drivers/cc3100/inc/nonos.h new file mode 100644 index 0000000000..a888a90cf9 --- /dev/null +++ b/drivers/cc3100/inc/nonos.h @@ -0,0 +1,325 @@ +/* + * nonos.h - CC31xx/CC32xx Host Driver Implementation + * + * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +*/ + +#ifndef __NONOS_H__ +#define __NONOS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifndef SL_PLATFORM_MULTI_THREADED + +/* This function call the user defined function, if defined, from the sync wait loop */ +/* The use case of this function is to allow nonos system to call a user function to put the device into sleep */ +/* The wake up should be activated after getting an interrupt from the device to Host */ +/* The user function must return without blocking to prevent a delay on the event handling */ +/* +#define _SlSyncWaitLoopCallback UserSleepFunction +*/ + + + +#define NONOS_WAIT_FOREVER 0xFF +#define NONOS_NO_WAIT 0x01 + +#define NONOS_RET_OK (0) +#define NONOS_RET_ERR (0xFF) +#define OSI_OK NONOS_RET_OK + +#define __NON_OS_SYNC_OBJ_CLEAR_VALUE 0x11 +#define __NON_OS_SYNC_OBJ_SIGNAL_VALUE 0x22 +#define __NON_OS_LOCK_OBJ_UNLOCK_VALUE 0x33 +#define __NON_OS_LOCK_OBJ_LOCK_VALUE 0x44 + +/*! + \brief type definition for the return values of this adaptation layer +*/ +typedef _i8 _SlNonOsRetVal_t; + +/*! + \brief type definition for a time value +*/ +typedef _u8 _SlNonOsTime_t; + +/*! + \brief type definition for a sync object container + + Sync object is object used to synchronize between two threads or thread and interrupt handler. + One thread is waiting on the object and the other thread send a signal, which then + release the waiting thread. + The signal must be able to be sent from interrupt context. + This object is generally implemented by binary semaphore or events. +*/ +typedef _u8 _SlNonOsSemObj_t; + + +#define _SlTime_t _SlNonOsTime_t + +#define _SlSyncObj_t _SlNonOsSemObj_t + +#define _SlLockObj_t _SlNonOsSemObj_t + +#define SL_OS_WAIT_FOREVER NONOS_WAIT_FOREVER + +#define SL_OS_RET_CODE_OK NONOS_RET_OK + +#define SL_OS_NO_WAIT NONOS_NO_WAIT + + + + + +/*! + \brief This function creates a sync object + + The sync object is used for synchronization between different thread or ISR and + a thread. + + \param pSyncObj - pointer to the sync object control block + + \return upon successful creation the function return 0 + Otherwise, a negative value indicating the error code shall be returned + \note + \warning +*/ +#define _SlNonOsSyncObjCreate(pSyncObj) _SlNonOsSemSet(pSyncObj,__NON_OS_SYNC_OBJ_CLEAR_VALUE) + +/*! + \brief This function deletes a sync object + + \param pSyncObj - pointer to the sync object control block + + \return upon successful deletion the function should return 0 + Otherwise, a negative value indicating the error code shall be returned + \note + \warning +*/ +#define _SlNonOsSyncObjDelete(pSyncObj) _SlNonOsSemSet(pSyncObj,0) + +/*! + \brief This function generates a sync signal for the object. + + All suspended threads waiting on this sync object are resumed + + \param pSyncObj - pointer to the sync object control block + + \return upon successful signaling the function should return 0 + Otherwise, a negative value indicating the error code shall be returned + \note the function could be called from ISR context + \warning +*/ +#define _SlNonOsSyncObjSignal(pSyncObj) _SlNonOsSemSet(pSyncObj,__NON_OS_SYNC_OBJ_SIGNAL_VALUE) + +/*! + \brief This function waits for a sync signal of the specific sync object + + \param pSyncObj - pointer to the sync object control block + \param Timeout - numeric value specifies the maximum number of mSec to + stay suspended while waiting for the sync signal + Currently, the simple link driver uses only two values: + - NONOS_WAIT_FOREVER + - NONOS_NO_WAIT + + \return upon successful reception of the signal within the timeout window return 0 + Otherwise, a negative value indicating the error code shall be returned + \note + \warning +*/ +#define _SlNonOsSyncObjWait(pSyncObj , Timeout) _SlNonOsSemGet(pSyncObj,__NON_OS_SYNC_OBJ_SIGNAL_VALUE,__NON_OS_SYNC_OBJ_CLEAR_VALUE,Timeout) + +/*! + \brief This function clears a sync object + + \param pSyncObj - pointer to the sync object control block + + \return upon successful clearing the function should return 0 + Otherwise, a negative value indicating the error code shall be returned + \note + \warning +*/ +#define _SlNonOsSyncObjClear(pSyncObj) _SlNonOsSemSet(pSyncObj,__NON_OS_SYNC_OBJ_CLEAR_VALUE) + +/*! + \brief This function creates a locking object. + + The locking object is used for protecting a shared resources between different + threads. + + \param pLockObj - pointer to the locking object control block + + \return upon successful creation the function should return 0 + Otherwise, a negative value indicating the error code shall be returned + \note + \warning +*/ +#define _SlNonOsLockObjCreate(pLockObj) _SlNonOsSemSet(pLockObj,__NON_OS_LOCK_OBJ_UNLOCK_VALUE) + +/*! + \brief This function deletes a locking object. + + \param pLockObj - pointer to the locking object control block + + \return upon successful deletion the function should return 0 + Otherwise, a negative value indicating the error code shall be returned + \note + \warning +*/ +#define _SlNonOsLockObjDelete(pLockObj) _SlNonOsSemSet(pLockObj,0) + +/*! + \brief This function locks a locking object. + + All other threads that call this function before this thread calls + the _SlNonOsLockObjUnlock would be suspended + + \param pLockObj - pointer to the locking object control block + \param Timeout - numeric value specifies the maximum number of mSec to + stay suspended while waiting for the locking object + Currently, the simple link driver uses only two values: + - NONOS_WAIT_FOREVER + - NONOS_NO_WAIT + + + \return upon successful reception of the locking object the function should return 0 + Otherwise, a negative value indicating the error code shall be returned + \note + \warning +*/ +#define _SlNonOsLockObjLock(pLockObj , Timeout) _SlNonOsSemGet(pLockObj,__NON_OS_LOCK_OBJ_UNLOCK_VALUE,__NON_OS_LOCK_OBJ_LOCK_VALUE,Timeout) + +/*! + \brief This function unlock a locking object. + + \param pLockObj - pointer to the locking object control block + + \return upon successful unlocking the function should return 0 + Otherwise, a negative value indicating the error code shall be returned + \note + \warning +*/ +#define _SlNonOsLockObjUnlock(pLockObj) _SlNonOsSemSet(pLockObj,__NON_OS_LOCK_OBJ_UNLOCK_VALUE) + + +/*! + \brief This function call the pEntry callback from a different context + + \param pEntry - pointer to the entry callback function + + \param pValue - pointer to any type of memory structure that would be + passed to pEntry callback from the execution thread. + + \param flags - execution flags - reserved for future usage + + \return upon successful registration of the spawn the function return 0 + (the function is not blocked till the end of the execution of the function + and could be returned before the execution is actually completed) + Otherwise, a negative value indicating the error code shall be returned + \note + \warning +*/ +_SlNonOsRetVal_t _SlNonOsSpawn(_SlSpawnEntryFunc_t pEntry , void* pValue , _u32 flags); + + +/*! + \brief This function must be called from the main loop in non-os paltforms + + \param None + + \return 0 - No more activities + 1 - Activity still in progress + \note + \warning +*/ +_SlNonOsRetVal_t _SlNonOsMainLoopTask(void); + +extern _SlNonOsRetVal_t _SlNonOsSemGet(_SlNonOsSemObj_t* pSyncObj, _SlNonOsSemObj_t WaitValue, _SlNonOsSemObj_t SetValue, _SlNonOsTime_t Timeout); +extern _SlNonOsRetVal_t _SlNonOsSemSet(_SlNonOsSemObj_t* pSemObj , _SlNonOsSemObj_t Value); +extern _SlNonOsRetVal_t _SlNonOsSpawn(_SlSpawnEntryFunc_t pEntry , void* pValue , _u32 flags); + +#if (defined(_SlSyncWaitLoopCallback)) +extern void _SlSyncWaitLoopCallback(void); +#endif + + +/***************************************************************************** + + Overwrite SimpleLink driver OS adaptation functions + + + *****************************************************************************/ + +#undef sl_SyncObjCreate +#define sl_SyncObjCreate(pSyncObj,pName) _SlNonOsSemSet(pSyncObj,__NON_OS_SYNC_OBJ_CLEAR_VALUE) + +#undef sl_SyncObjDelete +#define sl_SyncObjDelete(pSyncObj) _SlNonOsSemSet(pSyncObj,0) + +#undef sl_SyncObjSignal +#define sl_SyncObjSignal(pSyncObj) _SlNonOsSemSet(pSyncObj,__NON_OS_SYNC_OBJ_SIGNAL_VALUE) + +#undef sl_SyncObjSignalFromIRQ +#define sl_SyncObjSignalFromIRQ(pSyncObj) _SlNonOsSemSet(pSyncObj,__NON_OS_SYNC_OBJ_SIGNAL_VALUE) + +#undef sl_SyncObjWait +#define sl_SyncObjWait(pSyncObj,Timeout) _SlNonOsSemGet(pSyncObj,__NON_OS_SYNC_OBJ_SIGNAL_VALUE,__NON_OS_SYNC_OBJ_CLEAR_VALUE,Timeout) + +#undef sl_LockObjCreate +#define sl_LockObjCreate(pLockObj,pName) _SlNonOsSemSet(pLockObj,__NON_OS_LOCK_OBJ_UNLOCK_VALUE) + +#undef sl_LockObjDelete +#define sl_LockObjDelete(pLockObj) _SlNonOsSemSet(pLockObj,0) + +#undef sl_LockObjLock +#define sl_LockObjLock(pLockObj,Timeout) _SlNonOsSemGet(pLockObj,__NON_OS_LOCK_OBJ_UNLOCK_VALUE,__NON_OS_LOCK_OBJ_LOCK_VALUE,Timeout) + +#undef sl_LockObjUnlock +#define sl_LockObjUnlock(pLockObj) _SlNonOsSemSet(pLockObj,__NON_OS_LOCK_OBJ_UNLOCK_VALUE) + +#undef sl_Spawn +#define sl_Spawn(pEntry,pValue,flags) _SlNonOsSpawn(pEntry,pValue,flags) + +#undef _SlTaskEntry +#define _SlTaskEntry _SlNonOsMainLoopTask + +#endif /* !SL_PLATFORM_MULTI_THREADED */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif diff --git a/drivers/cc3100/inc/objInclusion.h b/drivers/cc3100/inc/objInclusion.h new file mode 100644 index 0000000000..c636724057 --- /dev/null +++ b/drivers/cc3100/inc/objInclusion.h @@ -0,0 +1,325 @@ +/* + * objInclusion.h - CC31xx/CC32xx Host Driver Implementation + * + * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +*/ + +#include <simplelink.h> + +#ifndef OBJINCLUSION_H_ +#define OBJINCLUSION_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + + For future use + +*******************************************************************************/ + +#define __inln /* if inline functions requiered: #define __inln inline */ + +#define SL_DEVICE /* Device silo is currently always mandatory */ + + + +/****************************************************************************** + + Qualifiers for package customizations + +*******************************************************************************/ + +#if defined (SL_DEVICE) +#define __dev 1 +#else +#define __dev 0 +#endif + +#if defined (SL_DEVICE) && defined (SL_INC_EXT_API) +#define __dev__ext 1 +#else +#define __dev__ext 0 +#endif + + +#if (!defined (SL_PLATFORM_MULTI_THREADED)) || (!defined (SL_PLATFORM_EXTERNAL_SPAWN)) +#define __int__spwn 1 +#else +#define __int__spwn 0 +#endif + +#if defined (SL_INC_NET_APP_PKG) +#define __nap 1 +#else +#define __nap 0 +#endif + +#if defined (SL_INC_NET_APP_PKG) && defined (SL_INC_SOCK_CLIENT_SIDE_API) +#define __nap__clt 1 +#else +#define __nap__clt 0 +#endif + +#if defined (SL_INC_NET_APP_PKG) && defined (SL_INC_EXT_API) +#define __nap__ext 1 +#else +#define __nap__ext 0 +#endif + +#if defined (SL_INC_NET_CFG_PKG) +#define __ncg 1 +#else +#define __ncg 0 +#endif + +#if defined (SL_INC_NET_CFG_PKG) && defined (SL_INC_EXT_API) +#define __ncg__ext 1 +#else +#define __ncg__ext 0 +#endif + +#if defined (SL_INC_NVMEM_PKG) +#define __nvm 1 +#else +#define __nvm 0 +#endif + +#if defined (SL_INC_SOCKET_PKG) +#define __sck 1 +#else +#define __sck 0 +#endif + +#if defined (SL_INC_SOCKET_PKG) && defined (SL_INC_EXT_API) +#define __sck__ext 1 +#else +#define __sck__ext 0 +#endif + +#if defined (SL_INC_SOCKET_PKG) && defined (SL_INC_SOCK_SERVER_SIDE_API) +#define __sck__srv 1 +#else +#define __sck__srv 0 +#endif + +#if defined (SL_INC_SOCKET_PKG) && defined (SL_INC_SOCK_CLIENT_SIDE_API) +#define __sck__clt 1 +#else +#define __sck__clt 0 +#endif + +#if defined (SL_INC_SOCKET_PKG) && defined (SL_INC_SOCK_RECV_API) +#define __sck__rcv 1 +#else +#define __sck__rcv 0 +#endif + +#if defined (SL_INC_SOCKET_PKG) && defined (SL_INC_SOCK_SEND_API) +#define __sck__snd 1 +#else +#define __sck__snd 0 +#endif + +#if defined (SL_INC_WLAN_PKG) +#define __wln 1 +#else +#define __wln 0 +#endif + +#if defined (SL_INC_WLAN_PKG) && defined (SL_INC_EXT_API) +#define __wln__ext 1 +#else +#define __wln__ext 0 +#endif + +/* The return 1 is the function need to be included in the output */ +#define _SL_INCLUDE_FUNC(Name) (_SL_INC_##Name) + +/* Driver */ +#define _SL_INC_sl_NetAppStart __nap + +#define _SL_INC_sl_NetAppStop __nap + +#define _SL_INC_sl_NetAppDnsGetHostByName __nap__clt + + +#define _SL_INC_sl_NetAppDnsGetHostByService __nap__clt +#define _SL_INC_sl_NetAppMDNSRegisterService __nap__clt +#define _SL_INC_sl_NetAppMDNSUnRegisterService __nap__clt +#define _SL_INC_sl_NetAppMDNSRegisterUnregisterService __nap__clt +#define _SL_INC_sl_NetAppGetServiceList __nap__clt + + +#define _SL_INC_sl_DnsGetHostByAddr __nap__ext + +#define _SL_INC_sl_NetAppPingStart __nap + +#define _SL_INC_sl_NetAppPingReport __nap + +/* FS */ +#define _SL_INC_sl_FsOpen __nvm + +#define _SL_INC_sl_FsClose __nvm + +#define _SL_INC_sl_FsRead __nvm + +#define _SL_INC_sl_FsWrite __nvm + +#define _SL_INC_sl_FsGetInfo __nvm + +#define _SL_INC_sl_FsDel __nvm + +/* netcfg */ +#define _SL_INC_sl_MacAdrrSet __ncg + +#define _SL_INC_sl_MacAdrrGet __ncg + +#define _SL_INC_sl_NetCfgGet __ncg + +#define _SL_INC_sl_NetCfgSet __ncg + +#define _SL_INC_sl_NetAppSet __nap + +#define _SL_INC_sl_NetAppGet __nap + +/* socket */ +#define _SL_INC_sl_Socket __sck + +#define _SL_INC_sl_Close __sck__ext + +#define _SL_INC_sl_Accept __sck__srv + +#define _SL_INC_sl_Bind __sck + +#define _SL_INC_sl_Listen __sck__srv + +#define _SL_INC_sl_Connect __sck__clt + +#define _SL_INC_sl_Select __sck + +#define _SL_INC_sl_SetSockOpt __sck + +#define _SL_INC_sl_GetSockOpt __sck__ext + +#define _SL_INC_sl_Recv __sck__rcv + +#define _SL_INC_sl_RecvFrom __sck__rcv + +#define _SL_INC_sl_Write __sck__snd + +#define _SL_INC_sl_Send __sck__snd + +#define _SL_INC_sl_SendTo __sck__snd + +#define _SL_INC_sl_Htonl __sck + +#define _SL_INC_sl_Htons __sck + +/* wlan */ +#define _SL_INC_sl_WlanConnect __wln__ext + +#define _SL_INC_sl_WlanDisconnect __wln__ext + +#define _SL_INC_sl_WlanProfileAdd __wln__ext + +#define _SL_INC_sl_WlanProfileGet __wln__ext + +#define _SL_INC_sl_WlanProfileDel __wln__ext + +#define _SL_INC_sl_WlanPolicySet __wln__ext + +#define _SL_INC_sl_WlanPolicyGet __wln__ext + +#define _SL_INC_sl_WlanGetNetworkList __wln__ext + +#define _SL_INC_sl_WlanRxFilterAdd __wln__ext + +#define _SL_INC_sl_WlanRxFilterSet __wln__ext + +#define _SL_INC_sl_WlanRxFilterGet __wln__ext + +#define _SL_INC_sl_SmartConfigStart __wln + +#define _SL_INC_sl_SmartConfigOptSet __wln__ext + + +#define _SL_INC_sl_WlanSmartConfigStart __wln + +#define _SL_INC_sl_WlanSmartConfigStop __wln + +#define _SL_INC_sl_WlanSetMode __wln + +#define _SL_INC_sl_WlanSet __wln + +#define _SL_INC_sl_WlanGet __wln + +#define _SL_INC_sl_SmartConfigOptSet __wln__ext + +#define _SL_INC_sl_SmartConfigOptGet __wln__ext + +#define _SL_INC_sl_WlanRxStatStart __wln__ext + +#define _SL_INC_sl_WlanRxStatStop __wln__ext + +#define _SL_INC_sl_WlanRxStatGet __wln__ext + + +/* device */ +#define _SL_INC_sl_Task __int__spwn + +#define _SL_INC_sl_Start __dev + +#define _SL_INC_sl_Stop __dev + +#define _SL_INC_sl_StatusGet __dev + +#ifdef SL_IF_TYPE_UART +#define _SL_INC_sl_UartSetMode __dev +#endif + +#define _SL_INC_sl_EventMaskGet __dev__ext + +#define _SL_INC_sl_EventMaskSet __dev__ext + +#define _SL_INC_sl_DevGet __dev__ext + +#define _SL_INC_sl_DevSet __dev__ext + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /*OBJINCLUSION_H_ */ diff --git a/drivers/cc3100/inc/protocol.h b/drivers/cc3100/inc/protocol.h new file mode 100644 index 0000000000..f83ad4c3df --- /dev/null +++ b/drivers/cc3100/inc/protocol.h @@ -0,0 +1,1176 @@ +/* + * protocol.h - CC31xx/CC32xx Host Driver Implementation + * + * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +*/ + +/*******************************************************************************\ +* +* FILE NAME: protocol.h +* +* DESCRIPTION: Constant and data structure definitions and function +* prototypes for the SL protocol module, which implements +* processing of SimpleLink Commands. +* +* AUTHOR: +* +\*******************************************************************************/ + +#ifndef _SL_PROTOCOL_TYPES_H_ +#define _SL_PROTOCOL_TYPES_H_ + +/**************************************************************************** +** +** User I/F pools definitions +** +****************************************************************************/ + +/**************************************************************************** +** +** Definitions for SimpleLink Commands +** +****************************************************************************/ + + +/* pattern for LE 8/16/32 or BE*/ +#define H2N_SYNC_PATTERN {0xBBDDEEFF,0x4321,0x34,0x12} +#define H2N_CNYS_PATTERN {0xBBDDEEFF,0x8765,0x78,0x56} + +#define H2N_DUMMY_PATTERN (_u32)0xFFFFFFFF +#define N2H_SYNC_PATTERN (_u32)0xABCDDCBA +#define SYNC_PATTERN_LEN (_u32)sizeof(_u32) +#define UART_SET_MODE_MAGIC_CODE (_u32)0xAA55AA55 +#define SPI_16BITS_BUG(pattern) (_u32)((_u32)pattern & (_u32)0xFFFF7FFF) +#define SPI_8BITS_BUG(pattern) (_u32)((_u32)pattern & (_u32)0xFFFFFF7F) + + + +typedef struct +{ + _u16 Opcode; + _u16 Len; +}_SlGenericHeader_t; + + +typedef struct +{ + _u32 Long; + _u16 Short; + _u8 Byte1; + _u8 Byte2; +}_SlSyncPattern_t; + +typedef _SlGenericHeader_t _SlCommandHeader_t; + +typedef struct +{ + _SlGenericHeader_t GenHeader; + _u8 TxPoolCnt; + _u8 DevStatus; + _u8 SocketTXFailure; + _u8 SocketNonBlocking; +}_SlResponseHeader_t; + +#define _SL_RESP_SPEC_HDR_SIZE (sizeof(_SlResponseHeader_t) - sizeof(_SlGenericHeader_t)) +#define _SL_RESP_HDR_SIZE sizeof(_SlResponseHeader_t) +#define _SL_CMD_HDR_SIZE sizeof(_SlCommandHeader_t) + +#define _SL_RESP_ARGS_START(_pMsg) (((_SlResponseHeader_t *)(_pMsg)) + 1) + +/* Used only in NWP! */ +typedef struct +{ + _SlCommandHeader_t sl_hdr; + _u8 func_args_start; +} T_SCMD; + + +#define WLAN_CONN_STATUS_BIT 0x01 +#define EVENTS_Q_STATUS_BIT 0x02 +#define PENDING_RCV_CMD_BIT 0x04 +#define FW_BUSY_PACKETS_BIT 0x08 + +#define INIT_STA_OK 0x11111111 +#define INIT_STA_ERR 0x22222222 +#define INIT_AP_OK 0x33333333 +#define INIT_AP_ERR 0x44444444 +#define INIT_P2P_OK 0x55555555 +#define INIT_P2P_ERR 0x66666666 + +/**************************************************************************** +** OPCODES +****************************************************************************/ +#define SL_IPV4_IPV6_OFFSET ( 9 ) +#define SL_OPCODE_IPV4 ( 0x0 << SL_IPV4_IPV6_OFFSET ) +#define SL_OPCODE_IPV6 ( 0x1 << SL_IPV4_IPV6_OFFSET ) + +#define SL_SYNC_ASYNC_OFFSET ( 10 ) +#define SL_OPCODE_SYNC (0x1 << SL_SYNC_ASYNC_OFFSET ) +#define SL_OPCODE_SILO_OFFSET ( 11 ) +#define SL_OPCODE_SILO_MASK ( 0xF << SL_OPCODE_SILO_OFFSET ) +#define SL_OPCODE_SILO_DEVICE ( 0x0 << SL_OPCODE_SILO_OFFSET ) +#define SL_OPCODE_SILO_WLAN ( 0x1 << SL_OPCODE_SILO_OFFSET ) +#define SL_OPCODE_SILO_SOCKET ( 0x2 << SL_OPCODE_SILO_OFFSET ) +#define SL_OPCODE_SILO_NETAPP ( 0x3 << SL_OPCODE_SILO_OFFSET ) +#define SL_OPCODE_SILO_NVMEM ( 0x4 << SL_OPCODE_SILO_OFFSET ) +#define SL_OPCODE_SILO_NETCFG ( 0x5 << SL_OPCODE_SILO_OFFSET ) + +#define SL_FAMILY_SHIFT (0x4) +#define SL_FLAGS_MASK (0xF) + +#define SL_OPCODE_DEVICE_INITCOMPLETE 0x0008 +#define SL_OPCODE_DEVICE_STOP_COMMAND 0x8473 +#define SL_OPCODE_DEVICE_STOP_RESPONSE 0x0473 +#define SL_OPCODE_DEVICE_STOP_ASYNC_RESPONSE 0x0073 +#define SL_OPCODE_DEVICE_DEVICEASYNCDUMMY 0x0063 + +#define SL_OPCODE_DEVICE_VERSIONREADCOMMAND 0x8470 +#define SL_OPCODE_DEVICE_VERSIONREADRESPONSE 0x0470 +#define SL_OPCODE_DEVICE_DEVICEASYNCFATALERROR 0x0078 +#define SL_OPCODE_WLAN_WLANCONNECTCOMMAND 0x8C80 +#define SL_OPCODE_WLAN_WLANCONNECTRESPONSE 0x0C80 +#define SL_OPCODE_WLAN_WLANASYNCCONNECTEDRESPONSE 0x0880 +#define SL_OPCODE_WLAN_P2P_DEV_FOUND 0x0830 +#define SL_OPCODE_WLAN_CONNECTION_FAILED 0x0831 +#define SL_OPCODE_WLAN_P2P_NEG_REQ_RECEIVED 0x0832 + +#define SL_OPCODE_WLAN_WLANDISCONNECTCOMMAND 0x8C81 +#define SL_OPCODE_WLAN_WLANDISCONNECTRESPONSE 0x0C81 +#define SL_OPCODE_WLAN_WLANASYNCDISCONNECTEDRESPONSE 0x0881 +#define SL_OPCODE_WLAN_WLANCONNECTEAPCOMMAND 0x8C82 +#define SL_OPCODE_WLAN_WLANCONNECTEAPCRESPONSE 0x0C82 +#define SL_OPCODE_WLAN_PROFILEADDCOMMAND 0x8C83 +#define SL_OPCODE_WLAN_PROFILEADDRESPONSE 0x0C83 +#define SL_OPCODE_WLAN_PROFILEGETCOMMAND 0x8C84 +#define SL_OPCODE_WLAN_PROFILEGETRESPONSE 0x0C84 +#define SL_OPCODE_WLAN_PROFILEDELCOMMAND 0x8C85 +#define SL_OPCODE_WLAN_PROFILEDELRESPONSE 0x0C85 +#define SL_OPCODE_WLAN_POLICYSETCOMMAND 0x8C86 +#define SL_OPCODE_WLAN_POLICYSETRESPONSE 0x0C86 +#define SL_OPCODE_WLAN_POLICYGETCOMMAND 0x8C87 +#define SL_OPCODE_WLAN_POLICYGETRESPONSE 0x0C87 +#define SL_OPCODE_WLAN_FILTERADD 0x8C88 +#define SL_OPCODE_WLAN_FILTERADDRESPONSE 0x0C88 +#define SL_OPCODE_WLAN_FILTERGET 0x8C89 +#define SL_OPCODE_WLAN_FILTERGETRESPONSE 0x0C89 +#define SL_OPCODE_WLAN_FILTERDELETE 0x8C8A +#define SL_OPCODE_WLAN_FILTERDELETERESPOSNE 0x0C8A +#define SL_OPCODE_WLAN_WLANGETSTATUSCOMMAND 0x8C8F +#define SL_OPCODE_WLAN_WLANGETSTATUSRESPONSE 0x0C8F +#define SL_OPCODE_WLAN_STARTTXCONTINUESCOMMAND 0x8CAA +#define SL_OPCODE_WLAN_STARTTXCONTINUESRESPONSE 0x0CAA +#define SL_OPCODE_WLAN_STOPTXCONTINUESCOMMAND 0x8CAB +#define SL_OPCODE_WLAN_STOPTXCONTINUESRESPONSE 0x0CAB +#define SL_OPCODE_WLAN_STARTRXSTATCOMMAND 0x8CAC +#define SL_OPCODE_WLAN_STARTRXSTATRESPONSE 0x0CAC +#define SL_OPCODE_WLAN_STOPRXSTATCOMMAND 0x8CAD +#define SL_OPCODE_WLAN_STOPRXSTATRESPONSE 0x0CAD +#define SL_OPCODE_WLAN_GETRXSTATCOMMAND 0x8CAF +#define SL_OPCODE_WLAN_GETRXSTATRESPONSE 0x0CAF +#define SL_OPCODE_WLAN_POLICYSETCOMMANDNEW 0x8CB0 +#define SL_OPCODE_WLAN_POLICYSETRESPONSENEW 0x0CB0 +#define SL_OPCODE_WLAN_POLICYGETCOMMANDNEW 0x8CB1 +#define SL_OPCODE_WLAN_POLICYGETRESPONSENEW 0x0CB1 + +#define SL_OPCODE_WLAN_SMART_CONFIG_START_COMMAND 0x8CB2 +#define SL_OPCODE_WLAN_SMART_CONFIG_START_RESPONSE 0x0CB2 +#define SL_OPCODE_WLAN_SMART_CONFIG_START_ASYNC_RESPONSE 0x08B2 +#define SL_OPCODE_WLAN_SMART_CONFIG_STOP_COMMAND 0x8CB3 +#define SL_OPCODE_WLAN_SMART_CONFIG_STOP_RESPONSE 0x0CB3 +#define SL_OPCODE_WLAN_SMART_CONFIG_STOP_ASYNC_RESPONSE 0x08B3 +#define SL_OPCODE_WLAN_SET_MODE 0x8CB4 +#define SL_OPCODE_WLAN_SET_MODE_RESPONSE 0x0CB4 +#define SL_OPCODE_WLAN_CFG_SET 0x8CB5 +#define SL_OPCODE_WLAN_CFG_SET_RESPONSE 0x0CB5 +#define SL_OPCODE_WLAN_CFG_GET 0x8CB6 +#define SL_OPCODE_WLAN_CFG_GET_RESPONSE 0x0CB6 +#define SL_OPCODE_WLAN_STA_CONNECTED 0x082E +#define SL_OPCODE_WLAN_STA_DISCONNECTED 0x082F +#define SL_OPCODE_WLAN_EAP_PROFILEADDCOMMAND 0x8C67 +#define SL_OPCODE_WLAN_EAP_PROFILEADDCOMMAND_RESPONSE 0x0C67 + +#define SL_OPCODE_SOCKET_SOCKET 0x9401 +#define SL_OPCODE_SOCKET_SOCKETRESPONSE 0x1401 +#define SL_OPCODE_SOCKET_CLOSE 0x9402 +#define SL_OPCODE_SOCKET_CLOSERESPONSE 0x1402 +#define SL_OPCODE_SOCKET_ACCEPT 0x9403 +#define SL_OPCODE_SOCKET_ACCEPTRESPONSE 0x1403 +#define SL_OPCODE_SOCKET_ACCEPTASYNCRESPONSE 0x1003 +#define SL_OPCODE_SOCKET_ACCEPTASYNCRESPONSE_V6 0x1203 +#define SL_OPCODE_SOCKET_BIND 0x9404 +#define SL_OPCODE_SOCKET_BIND_V6 0x9604 +#define SL_OPCODE_SOCKET_BINDRESPONSE 0x1404 +#define SL_OPCODE_SOCKET_LISTEN 0x9405 +#define SL_OPCODE_SOCKET_LISTENRESPONSE 0x1405 +#define SL_OPCODE_SOCKET_CONNECT 0x9406 +#define SL_OPCODE_SOCKET_CONNECT_V6 0x9606 +#define SL_OPCODE_SOCKET_CONNECTRESPONSE 0x1406 +#define SL_OPCODE_SOCKET_CONNECTASYNCRESPONSE 0x1006 +#define SL_OPCODE_SOCKET_SELECT 0x9407 +#define SL_OPCODE_SOCKET_SELECTRESPONSE 0x1407 +#define SL_OPCODE_SOCKET_SELECTASYNCRESPONSE 0x1007 +#define SL_OPCODE_SOCKET_SETSOCKOPT 0x9408 +#define SL_OPCODE_SOCKET_SETSOCKOPTRESPONSE 0x1408 +#define SL_OPCODE_SOCKET_GETSOCKOPT 0x9409 +#define SL_OPCODE_SOCKET_GETSOCKOPTRESPONSE 0x1409 +#define SL_OPCODE_SOCKET_RECV 0x940A +#define SL_OPCODE_SOCKET_RECVASYNCRESPONSE 0x100A +#define SL_OPCODE_SOCKET_RECVFROM 0x940B +#define SL_OPCODE_SOCKET_RECVFROMASYNCRESPONSE 0x100B +#define SL_OPCODE_SOCKET_RECVFROMASYNCRESPONSE_V6 0x120B +#define SL_OPCODE_SOCKET_SEND 0x940C +#define SL_OPCODE_SOCKET_SENDTO 0x940D +#define SL_OPCODE_SOCKET_SENDTO_V6 0x960D +#define SL_OPCODE_SOCKET_TXFAILEDASYNCRESPONSE 0x100E +#define SL_OPCODE_SOCKET_SOCKETASYNCEVENT 0x100F +#define SL_OPCODE_NETAPP_START_COMMAND 0x9C0A +#define SL_OPCODE_NETAPP_START_RESPONSE 0x1C0A +#define SL_OPCODE_NETAPP_NETAPPSTARTRESPONSE 0x1C0A +#define SL_OPCODE_NETAPP_STOP_COMMAND 0x9C61 +#define SL_OPCODE_NETAPP_STOP_RESPONSE 0x1C61 +#define SL_OPCODE_NETAPP_NETAPPSET 0x9C0B +#define SL_OPCODE_NETAPP_NETAPPSETRESPONSE 0x1C0B +#define SL_OPCODE_NETAPP_NETAPPGET 0x9C27 +#define SL_OPCODE_NETAPP_NETAPPGETRESPONSE 0x1C27 +#define SL_OPCODE_NETAPP_DNSGETHOSTBYNAME 0x9C20 +#define SL_OPCODE_NETAPP_DNSGETHOSTBYNAMERESPONSE 0x1C20 +#define SL_OPCODE_NETAPP_DNSGETHOSTBYNAMEASYNCRESPONSE 0x1820 +#define SL_OPCODE_NETAPP_DNSGETHOSTBYNAMEASYNCRESPONSE_V6 0x1A20 +#define SL_OPCODE_NETAPP_NETAPP_MDNS_LOOKUP_SERVICE 0x9C71 +#define SL_OPCODE_NETAPP_NETAPP_MDNS_LOOKUP_SERVICE_RESPONSE 0x1C72 +#define SL_OPCODE_NETAPP_MDNSREGISTERSERVICE 0x9C34 +#define SL_OPCODE_NETAPP_MDNSREGISTERSERVICERESPONSE 0x1C34 +#define SL_OPCODE_NETAPP_MDNSGETHOSTBYSERVICE 0x9C35 +#define SL_OPCODE_NETAPP_MDNSGETHOSTBYSERVICERESPONSE 0x1C35 +#define SL_OPCODE_NETAPP_MDNSGETHOSTBYSERVICEASYNCRESPONSE 0x1835 +#define SL_OPCODE_NETAPP_MDNSGETHOSTBYSERVICEASYNCRESPONSE_V6 0x1A35 +#define SL_OPCODE_NETAPP_DNSGETHOSTBYADDR 0x9C26 +#define SL_OPCODE_NETAPP_DNSGETHOSTBYADDR_V6 0x9E26 +#define SL_OPCODE_NETAPP_DNSGETHOSTBYADDRRESPONSE 0x1C26 +#define SL_OPCODE_NETAPP_DNSGETHOSTBYADDRASYNCRESPONSE 0x1826 +#define SL_OPCODE_NETAPP_PINGSTART 0x9C21 +#define SL_OPCODE_NETAPP_PINGSTART_V6 0x9E21 +#define SL_OPCODE_NETAPP_PINGSTARTRESPONSE 0x1C21 +#define SL_OPCODE_NETAPP_PINGREPORTREQUEST 0x9C22 +#define SL_OPCODE_NETAPP_PINGREPORTREQUESTRESPONSE 0x1822 +#define SL_OPCODE_NETAPP_PINGSTOP 0x9C23 +#define SL_OPCODE_NETAPP_PINGSTOPRESPONSE 0x1C23 +#define SL_OPCODE_NETAPP_ARPFLUSH 0x9C24 +#define SL_OPCODE_NETAPP_ARPFLUSHRESPONSE 0x1C24 +#define SL_OPCODE_NETAPP_IPACQUIRED 0x1825 +#define SL_OPCODE_NETAPP_IPV4_LOST 0x1832 +#define SL_OPCODE_NETAPP_DHCP_IPV4_ACQUIRE_TIMEOUT 0x1833 +#define SL_OPCODE_NETAPP_IPACQUIRED_V6 0x1A25 +#define SL_OPCODE_NETAPP_IPERFSTARTCOMMAND 0x9C28 +#define SL_OPCODE_NETAPP_IPERFSTARTRESPONSE 0x1C28 +#define SL_OPCODE_NETAPP_IPERFSTOPCOMMAND 0x9C29 +#define SL_OPCODE_NETAPP_IPERFSTOPRESPONSE 0x1C29 +#define SL_OPCODE_NETAPP_CTESTSTARTCOMMAND 0x9C2A +#define SL_OPCODE_NETAPP_CTESTSTARTRESPONSE 0x1C2A +#define SL_OPCODE_NETAPP_CTESTASYNCRESPONSE 0x182A +#define SL_OPCODE_NETAPP_CTESTSTOPCOMMAND 0x9C2B +#define SL_OPCODE_NETAPP_CTESTSTOPRESPONSE 0x1C2B +#define SL_OPCODE_NETAPP_IP_LEASED 0x182C +#define SL_OPCODE_NETAPP_IP_RELEASED 0x182D +#define SL_OPCODE_NETAPP_HTTPGETTOKENVALUE 0x182E +#define SL_OPCODE_NETAPP_HTTPSENDTOKENVALUE 0x9C2F +#define SL_OPCODE_NETAPP_HTTPPOSTTOKENVALUE 0x1830 +#define SL_OPCODE_NVMEM_FILEOPEN 0xA43C +#define SL_OPCODE_NVMEM_FILEOPENRESPONSE 0x243C +#define SL_OPCODE_NVMEM_FILECLOSE 0xA43D +#define SL_OPCODE_NVMEM_FILECLOSERESPONSE 0x243D +#define SL_OPCODE_NVMEM_FILEREADCOMMAND 0xA440 +#define SL_OPCODE_NVMEM_FILEREADRESPONSE 0x2440 +#define SL_OPCODE_NVMEM_FILEWRITECOMMAND 0xA441 +#define SL_OPCODE_NVMEM_FILEWRITERESPONSE 0x2441 +#define SL_OPCODE_NVMEM_FILEGETINFOCOMMAND 0xA442 +#define SL_OPCODE_NVMEM_FILEGETINFORESPONSE 0x2442 +#define SL_OPCODE_NVMEM_FILEDELCOMMAND 0xA443 +#define SL_OPCODE_NVMEM_FILEDELRESPONSE 0x2443 +#define SL_OPCODE_NVMEM_NVMEMFORMATCOMMAND 0xA444 +#define SL_OPCODE_NVMEM_NVMEMFORMATRESPONSE 0x2444 + +#define SL_OPCODE_DEVICE_SETDEBUGLEVELCOMMAND 0x846A +#define SL_OPCODE_DEVICE_SETDEBUGLEVELRESPONSE 0x046A + +#define SL_OPCODE_DEVICE_NETCFG_SET_COMMAND 0x8432 +#define SL_OPCODE_DEVICE_NETCFG_SET_RESPONSE 0x0432 +#define SL_OPCODE_DEVICE_NETCFG_GET_COMMAND 0x8433 +#define SL_OPCODE_DEVICE_NETCFG_GET_RESPONSE 0x0433 +/* */ +#define SL_OPCODE_DEVICE_SETUARTMODECOMMAND 0x846B +#define SL_OPCODE_DEVICE_SETUARTMODERESPONSE 0x046B +#define SL_OPCODE_DEVICE_SSISIZESETCOMMAND 0x846B +#define SL_OPCODE_DEVICE_SSISIZESETRESPONSE 0x046B + +/* */ +#define SL_OPCODE_DEVICE_EVENTMASKSET 0x8464 +#define SL_OPCODE_DEVICE_EVENTMASKSETRESPONSE 0x0464 +#define SL_OPCODE_DEVICE_EVENTMASKGET 0x8465 +#define SL_OPCODE_DEVICE_EVENTMASKGETRESPONSE 0x0465 + +#define SL_OPCODE_DEVICE_DEVICEGET 0x8466 +#define SL_OPCODE_DEVICE_DEVICEGETRESPONSE 0x0466 +#define SL_OPCODE_DEVICE_DEVICESET 0x84B7 +#define SL_OPCODE_DEVICE_DEVICESETRESPONSE 0x04B7 + +#define SL_OPCODE_WLAN_SCANRESULTSGETCOMMAND 0x8C8C +#define SL_OPCODE_WLAN_SCANRESULTSGETRESPONSE 0x0C8C +#define SL_OPCODE_WLAN_SMARTCONFIGOPTSET 0x8C8D +#define SL_OPCODE_WLAN_SMARTCONFIGOPTSETRESPONSE 0x0C8D +#define SL_OPCODE_WLAN_SMARTCONFIGOPTGET 0x8C8E +#define SL_OPCODE_WLAN_SMARTCONFIGOPTGETRESPONSE 0x0C8E + +#define SL_OPCODE_FREE_BSD_RECV_BUFFER 0xCCCB +#define SL_OPCODE_FREE_NON_BSD_READ_BUFFER 0xCCCD + + +/* Rx Filters opcodes */ +#define SL_OPCODE_WLAN_WLANRXFILTERADDCOMMAND 0x8C6C +#define SL_OPCODE_WLAN_WLANRXFILTERADDRESPONSE 0x0C6C +#define SL_OPCODE_WLAN_WLANRXFILTERSETCOMMAND 0x8C6D +#define SL_OPCODE_WLAN_WLANRXFILTERSETRESPONSE 0x0C6D +#define SL_OPCODE_WLAN_WLANRXFILTERGETSTATISTICSINFOCOMMAND 0x8C6E +#define SL_OPCODE_WLAN_WLANRXFILTERGETSTATISTICSINFORESPONSE 0x0C6E +#define SL_OPCODE_WLAN_WLANRXFILTERGETCOMMAND 0x8C6F +#define SL_OPCODE_WLAN_WLANRXFILTERGETRESPONSE 0x0C6F +#define SL_OPCODE_WLAN_WLANRXFILTERGETINFO 0x8C70 +#define SL_OPCODE_WLAN_WLANRXFILTERGETINFORESPONSE 0x0C70 + + +/******************************************************************************************/ +/* Device structs */ +/******************************************************************************************/ +typedef _u32 InitStatus_t; + + +typedef struct +{ + _i32 Status; +}InitComplete_t; + +typedef struct +{ + _i16 status; + _u16 padding; + +}_BasicResponse_t; + +typedef struct +{ + _u16 Timeout; + _u16 padding; +}_DevStopCommand_t; + +typedef struct +{ + _u32 group; + _u32 mask; +}_DevMaskEventSetCommand_t; + +typedef _BasicResponse_t _DevMaskEventSetResponse_t; + + +typedef struct +{ + _u32 group; +}_DevMaskEventGetCommand_t; + + +typedef struct +{ + _u32 group; + _u32 mask; +}_DevMaskEventGetResponse_t; + + +typedef struct +{ + _u32 group; +}_DevStatusGetCommand_t; + + +typedef struct +{ + _u32 group; + _u32 status; +}_DevStatusGetResponse_t; + +typedef struct +{ + _u32 ChipId; + _u32 FwVersion[4]; + _u8 PhyVersion[4]; +}_Device_VersionReadResponsePart_t; + +typedef struct +{ + _Device_VersionReadResponsePart_t part; + _u32 NwpVersion[4]; + _u16 RomVersion; + _u16 Padding; +}_Device_VersionReadResponseFull_t; + + +typedef struct +{ + _u32 BaudRate; + _u8 FlowControlEnable; +}_DevUartSetModeCommand_t; + +typedef _BasicResponse_t _DevUartSetModeResponse_t; + +/******************************************************/ + +typedef struct +{ + _u8 SsiSizeInBytes; + _u8 Padding[3]; +}_StellarisSsiSizeSet_t; + +/*****************************************************************************************/ +/* WLAN structs */ +/*****************************************************************************************/ +#define MAXIMAL_PASSWORD_LENGTH (64) + +typedef struct{ + _u8 SecType; + _u8 SsidLen; + _u8 Bssid[6]; + _u8 PasswordLen; +}_WlanConnectCommon_t; + +#define SSID_STRING(pCmd) (_i8 *)((_WlanConnectCommon_t *)(pCmd) + 1) +#define PASSWORD_STRING(pCmd) (SSID_STRING(pCmd) + ((_WlanConnectCommon_t *)(pCmd))->SsidLen) + +typedef struct{ + _WlanConnectCommon_t Common; + _u8 UserLen; + _u8 AnonUserLen; + _u8 CertIndex; + _u32 EapBitmask; +}_WlanConnectEapCommand_t; + +#define EAP_SSID_STRING(pCmd) (_i8 *)((_WlanConnectEapCommand_t *)(pCmd) + 1) +#define EAP_PASSWORD_STRING(pCmd) (EAP_SSID_STRING(pCmd) + ((_WlanConnectEapCommand_t *)(pCmd))->Common.SsidLen) +#define EAP_USER_STRING(pCmd) (EAP_PASSWORD_STRING(pCmd) + ((_WlanConnectEapCommand_t *)(pCmd))->Common.PasswordLen) +#define EAP_ANON_USER_STRING(pCmd) (EAP_USER_STRING(pCmd) + ((_WlanConnectEapCommand_t *)(pCmd))->UserLen) + + +typedef struct +{ + _u8 PolicyType; + _u8 Padding; + _u8 PolicyOption; + _u8 PolicyOptionLen; +}_WlanPoliciySetGet_t; + + +typedef struct{ + _u32 minDwellTime; + _u32 maxDwellTime; + _u32 numProbeResponse; + _u32 G_Channels_mask; + _i32 rssiThershold; + _i32 snrThershold; + _i32 defaultTXPower; + _u16 intervalList[16]; +}_WlanScanParamSetCommand_t; + + +typedef struct{ + _i8 SecType; + _u8 SsidLen; + _u8 Priority; + _u8 Bssid[6]; + _u8 PasswordLen; + _u8 WepKeyId; +}_WlanAddGetProfile_t; + + +typedef struct{ + _WlanAddGetProfile_t Common; + _u8 UserLen; + _u8 AnonUserLen; + _u8 CertIndex; + _u16 padding; + _u32 EapBitmask; +}_WlanAddGetEapProfile_t; + + + + +#define PROFILE_SSID_STRING(pCmd) ((_i8 *)((_WlanAddGetProfile_t *)(pCmd) + 1)) +#define PROFILE_PASSWORD_STRING(pCmd) (PROFILE_SSID_STRING(pCmd) + ((_WlanAddGetProfile_t *)(pCmd))->SsidLen) + +#define EAP_PROFILE_SSID_STRING(pCmd) (_i8 *)((_WlanAddGetEapProfile_t *)(pCmd) + 1) +#define EAP_PROFILE_PASSWORD_STRING(pCmd) (EAP_PROFILE_SSID_STRING(pCmd) + ((_WlanAddGetEapProfile_t *)(pCmd))->Common.SsidLen) +#define EAP_PROFILE_USER_STRING(pCmd) (EAP_PROFILE_PASSWORD_STRING(pCmd) + ((_WlanAddGetEapProfile_t *)(pCmd))->Common.PasswordLen) +#define EAP_PROFILE_ANON_USER_STRING(pCmd) (EAP_PROFILE_USER_STRING(pCmd) + ((_WlanAddGetEapProfile_t *)(pCmd))->UserLen) + + + +typedef struct +{ + _u8 index; + _u8 padding[3]; +}_WlanProfileDelGetCommand_t; + +typedef _BasicResponse_t _WlanGetNetworkListResponse_t; + +typedef struct +{ + _u8 index; + _u8 count; + _i8 padding[2]; +}_WlanGetNetworkListCommand_t; + + + + +typedef struct +{ + _u32 groupIdBitmask; + _u8 cipher; + _u8 publicKeyLen; + _u8 group1KeyLen; + _u8 group2KeyLen; +}_WlanSmartConfigStartCommand_t; + +#define SMART_CONFIG_START_PUBLIC_KEY_STRING(pCmd) ((_i8 *)((_WlanSmartConfigStartCommand_t *)(pCmd) + 1)) +#define SMART_CONFIG_START_GROUP1_KEY_STRING(pCmd) ((_i8 *) (SMART_CONFIG_START_PUBLIC_KEY_STRING(pCmd) + ((_WlanSmartConfigStartCommand_t *)(pCmd))->publicKeyLen)) +#define SMART_CONFIG_START_GROUP2_KEY_STRING(pCmd) ((_i8 *) (SMART_CONFIG_START_GROUP1_KEY_STRING(pCmd) + ((_WlanSmartConfigStartCommand_t *)(pCmd))->group1KeyLen)) + + + +typedef struct +{ + _u8 mode; + _u8 padding[3]; +}_WlanSetMode_t; + + + + +typedef struct +{ + _u16 Status; + _u16 ConfigId; + _u16 ConfigOpt; + _u16 ConfigLen; +}_WlanCfgSetGet_t; + + +/* ******************************************************************************/ +/* RX filters - Start */ +/* ******************************************************************************/ +/* -- 80 bytes */ +typedef struct _WlanRxFilterAddCommand_t +{ + /* -- 1 byte */ + SlrxFilterRuleType_t RuleType; + /* -- 1 byte */ + SlrxFilterFlags_t FilterFlags; + /* -- 1 byte */ + SlrxFilterID_t FilterId; + /* -- 1 byte */ + _u8 Padding; + /* -- 56 byte */ + SlrxFilterRule_t Rule; + /* -- 12 byte ( 3 padding ) */ + SlrxFilterTrigger_t Trigger; + /* -- 8 byte */ + SlrxFilterAction_t Action; +}_WlanRxFilterAddCommand_t; + + + +/* -- 4 bytes */ +typedef struct l_WlanRxFilterAddCommandReponse_t +{ + /* -- 1 byte */ + SlrxFilterID_t FilterId; + /* -- 1 Byte */ + _u8 Status; + /* -- 2 byte */ + _u8 Padding[2]; + +}_WlanRxFilterAddCommandReponse_t; + + + +/* + * \struct _WlanRxFilterSetCommand_t + */ +typedef struct _WlanRxFilterSetCommand_t +{ + _u16 InputBufferLength; + /* 1 byte */ + SLrxFilterOperation_t RxFilterOperation; + _u8 Padding[1]; +}_WlanRxFilterSetCommand_t; + +/** + * \struct _WlanRxFilterSetCommandReponse_t + */ +typedef struct _WlanRxFilterSetCommandReponse_t +{ + /* 1 byte */ + _u8 Status; + /* 3 bytes */ + _u8 Padding[3]; + +}_WlanRxFilterSetCommandReponse_t; + +/** + * \struct _WlanRxFilterGetCommand_t + */ +typedef struct _WlanRxFilterGetCommand_t +{ + _u16 OutputBufferLength; + /* 1 byte */ + SLrxFilterOperation_t RxFilterOperation; + _u8 Padding[1]; +}_WlanRxFilterGetCommand_t; + +/** + * \struct _WlanRxFilterGetCommandReponse_t + */ +typedef struct _WlanRxFilterGetCommandReponse_t +{ + /* 1 byte */ + _u8 Status; + /* 1 bytes */ + _u8 Padding; + /* 2 byte */ + _u16 OutputBufferLength; + +}_WlanRxFilterGetCommandReponse_t; + + + +/* ******************************************************************************/ +/* RX filters -- End */ +/* ******************************************************************************/ + +typedef struct +{ + _u16 status; + _u8 WlanRole; /* 0 = station, 2 = AP */ + _u8 Ipv6Enabled; + _u8 Ipv6DhcpEnabled; + + _u32 ipV6Global[4]; + _u32 ipV6Local[4]; + _u32 ipV6DnsServer[4]; + _u8 Ipv6DhcpState; + +}_NetappIpV6configRetArgs_t; + + +typedef struct +{ + _u8 ipV4[4]; + _u8 ipV4Mask[4]; + _u8 ipV4Gateway[4]; + _u8 ipV4DnsServer[4]; + _u8 ipV4Start[4]; + _u8 ipV4End[4]; +}_NetCfgIpV4AP_Args_t; + + + +typedef struct +{ + _u16 status; + _u8 MacAddr[6]; +} _MAC_Address_SetGet_t; + + +typedef struct +{ + _u16 Status; + _u16 ConfigId; + _u16 ConfigOpt; + _u16 ConfigLen; +}_NetCfgSetGet_t; + +typedef struct +{ + _u16 Status; + _u16 DeviceSetId; + _u16 Option; + _u16 ConfigLen; +}_DeviceSetGet_t; + + + + +/******************************************************************************************/ +/* Socket structs */ +/******************************************************************************************/ + +typedef struct +{ + _u8 Domain; + _u8 Type; + _u8 Protocol; + _u8 Padding; +}_SocketCommand_t; + + +typedef struct +{ + _i16 statusOrLen; + _u8 sd; + _u8 padding; +}_SocketResponse_t; + +typedef struct +{ + _u8 sd; + _u8 family; + _u8 padding1; + _u8 padding2; +}_AcceptCommand_t; + + +typedef struct +{ + _i16 statusOrLen; + _u8 sd; + _u8 family; + _u16 port; + _u16 paddingOrAddr; + _u32 address; +}_SocketAddrAsyncIPv4Response_t; + +typedef struct +{ + _i16 statusOrLen; + _u8 sd; + _u8 family; + _u16 port; + _u8 address[6]; +}_SocketAddrAsyncIPv6EUI48Response_t; +typedef struct +{ + _i16 statusOrLen; + _u8 sd; + _u8 family; + _u16 port; + _u16 paddingOrAddr; + _u32 address[4]; +}_SocketAddrAsyncIPv6Response_t; + + +typedef struct +{ + _i16 lenOrPadding; + _u8 sd; + _u8 FamilyAndFlags; + _u16 port; + _u16 paddingOrAddr; + _u32 address; +}_SocketAddrIPv4Command_t; + +typedef struct +{ + _i16 lenOrPadding; + _u8 sd; + _u8 FamilyAndFlags; + _u16 port; + _u8 address[6]; +}_SocketAddrIPv6EUI48Command_t; +typedef struct +{ + _i16 lenOrPadding; + _u8 sd; + _u8 FamilyAndFlags; + _u16 port; + _u16 paddingOrAddr; + _u32 address[4]; +}_SocketAddrIPv6Command_t; + +typedef union { + _SocketAddrIPv4Command_t IpV4; + _SocketAddrIPv6EUI48Command_t IpV6EUI48; +#ifdef SL_SUPPORT_IPV6 + _SocketAddrIPv6Command_t IpV6; +#endif +} _SocketAddrCommand_u; + +typedef union { + _SocketAddrAsyncIPv4Response_t IpV4; + _SocketAddrAsyncIPv6EUI48Response_t IpV6EUI48; +#ifdef SL_SUPPORT_IPV6 + _SocketAddrAsyncIPv6Response_t IpV6; +#endif +} _SocketAddrResponse_u; + +typedef struct +{ + _u8 sd; + _u8 backlog; + _u8 padding1; + _u8 padding2; +}_ListenCommand_t; + +typedef struct +{ + _u8 sd; + _u8 padding0; + _u8 padding1; + _u8 padding2; +}_CloseCommand_t; + + +typedef struct +{ + _u8 nfds; + _u8 readFdsCount; + _u8 writeFdsCount; + _u8 padding; + _u16 readFds; + _u16 writeFds; + _u16 tv_usec; + _u16 tv_sec; +}_SelectCommand_t; + + +typedef struct +{ + _u16 status; + _u8 readFdsCount; + _u8 writeFdsCount; + _u16 readFds; + _u16 writeFds; +}_SelectAsyncResponse_t; + +typedef struct +{ + _u8 sd; + _u8 level; + _u8 optionName; + _u8 optionLen; +}_setSockOptCommand_t; + +typedef struct +{ + _u8 sd; + _u8 level; + _u8 optionName; + _u8 optionLen; +}_getSockOptCommand_t; + +typedef struct +{ + _i16 status; + _u8 sd; + _u8 optionLen; +}_getSockOptResponse_t; + + +typedef struct +{ + _u16 StatusOrLen; + _u8 sd; + _u8 FamilyAndFlags; +}_sendRecvCommand_t; + +/***************************************************************************************** +* NETAPP structs +******************************************************************************************/ + + +typedef _BasicResponse_t _NetAppStartStopResponse_t; + +typedef struct +{ + _u32 appId; +}_NetAppStartStopCommand_t; + +typedef struct +{ + _u16 Status; + _u16 AppId; + _u16 ConfigOpt; + _u16 ConfigLen; +}_NetAppSetGet_t; +typedef struct +{ + _u16 port_number; +} _NetAppHttpServerGetSet_port_num_t; + +typedef struct +{ + _u8 auth_enable; +}_NetAppHttpServerGetSet_auth_enable_t; + +typedef struct _sl_NetAppHttpServerGetToken_t +{ + _u8 token_name_len; + _u8 padd1; + _u16 padd2; +}sl_NetAppHttpServerGetToken_t; + +typedef struct _sl_NetAppHttpServerSendToken_t +{ + _u8 token_value_len; + _u8 token_name_len; + _u8 token_name[MAX_TOKEN_NAME_LEN]; + _u16 padd; +}sl_NetAppHttpServerSendToken_t; + +typedef struct _sl_NetAppHttpServerPostToken_t +{ + _u8 post_action_len; + _u8 token_name_len; + _u8 token_value_len; + _u8 padding; +}sl_NetAppHttpServerPostToken_t; + + +typedef struct +{ + _u16 Len; + _u8 family; + _u8 padding; +}_GetHostByNameCommand_t; + +typedef struct +{ + _u16 status; + _u16 padding; + _u32 ip0; + _u32 ip1; + _u32 ip2; + _u32 ip3; +}_GetHostByNameIPv6AsyncResponse_t; + +typedef struct +{ + _u16 status; + _u8 padding1; + _u8 padding2; + _u32 ip0; +}_GetHostByNameIPv4AsyncResponse_t; + + + + +typedef enum +{ + CTST_BSD_UDP_TX, + CTST_BSD_UDP_RX, + CTST_BSD_TCP_TX, + CTST_BSD_TCP_RX, + CTST_BSD_TCP_SERVER_BI_DIR, + CTST_BSD_TCP_CLIENT_BI_DIR, + CTST_BSD_UDP_BI_DIR, + CTST_BSD_RAW_TX, + CTST_BSD_RAW_RX, + CTST_BSD_RAW_BI_DIR, + CTST_BSD_SECURED_TCP_TX, + CTST_BSD_SECURED_TCP_RX, + CTST_BSD_SECURED_TCP_SERVER_BI_DIR, + CTST_BSD_SECURED_TCP_CLIENT_BI_DIR + }CommTest_e; + +typedef struct _sl_protocol_CtestStartCommand_t +{ + _u32 Test; + _u16 DestPort; + _u16 SrcPort; + _u32 DestAddr[4]; + _u32 PayloadSize; + _u32 timeout; + _u32 csEnabled; + _u32 secure; + _u32 rawProtocol; + _u8 reserved1[4]; +}_CtestStartCommand_t; + +typedef struct +{ + _u8 test; + _u8 socket; + _i16 status; + _u32 startTime; + _u32 endTime; + _u16 txKbitsSec; + _u16 rxKbitsSec; + _u32 outOfOrderPackets; + _u32 missedPackets; +}_CtestAsyncResponse_t; + +typedef struct +{ + _u32 pingIntervalTime; + _u16 PingSize; + _u16 pingRequestTimeout; + _u32 totalNumberOfAttempts; + _u32 flags; + _u32 ip0; + _u32 ip1OrPaadding; + _u32 ip2OrPaadding; + _u32 ip3OrPaadding; +}_PingStartCommand_t; + +typedef struct +{ + _u16 status; + _u16 rttMin; + _u16 rttMax; + _u16 rttAvg; + _u32 numSuccsessPings; + _u32 numSendsPings; + _u32 testTime; +}_PingReportResponse_t; + + +typedef struct +{ + _u32 ip; + _u32 gateway; + _u32 dns; +}_IpV4AcquiredAsync_t; + + +typedef enum +{ + ACQUIRED_IPV6_LOCAL = 1, + ACQUIRED_IPV6_GLOBAL +}IpV6AcquiredType_e; + + +typedef struct +{ + _u32 type; + _u32 ip[4]; + _u32 gateway[4]; + _u32 dns[4]; +}_IpV6AcquiredAsync_t; + + +typedef union +{ + _SocketCommand_t EventMask; + _sendRecvCommand_t DeviceInit; +}_device_commands_t; + +/***************************************************************************************** +* FS structs +******************************************************************************************/ + +typedef struct +{ + _u32 FileHandle; + _u32 Offset; + _u16 Len; + _u16 Padding; +}_FsReadCommand_t; + +typedef struct +{ + _u32 Mode; + _u32 Token; +}_FsOpenCommand_t; + +typedef struct +{ + _u32 FileHandle; + _u32 Token; +}_FsOpenResponse_t; + + +typedef struct +{ + _u32 FileHandle; + _u32 CertificFileNameLength; + _u32 SignatureLen; +}_FsCloseCommand_t; + + +typedef _BasicResponse_t _FsReadResponse_t; +typedef _BasicResponse_t _FsDeleteResponse_t; +typedef _BasicResponse_t _FsCloseResponse_t; + +typedef struct +{ + _u16 Status; + _u16 flags; + _u32 FileLen; + _u32 AllocatedLen; + _u32 Token[4]; +}_FsGetInfoResponse_t; + +typedef struct +{ + _u8 DeviceID; + _u8 Padding[3]; +}_FsFormatCommand_t; + +typedef _BasicResponse_t _FsFormatResponse_t; + +typedef struct +{ + _u32 Token; +}_FsDeleteCommand_t; + +typedef _FsDeleteCommand_t _FsGetInfoCommand_t; + +typedef struct +{ + _u32 FileHandle; + _u32 Offset; + _u16 Len; + _u16 Padding; +}_FsWriteCommand_t; + +typedef _BasicResponse_t _FsWriteResponse_t; + + + +/* Set Max Async Payload length depending on flavor (Tiny, Small, etc.) */ +#define SL_ASYNC_MAX_PAYLOAD_LEN 160 /* size must be aligned to 4 */ +#define SL_ASYNC_MAX_MSG_LEN (_SL_RESP_HDR_SIZE + SL_ASYNC_MAX_PAYLOAD_LEN) + +#define RECV_ARGS_SIZE (sizeof(_SocketResponse_t)) +#define RECVFROM_IPV4_ARGS_SIZE (sizeof(_SocketAddrAsyncIPv4Response_t)) +#define RECVFROM_IPV6_ARGS_SIZE (sizeof(_SocketAddrAsyncIPv6Response_t)) + +#define SL_IPV4_ADDRESS_SIZE (sizeof(_u32)) +#define SL_IPV6_ADDRESS_SIZE (4 * sizeof(_u32)) + +#endif /* _SL_PROTOCOL_TYPES_H_ */ diff --git a/drivers/cc3100/inc/simplelink.h b/drivers/cc3100/inc/simplelink.h new file mode 100644 index 0000000000..412d6242cb --- /dev/null +++ b/drivers/cc3100/inc/simplelink.h @@ -0,0 +1,592 @@ +/* + * simplelink.h - CC31xx/CC32xx Host Driver Implementation + * + * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +*/ + + +/*! + \mainpage SimpleLink Driver + + \section intro_sec Introduction + + The SimpleLink CC31xx/CC2xx family allows to add Wi-Fi and networking capabilities + to low-cost embedded products without having prior Wi-Fi, RF or networking expertise. + The CC31xx/CC32xx is an ideal solution for microcontroller-based sensor and control + applications such as home appliances, home automation and smart metering. + The CC31xx/CC32xx has integrated a comprehensive TCP/IP network stack, Wi-Fi driver and + security supplicant leading to easier portability to microcontrollers, to an + ultra-low memory footprint, all without compromising the capabilities and robustness + of the final application. + + + + \section modules_sec Module Names + To make it simple, TI's SimpleLink CC31xx/CC32xx platform capabilities were divided into modules by topic (Silo). + These capabilities range from basic device management through wireless + network configuration, standard BSD socket and much more. + Listed below are the various modules in the SimpleLink CC31xx/CC32xx driver: + -# \ref device - controls the behaviour of the CC31xx/CC32xx device (start/stop, events masking and obtaining specific device status) + -# \ref wlan - controls the use of the WiFi WLAN module including: + - Connection features, such as: profiles, policies, SmartConfig™ + - Advanced WLAN features, such as: scans, rx filters and rx statistics collection + -# \ref socket - controls standard client/server sockets programming options and capabilities + -# \ref netapp - activates networking applications, such as: HTTP Server, DHCP Server, Ping, DNS and mDNS. + -# \ref netcfg - controls the configuration of the device addresses (i.e. IP and MAC addresses) + -# \ref FileSystem - provides file system capabilities to TI's CC31XX that can be used by both the CC31XX device and the user. + + + \section proting_sec Porting Guide + + The porting of the SimpleLink driver to any new platform is based on few simple steps. + This guide takes you through this process step by step. Please follow the instructions + carefully to avoid any problems during this process and to enable efficient and proper + work with the device. + Please notice that all modifications and porting adjustments of the driver should be + made in the user.h header file only. + Keep making any of the changes only in this file will ensure smoothly transaction to + new versions of the driver at the future! + + + \subsection porting_step1 Step 1 - Create your own user.h file + + The first step is to create a user.h file that will include your configurations and + adjustments. You can use the empty template provided as part of this driver or + you can choose to base your file on file from one of the wide range of examples + applications provided by Texas Instruments + + + \subsection porting_step2 Step 2 - Select the capabilities set required for your application + + Texas Instruments made a lot of efforts to build set of predefined capability sets that would + fit most of the target application. + It is recommended to try and choose one of this predefined capabilities set before going to + build your own customized set. If you find compatible set you can skip the rest of this step. + + The available sets are: + -# SL_TINY - Compatible to be used on platforms with very limited resources. Provides + the best in class foot print in terms of Code and Data consumption. + -# SL_SMALL - Compatible to most common networking applications. Provide the most + common APIs with decent balance between code size, data size, functionality + and performances + -# SL_FULL - Provide access to all SimpleLink functionalities + + + \subsection porting_step3 Step 3 - Bind the device enable/disable output line + + The enable/disable line (nHib) provide mechanism to enter the device into the least current + consumption mode. This mode could be used when no traffic is required (tx/rx). + when this line is not connected to any IO of the host this define should be left empty. + Not connecting this line results in ability to start the driver only once. + + + \subsection porting_step4 Step 4 - Writing your interface communication driver + + The SimpleLink device support several standard communication protocol among SPI and + UART. Depending on your needs and your hardware design, you should choose the + communication channel type. + The interface for this communication channel should include 4 simple access functions: + -# open + -# close + -# read + -# write + + The way this driver would be implemented is directly effecting the efficiency and + the performances of the SimpleLink device on this platform. + If your system has DMA you should consider to use it in order to increase the utilization + of the communication channel + If you have enough memory resources you should consider using a buffer to increase the + efficiency of the write operations. + + + \subsection porting_step5 Step 5 - Choose your memory management model + + The SimpleLink driver support two memory models: + -# Static (default) + -# Dynamic + + If you choose to work in dynamic model you will have to provide alloc and free functions + to be used by the Simple Link driver otherwise nothing need to be done. + + + \subsection porting_step6 Step 6 - OS adaptation + + The SimpleLink driver could run on two kind of platforms: + -# Non-Os / Single Threaded (default) + -# Multi-Threaded + + If you choose to work in multi-threaded environment under operating system you will have to + provide some basic adaptation routines to allow the driver to protect access to resources + for different threads (locking object) and to allow synchronization between threads (sync objects). + In additional the driver support running without dedicated thread allocated solely to the simple + link driver. If you choose to work in this mode, you should also supply a spawn method that + will enable to run function on a temporary context. + + + \subsection porting_step7 Step 7 - Set your asynchronous event handlers routines + + The SimpleLink device generate asynchronous events in several situations. + These asynchronous events could be masked. + In order to catch these events you have to provide handler routines. + Please notice that if you not provide a handler routine and the event is received, + the driver will drop this event without any indication of this drop. + + + \subsection porting_step8 Step 8 - Run diagnostic tools to validate the correctness of your porting + + The driver is delivered with some porting diagnostic tools to simplify the porting validation process + and to reduce issues latter. It is very important to follow carefully this process. + + The diagnostic process include: + -# Validating Interface Communication Driver + -# Validating OS adaptation layer + -# Validating HW integrity + -# Validating basic work with the device + + + \section sw_license License + + * + * + * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +*/ + + + +#ifndef __SIMPLELINK_H__ +#define __SIMPLELINK_H__ + +#include "user.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + + +/*! \attention Async event activation notes + Function prototypes for event callback handlers + Event handler function names should be defined in the user.h file + e.g. + "#define sl_WlanEvtHdlr SLWlanEventHandler" + Indicates all WLAN events are handled by User func "SLWlanEventHandler" + Important notes: + 1. Event handlers cannot activate another SimpleLink API from the event's context + 2. Event's data is valid during event's context. Any application data + which is required for the user application should be copied or marked + into user's variables + 3. It is not recommended to delay the execution of the event callback handler + +*/ + +/*! + + \addtogroup UserEvents + @{ + +*/ + + +/*****************************************************************************/ +/* Macro declarations for Host Driver version */ +/*****************************************************************************/ +#define SL_DRIVER_VERSION "1.0.0.1" +#define SL_MAJOR_VERSION_NUM 1L +#define SL_MINOR_VERSION_NUM 0L +#define SL_VERSION_NUM 0L +#define SL_SUB_VERSION_NUM 1L + + +/*****************************************************************************/ +/* Macro declarations for predefined configurations */ +/*****************************************************************************/ + +#ifdef SL_TINY +#undef SL_INC_ARG_CHECK +#undef SL_INC_EXT_API +#undef SL_INC_SOCK_CLIENT_SIDE_API +#undef SL_INC_SOCK_SEND_API +#undef SL_INC_WLAN_PKG +#undef SL_INC_NET_APP_PKG +#undef SL_INC_NET_CFG_PKG +#undef SL_INC_FS_PKG +#define SL_INC_SOCK_SERVER_SIDE_API +#define SL_INC_SOCK_RECV_API +#define SL_INC_SOCKET_PKG +#endif + +#ifdef SL_SMALL +#undef SL_INC_EXT_API +#undef SL_INC_NET_APP_PKG +#undef SL_INC_NET_CFG_PKG +#undef SL_INC_FS_PKG +#define SL_INC_ARG_CHECK +#define SL_INC_WLAN_PKG +#define SL_INC_SOCKET_PKG +#define SL_INC_SOCK_CLIENT_SIDE_API +#define SL_INC_SOCK_SERVER_SIDE_API +#define SL_INC_SOCK_RECV_API +#define SL_INC_SOCK_SEND_API +#endif + +#ifdef SL_FULL +#define SL_INC_EXT_API +#define SL_INC_NET_APP_PKG +#define SL_INC_NET_CFG_PKG +#define SL_INC_FS_PKG +#define SL_INC_ARG_CHECK +#define SL_INC_WLAN_PKG +#define SL_INC_SOCKET_PKG +#define SL_INC_SOCK_CLIENT_SIDE_API +#define SL_INC_SOCK_SERVER_SIDE_API +#define SL_INC_SOCK_RECV_API +#define SL_INC_SOCK_SEND_API +#endif + +#define SL_RET_CODE_OK (0) +#define SL_RET_CODE_INVALID_INPUT (-2) +#define SL_RET_CODE_SELF_ERROR (-3) +#define SL_RET_CODE_NWP_IF_ERROR (-4) +#define SL_RET_CODE_MALLOC_ERROR (-5) + +#define sl_Memcpy memcpy +#define sl_Memset memset + +#define sl_SyncObjClear(pObj) sl_SyncObjWait(pObj,SL_OS_NO_WAIT) + +#define SL_MAX_SOCKETS (8) + + +/*****************************************************************************/ +/* Types definitions */ +/*****************************************************************************/ +typedef void (*_SlSpawnEntryFunc_t)(void* pValue); + +#ifndef NULL +#define NULL (0) +#endif + +#ifndef FALSE +#define FALSE (0) +#endif + +#ifndef TRUE +#define TRUE (!FALSE) +#endif + +#ifndef OK +#define OK (0) +#endif + +#ifndef _SL_USER_TYPES + #define _u8 unsigned char + #define _i8 signed char + + #define _u16 unsigned short + #define _i16 signed short + + #define _u32 unsigned long + #define _i32 signed long + #define _volatile volatile + #define _const const +#endif + +typedef _u16 _SlOpcode_t; +typedef _u8 _SlArgSize_t; +typedef _i16 _SlDataSize_t; +typedef _i16 _SlReturnVal_t; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + + +/*****************************************************************************/ +/* Include files */ +/*****************************************************************************/ + +#ifdef SL_PLATFORM_MULTI_THREADED + #include "../source/spawn.h" +#else + #include "../source/nonos.h" +#endif + + +/* + objInclusion.h and user.h must be included before all api header files + objInclusion.h must be the last arrangement just before including the API header files + since it based on the other configurations to decide which object should be included +*/ +#include "../source/objInclusion.h" +#include "trace.h" +#include "fs.h" +#include "socket.h" +#include "netapp.h" +#include "wlan.h" +#include "device.h" +#include "netcfg.h" +#include "wlan_rx_filters.h" + + + +/* Async functions description*/ + +/*! + \brief General async event for inspecting general events + + \param[out] pSlDeviceEvent pointer to SlDeviceEvent_t + + \par + Parameters: \n + <b>pSlDeviceEvent->Event = SL_DEVICE_FATAL_ERROR_EVENT </b> + - pSlDeviceEvent->EventData.deviceEvent fields: + - status: An error code indication from the device + - sender: The sender originator which is based on SlErrorSender_e enum + + \par Example: + \code + printf(General Event Handler - ID=%d Sender=%d\n\n", + pSlDeviceEvent->EventData.deviceEvent.status, // status of the general event + pSlDeviceEvent->EventData.deviceEvent.sender); // sender type + \endcode +*/ +#if (defined(sl_GeneralEvtHdlr)) +extern void sl_GeneralEvtHdlr(SlDeviceEvent_t *pSlDeviceEvent); +#endif + + +/*! + \brief WLAN Async event handler + + \param[out] pSlWlanEvent pointer to SlWlanEvent_t data + + \par + Parameters: + + - <b>pSlWlanEvent->Event = SL_WLAN_CONNECT_EVENT </b>, STA or P2P client connection indication event + - pSlWlanEvent->EventData.STAandP2PModeWlanConnected main fields: + - ssid_name + - ssid_len + - bssid + - go_peer_device_name + - go_peer_device_name_len + + - <b>pSlWlanEvent->Event = SL_WLAN_DISCONNECT_EVENT </b>, STA or P2P client disconnection event + - pSlWlanEvent->EventData.STAandP2PModeDisconnected main fields: + - ssid_name + - ssid_len + - reason_code + + - <b>pSlWlanEvent->Event = SL_WLAN_STA_CONNECTED_EVENT </b>, AP/P2P(Go) connected STA/P2P(Client) + - pSlWlanEvent->EventData.APModeStaConnected fields: + - go_peer_device_name + - mac + - go_peer_device_name_len + - wps_dev_password_id + - own_ssid: relevant for event sta-connected only + - own_ssid_len: relevant for event sta-connected only + + - <b>pSlWlanEvent->Event = SL_WLAN_STA_DISCONNECTED_EVENT </b>, AP/P2P(Go) disconnected STA/P2P(Client) + - pSlWlanEvent->EventData.APModestaDisconnected fields: + - go_peer_device_name + - mac + - go_peer_device_name_len + - wps_dev_password_id + - own_ssid: relevant for event sta-connected only + - own_ssid_len: relevant for event sta-connected only + + - <b>pSlWlanEvent->Event = SL_WLAN_SMART_CONFIG_COMPLETE_EVENT </b> + - pSlWlanEvent->EventData.smartConfigStartResponse fields: + - status + - ssid_len + - ssid + - private_token_len + - private_token + + - <b>pSlWlanEvent->Event = SL_WLAN_SMART_CONFIG_STOP_EVENT </b> + - pSlWlanEvent->EventData.smartConfigStopResponse fields: + - status + + - <b>pSlWlanEvent->Event = SL_WLAN_P2P_DEV_FOUND_EVENT </b> + - pSlWlanEvent->EventData.P2PModeDevFound fields: + - go_peer_device_name + - mac + - go_peer_device_name_len + - wps_dev_password_id + - own_ssid: relevant for event sta-connected only + - own_ssid_len: relevant for event sta-connected only + + - <b>pSlWlanEvent->Event = SL_WLAN_P2P_NEG_REQ_RECEIVED_EVENT </b> + - pSlWlanEvent->EventData.P2PModeNegReqReceived fields + - go_peer_device_name + - mac + - go_peer_device_name_len + - wps_dev_password_id + - own_ssid: relevant for event sta-connected only + + - <b>pSlWlanEvent->Event = SL_WLAN_CONNECTION_FAILED_EVENT </b>, P2P only + - pSlWlanEvent->EventData.P2PModewlanConnectionFailure fields: + - status +*/ +#if (defined(sl_WlanEvtHdlr)) +extern void sl_WlanEvtHdlr(SlWlanEvent_t *pSlWlanEvent); +#endif + + +/*! + \brief NETAPP Async event handler + + \param[out] pSlNetApp pointer to SlNetAppEvent_t data + + \par + Parameters: + - <b>pSlWlanEvent->Event = SL_NETAPP_IPV4_IPACQUIRED_EVENT</b>, IPV4 acquired event + - pSlWlanEvent->EventData.ipAcquiredV4 fields: + - ip + - gateway + - dns + + - <b>pSlWlanEvent->Event = SL_NETAPP_IP_LEASED_EVENT</b>, AP or P2P go dhcp lease event + - pSlWlanEvent->EventData.ipLeased fields: + - ip_address + - lease_time + - mac + + - <b>pSlWlanEvent->Event = SL_NETAPP_IP_RELEASED_EVENT</b>, AP or P2P go dhcp ip release event + - pSlWlanEvent->EventData.ipReleased fields + - ip_address + - mac + - reason + +*/ +#if (defined(sl_NetAppEvtHdlr)) +extern void sl_NetAppEvtHdlr(SlNetAppEvent_t *pSlNetApp); +#endif + +/*! + \brief Socket Async event handler + + \param[out] pSlSockEvent pointer to SlSockEvent_t data + + \par + Parameters:\n + - <b>pSlSockEvent->Event = SL_SOCKET_TX_FAILED_EVENT</b> + - pSlSockEvent->EventData fields: + - sd + - status + - <b>pSlSockEvent->Event = SL_SOCKET_ASYNC_EVENT</b> + - pSlSockEvent->EventData fields: + - sd + - type: SSL_ACCEPT or RX_FRAGMENTATION_TOO_BIG or OTHER_SIDE_CLOSE_SSL_DATA_NOT_ENCRYPTED + - val + +*/ +#if (defined(sl_SockEvtHdlr)) +extern void sl_SockEvtHdlr(SlSockEvent_t *pSlSockEvent); +#endif + +/*! + \brief HTTP server async event + + \param[out] pSlHttpServerEvent pointer to SlHttpServerEvent_t + \param[in] pSlHttpServerResponse pointer to SlHttpServerResponse_t + + \par + Parameters: \n + + - <b>pSlHttpServerEvent->Event = SL_NETAPP_HTTPGETTOKENVALUE_EVENT</b> + - pSlHttpServerEvent->EventData fields: + - httpTokenName + - data + - len + - pSlHttpServerResponse->ResponseData fields: + - data + - len + + - <b>pSlHttpServerEvent->Event = SL_NETAPP_HTTPPOSTTOKENVALUE_EVENT</b> + - pSlHttpServerEvent->EventData.httpPostData fields: + - action + - token_name + - token_value + - pSlHttpServerResponse->ResponseData fields: + - data + - len + +*/ +#if (defined(sl_HttpServerCallback)) +extern void sl_HttpServerCallback(SlHttpServerEvent_t *pSlHttpServerEvent, SlHttpServerResponse_t *pSlHttpServerResponse); +#endif +/*! + + Close the Doxygen group. + @} + + */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __SIMPLELINK_H__ */ + diff --git a/drivers/cc3100/inc/socket.h b/drivers/cc3100/inc/socket.h new file mode 100644 index 0000000000..9293be4d4b --- /dev/null +++ b/drivers/cc3100/inc/socket.h @@ -0,0 +1,1498 @@ +/* + * socket.h - CC31xx/CC32xx Host Driver Implementation + * + * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +*/ + +#ifndef __SL_SOCKET_H__ +#define __SL_SOCKET_H__ + +/*****************************************************************************/ +/* Include files */ +/*****************************************************************************/ +#include "simplelink.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +/*! + + \addtogroup socket + @{ + +*/ + +/*****************************************************************************/ +/* Macro declarations */ +/*****************************************************************************/ + +#define SL_FD_SETSIZE SL_MAX_SOCKETS /* Number of sockets to select on - same is max sockets! */ +#define BSD_SOCKET_ID_MASK (0x0F) /* Index using the LBS 4 bits for socket id 0-7 */ +/* Define some BSD protocol constants. */ +#define SL_SOCK_STREAM (1) /* TCP Socket */ +#define SL_SOCK_DGRAM (2) /* UDP Socket */ +#define SL_SOCK_RAW (3) /* Raw socket */ +#define SL_IPPROTO_TCP (6) /* TCP Raw Socket */ +#define SL_IPPROTO_UDP (17) /* UDP Raw Socket */ +#define SL_IPPROTO_RAW (255) /* Raw Socket */ +#define SL_SEC_SOCKET (100) /* Secured Socket Layer (SSL,TLS) */ + +/* Address families. */ +#define SL_AF_INET (2) /* IPv4 socket (UDP, TCP, etc) */ +#define SL_AF_INET6 (3) /* IPv6 socket (UDP, TCP, etc) */ +#define SL_AF_INET6_EUI_48 (9) +#define SL_AF_RF (6) /* data include RF parameter, All layer by user (Wifi could be disconnected) */ +#define SL_AF_PACKET (17) +/* Protocol families, same as address families. */ +#define SL_PF_INET AF_INET +#define SL_PF_INET6 AF_INET6 +#define SL_INADDR_ANY (0) /* bind any address */ + +/* error codes */ +#define SL_SOC_ERROR (-1) /* Failure. */ +#define SL_SOC_OK ( 0) /* Success. */ +#define SL_INEXE (-8) /* socket command in execution */ +#define SL_EBADF (-9) /* Bad file number */ +#define SL_ENSOCK (-10) /* The system limit on the total number of open socket, has been reached */ +#define SL_EAGAIN (-11) /* Try again */ +#define SL_EWOULDBLOCK SL_EAGAIN +#define SL_ENOMEM (-12) /* Out of memory */ +#define SL_EACCES (-13) /* Permission denied */ +#define SL_EFAULT (-14) /* Bad address */ +#define SL_ECLOSE (-15) /* close socket operation failed to transmit all queued packets */ +#define SL_EALREADY_ENABLED (-21) /* Transceiver - Transceiver already ON. there could be only one */ +#define SL_EINVAL (-22) /* Invalid argument */ +#define SL_EAUTO_CONNECT_OR_CONNECTING (-69) /* Transceiver - During connection, connected or auto mode started */ +#define SL_CONNECTION_PENDING (-72) /* Transceiver - Device is connected, disconnect first to open transceiver */ +#define SL_EUNSUPPORTED_ROLE (-86) /* Transceiver - Trying to start when WLAN role is AP or P2P GO */ +#define SL_EDESTADDRREQ (-89) /* Destination address required */ +#define SL_EPROTOTYPE (-91) /* Protocol wrong type for socket */ +#define SL_ENOPROTOOPT (-92) /* Protocol not available */ +#define SL_EPROTONOSUPPORT (-93) /* Protocol not supported */ +#define SL_ESOCKTNOSUPPORT (-94) /* Socket type not supported */ +#define SL_EOPNOTSUPP (-95) /* Operation not supported on transport endpoint */ +#define SL_EAFNOSUPPORT (-97) /* Address family not supported by protocol */ +#define SL_EADDRINUSE (-98) /* Address already in use */ +#define SL_EADDRNOTAVAIL (-99) /* Cannot assign requested address */ +#define SL_ENETUNREACH (-101) /* Network is unreachable */ +#define SL_ENOBUFS (-105) /* No buffer space available */ +#define SL_EOBUFF SL_ENOBUFS +#define SL_EISCONN (-106) /* Transport endpoint is already connected */ +#define SL_ENOTCONN (-107) /* Transport endpoint is not connected */ +#define SL_ETIMEDOUT (-110) /* Connection timed out */ +#define SL_ECONNREFUSED (-111) /* Connection refused */ +#define SL_EALREADY (-114) /* Non blocking connect in progress, try again */ + +#define SL_ESEC_RSA_WRONG_TYPE_E (-130) /* RSA wrong block type for RSA function */ +#define SL_ESEC_RSA_BUFFER_E (-131) /* RSA buffer error, output too small or */ +#define SL_ESEC_BUFFER_E (-132) /* output buffer too small or input too large */ +#define SL_ESEC_ALGO_ID_E (-133) /* setting algo id error */ +#define SL_ESEC_PUBLIC_KEY_E (-134) /* setting public key error */ +#define SL_ESEC_DATE_E (-135) /* setting date validity error */ +#define SL_ESEC_SUBJECT_E (-136) /* setting subject name error */ +#define SL_ESEC_ISSUER_E (-137) /* setting issuer name error */ +#define SL_ESEC_CA_TRUE_E (-138) /* setting CA basic constraint true error */ +#define SL_ESEC_EXTENSIONS_E (-139) /* setting extensions error */ +#define SL_ESEC_ASN_PARSE_E (-140) /* ASN parsing error, invalid input */ +#define SL_ESEC_ASN_VERSION_E (-141) /* ASN version error, invalid number */ +#define SL_ESEC_ASN_GETINT_E (-142) /* ASN get big _i16 error, invalid data */ +#define SL_ESEC_ASN_RSA_KEY_E (-143) /* ASN key init error, invalid input */ +#define SL_ESEC_ASN_OBJECT_ID_E (-144) /* ASN object id error, invalid id */ +#define SL_ESEC_ASN_TAG_NULL_E (-145) /* ASN tag error, not null */ +#define SL_ESEC_ASN_EXPECT_0_E (-146) /* ASN expect error, not zero */ +#define SL_ESEC_ASN_BITSTR_E (-147) /* ASN bit string error, wrong id */ +#define SL_ESEC_ASN_UNKNOWN_OID_E (-148) /* ASN oid error, unknown sum id */ +#define SL_ESEC_ASN_DATE_SZ_E (-149) /* ASN date error, bad size */ +#define SL_ESEC_ASN_BEFORE_DATE_E (-150) /* ASN date error, current date before */ +#define SL_ESEC_ASN_AFTER_DATE_E (-151) /* ASN date error, current date after */ +#define SL_ESEC_ASN_SIG_OID_E (-152) /* ASN signature error, mismatched oid */ +#define SL_ESEC_ASN_TIME_E (-153) /* ASN time error, unknown time type */ +#define SL_ESEC_ASN_INPUT_E (-154) /* ASN input error, not enough data */ +#define SL_ESEC_ASN_SIG_CONFIRM_E (-155) /* ASN sig error, confirm failure */ +#define SL_ESEC_ASN_SIG_HASH_E (-156) /* ASN sig error, unsupported hash type */ +#define SL_ESEC_ASN_SIG_KEY_E (-157) /* ASN sig error, unsupported key type */ +#define SL_ESEC_ASN_DH_KEY_E (-158) /* ASN key init error, invalid input */ +#define SL_ESEC_ASN_NTRU_KEY_E (-159) /* ASN ntru key decode error, invalid input */ +#define SL_ESEC_ECC_BAD_ARG_E (-170) /* ECC input argument of wrong type */ +#define SL_ESEC_ASN_ECC_KEY_E (-171) /* ASN ECC bad input */ +#define SL_ESEC_ECC_CURVE_OID_E (-172) /* Unsupported ECC OID curve type */ +#define SL_ESEC_BAD_FUNC_ARG (-173) /* Bad function argument provided */ +#define SL_ESEC_NOT_COMPILED_IN (-174) /* Feature not compiled in */ +#define SL_ESEC_UNICODE_SIZE_E (-175) /* Unicode password too big */ +#define SL_ESEC_NO_PASSWORD (-176) /* no password provided by user */ +#define SL_ESEC_ALT_NAME_E (-177) /* alt name size problem, too big */ +#define SL_ESEC_AES_GCM_AUTH_E (-180) /* AES-GCM Authentication check failure */ +#define SL_ESEC_AES_CCM_AUTH_E (-181) /* AES-CCM Authentication check failure */ +/* ssl tls security start with -300 offset */ +#define SL_ESEC_CLOSE_NOTIFY (-300) /* ssl/tls alerts */ +#define SL_ESEC_UNEXPECTED_MESSAGE (-310) /* ssl/tls alerts */ +#define SL_ESEC_BAD_RECORD_MAC (-320) /* ssl/tls alerts */ +#define SL_ESEC_DECRYPTION_FAILED (-321) /* ssl/tls alerts */ +#define SL_ESEC_RECORD_OVERFLOW (-322) /* ssl/tls alerts */ +#define SL_ESEC_DECOMPRESSION_FAILURE (-330) /* ssl/tls alerts */ +#define SL_ESEC_HANDSHAKE_FAILURE (-340) /* ssl/tls alerts */ +#define SL_ESEC_NO_CERTIFICATE (-341) /* ssl/tls alerts */ +#define SL_ESEC_BAD_CERTIFICATE (-342) /* ssl/tls alerts */ +#define SL_ESEC_UNSUPPORTED_CERTIFICATE (-343) /* ssl/tls alerts */ +#define SL_ESEC_CERTIFICATE_REVOKED (-344) /* ssl/tls alerts */ +#define SL_ESEC_CERTIFICATE_EXPIRED (-345) /* ssl/tls alerts */ +#define SL_ESEC_CERTIFICATE_UNKNOWN (-346) /* ssl/tls alerts */ +#define SL_ESEC_ILLEGAL_PARAMETER (-347) /* ssl/tls alerts */ +#define SL_ESEC_UNKNOWN_CA (-348) /* ssl/tls alerts */ +#define SL_ESEC_ACCESS_DENIED (-349) /* ssl/tls alerts */ +#define SL_ESEC_DECODE_ERROR (-350) /* ssl/tls alerts */ +#define SL_ESEC_DECRYPT_ERROR (-351) /* ssl/tls alerts */ +#define SL_ESEC_EXPORT_RESTRICTION (-360) /* ssl/tls alerts */ +#define SL_ESEC_PROTOCOL_VERSION (-370) /* ssl/tls alerts */ +#define SL_ESEC_INSUFFICIENT_SECURITY (-371) /* ssl/tls alerts */ +#define SL_ESEC_INTERNAL_ERROR (-380) /* ssl/tls alerts */ +#define SL_ESEC_USER_CANCELLED (-390) /* ssl/tls alerts */ +#define SL_ESEC_NO_RENEGOTIATION (-400) /* ssl/tls alerts */ +#define SL_ESEC_UNSUPPORTED_EXTENSION (-410) /* ssl/tls alerts */ +#define SL_ESEC_CERTIFICATE_UNOBTAINABLE (-411) /* ssl/tls alerts */ +#define SL_ESEC_UNRECOGNIZED_NAME (-412) /* ssl/tls alerts */ +#define SL_ESEC_BAD_CERTIFICATE_STATUS_RESPONSE (-413) /* ssl/tls alerts */ +#define SL_ESEC_BAD_CERTIFICATE_HASH_VALUE (-414) /* ssl/tls alerts */ +/* propierty secure */ +#define SL_ESECGENERAL (-450) /* error secure level general error */ +#define SL_ESECDECRYPT (-451) /* error secure level, decrypt recv packet fail */ +#define SL_ESECCLOSED (-452) /* secure layrer is closed by other size , tcp is still connected */ +#define SL_ESECSNOVERIFY (-453) /* Connected without server verification */ +#define SL_ESECNOCAFILE (-454) /* error secure level CA file not found*/ +#define SL_ESECMEMORY (-455) /* error secure level No memory space available */ +#define SL_ESECBADCAFILE (-456) /* error secure level bad CA file */ +#define SL_ESECBADCERTFILE (-457) /* error secure level bad Certificate file */ +#define SL_ESECBADPRIVATEFILE (-458) /* error secure level bad private file */ +#define SL_ESECBADDHFILE (-459) /* error secure level bad DH file */ +#define SL_ESECT00MANYSSLOPENED (-460) /* MAX SSL Sockets are opened */ +#define SL_ESECDATEERROR (-461) /* connected with certificate date verification error */ +#define SL_ESECHANDSHAKETIMEDOUT (-462) /* connection timed out due to handshake time */ + +/* end error codes */ + +/* Max payload size by protocol */ +#define SL_SOCKET_PAYLOAD_TYPE_MASK (0xF0) /*4 bits type, 4 bits sockets id */ +#define SL_SOCKET_PAYLOAD_TYPE_UDP_IPV4 (0x00) /* 1472 bytes */ +#define SL_SOCKET_PAYLOAD_TYPE_TCP_IPV4 (0x10) /* 1460 bytes */ +#define SL_SOCKET_PAYLOAD_TYPE_UDP_IPV6 (0x20) /* 1452 bytes */ +#define SL_SOCKET_PAYLOAD_TYPE_TCP_IPV6 (0x30) /* 1440 bytes */ +#define SL_SOCKET_PAYLOAD_TYPE_UDP_IPV4_SECURE (0x40) /* */ +#define SL_SOCKET_PAYLOAD_TYPE_TCP_IPV4_SECURE (0x50) /* */ +#define SL_SOCKET_PAYLOAD_TYPE_UDP_IPV6_SECURE (0x60) /* */ +#define SL_SOCKET_PAYLOAD_TYPE_TCP_IPV6_SECURE (0x70) /* */ +#define SL_SOCKET_PAYLOAD_TYPE_RAW_TRANCEIVER (0x80) /* 1536 bytes */ +#define SL_SOCKET_PAYLOAD_TYPE_RAW_PACKET (0x90) /* 1536 bytes */ +#define SL_SOCKET_PAYLOAD_TYPE_RAW_IP4 (0xa0) +#define SL_SOCKET_PAYLOAD_TYPE_RAW_IP6 (SL_SOCKET_PAYLOAD_TYPE_RAW_IP4 ) + + + +#define SL_SOL_SOCKET (1) /* Define the socket option category. */ +#define SL_IPPROTO_IP (2) /* Define the IP option category. */ +#define SL_SOL_PHY_OPT (3) /* Define the PHY option category. */ + +#define SL_SO_RCVBUF (8) /* Setting TCP receive buffer size */ +#define SL_SO_KEEPALIVE (9) /* Connections are kept alive with periodic messages */ +#define SL_SO_RCVTIMEO (20) /* Enable receive timeout */ +#define SL_SO_NONBLOCKING (24) /* Enable . disable nonblocking mode */ +#define SL_SO_SECMETHOD (25) /* security metohd */ +#define SL_SO_SECURE_MASK (26) /* security mask */ +#define SL_SO_SECURE_FILES (27) /* security files */ +#define SL_SO_CHANGE_CHANNEL (28) /* This option is available only when transceiver started */ +#define SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME (30) /* This option used to configue secure file */ +#define SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME (31) /* This option used to configue secure file */ +#define SL_SO_SECURE_FILES_CA_FILE_NAME (32) /* This option used to configue secure file */ +#define SL_SO_SECURE_FILES_DH_KEY_FILE_NAME (33) /* This option used to configue secure file */ + +#define SL_IP_MULTICAST_IF (60) /* Specify outgoing multicast interface */ +#define SL_IP_MULTICAST_TTL (61) /* Specify the TTL value to use for outgoing multicast packet. */ +#define SL_IP_ADD_MEMBERSHIP (65) /* Join IPv4 multicast membership */ +#define SL_IP_DROP_MEMBERSHIP (66) /* Leave IPv4 multicast membership */ +#define SL_IP_HDRINCL (67) /* Raw socket IPv4 header included. */ +#define SL_IP_RAW_RX_NO_HEADER (68) /* Proprietary socket option that does not includeIPv4/IPv6 header (and extension headers) on received raw sockets*/ +#define SL_IP_RAW_IPV6_HDRINCL (69) /* Transmitted buffer over IPv6 socket contains IPv6 header. */ + +#define SL_SO_PHY_RATE (100) /* WLAN Transmit rate */ +#define SL_SO_PHY_TX_POWER (101) /* TX Power level */ +#define SL_SO_PHY_NUM_FRAMES_TO_TX (102) /* Number of frames to transmit */ +#define SL_SO_PHY_PREAMBLE (103) /* Preamble for transmission */ + +#define SL_SO_SEC_METHOD_SSLV3 (0) /* security metohd SSL v3*/ +#define SL_SO_SEC_METHOD_TLSV1 (1) /* security metohd TLS v1*/ +#define SL_SO_SEC_METHOD_TLSV1_1 (2) /* security metohd TLS v1_1*/ +#define SL_SO_SEC_METHOD_TLSV1_2 (3) /* security metohd TLS v1_2*/ +#define SL_SO_SEC_METHOD_SSLv3_TLSV1_2 (4) /* use highest possible version from SSLv3 - TLS 1.2*/ +#define SL_SO_SEC_METHOD_DLSV1 (5) /* security metohd DTL v1 */ + +#define SL_SEC_MASK_SSL_RSA_WITH_RC4_128_SHA (1 << 0) +#define SL_SEC_MASK_SSL_RSA_WITH_RC4_128_MD5 (1 << 1) +#define SL_SEC_MASK_TLS_RSA_WITH_AES_256_CBC_SHA (1 << 2) +#define SL_SEC_MASK_TLS_DHE_RSA_WITH_AES_256_CBC_SHA (1 << 3) +#define SL_SEC_MASK_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA (1 << 4) +#define SL_SEC_MASK_TLS_ECDHE_RSA_WITH_RC4_128_SHA (1 << 5) +#define SL_SEC_MASK_SECURE_DEFAULT ((SEC_MASK_TLS_ECDHE_RSA_WITH_RC4_128_SHA << 1) - 1) + +#define SL_MSG_DONTWAIT (0x00000008) /* Nonblocking IO */ + +/* AP DHCP Server - IP Release reason code */ +#define SL_IP_LEASE_PEER_RELEASE (0) +#define SL_IP_LEASE_PEER_DECLINE (1) +#define SL_IP_LEASE_EXPIRED (2) + +/* possible types when receiving SL_SOCKET_ASYNC_EVENT*/ +#define SSL_ACCEPT (1) /* accept failed due to ssl issue ( tcp pass) */ +#define RX_FRAGMENTATION_TOO_BIG (2) /* connection less mode, rx packet fragmentation > 16K, packet is being released */ +#define OTHER_SIDE_CLOSE_SSL_DATA_NOT_ENCRYPTED (3) /* remote side down from secure to unsecure */ + + + +#ifdef SL_INC_STD_BSD_API_NAMING + +#define FD_SETSIZE SL_FD_SETSIZE + +#define SOCK_STREAM SL_SOCK_STREAM +#define SOCK_DGRAM SL_SOCK_DGRAM +#define SOCK_RAW SL_SOCK_RAW +#define IPPROTO_TCP SL_IPPROTO_TCP +#define IPPROTO_UDP SL_IPPROTO_UDP +#define IPPROTO_RAW SL_IPPROTO_RAW + +#define AF_INET SL_AF_INET +#define AF_INET6 SL_AF_INET6 +#define AF_INET6_EUI_48 SL_AF_INET6_EUI_48 +#define AF_RF SL_AF_RF +#define AF_PACKET SL_AF_PACKET + +#define PF_INET SL_PF_INET +#define PF_INET6 SL_PF_INET6 + +#define INADDR_ANY SL_INADDR_ANY +#define ERROR SL_SOC_ERROR +#define INEXE SL_INEXE +#define EBADF SL_EBADF +#define ENSOCK SL_ENSOCK +#define EAGAIN SL_EAGAIN +#define EWOULDBLOCK SL_EWOULDBLOCK +#define ENOMEM SL_ENOMEM +#define EACCES SL_EACCES +#define EFAULT SL_EFAULT +#define EINVAL SL_EINVAL +#define EDESTADDRREQ SL_EDESTADDRREQ +#define EPROTOTYPE SL_EPROTOTYPE +#define ENOPROTOOPT SL_ENOPROTOOPT +#define EPROTONOSUPPORT SL_EPROTONOSUPPORT +#define ESOCKTNOSUPPORT SL_ESOCKTNOSUPPORT +#define EOPNOTSUPP SL_EOPNOTSUPP +#define EAFNOSUPPORT SL_EAFNOSUPPORT +#define EADDRINUSE SL_EADDRINUSE +#define EADDRNOTAVAIL SL_EADDRNOTAVAIL +#define ENETUNREACH SL_ENETUNREACH +#define ENOBUFS SL_ENOBUFS +#define EOBUFF SL_EOBUFF +#define EISCONN SL_EISCONN +#define ENOTCONN SL_ENOTCONN +#define ETIMEDOUT SL_ETIMEDOUT +#define ECONNREFUSED SL_ECONNREFUSED + +#define SOL_SOCKET SL_SOL_SOCKET +#define IPPROTO_IP SL_IPPROTO_IP +#define SO_KEEPALIVE SL_SO_KEEPALIVE + +#define SO_RCVTIMEO SL_SO_RCVTIMEO +#define SO_NONBLOCKING SL_SO_NONBLOCKING + +#define IP_MULTICAST_IF SL_IP_MULTICAST_IF +#define IP_MULTICAST_TTL SL_IP_MULTICAST_TTL +#define IP_ADD_MEMBERSHIP SL_IP_ADD_MEMBERSHIP +#define IP_DROP_MEMBERSHIP SL_IP_DROP_MEMBERSHIP + +#define socklen_t SlSocklen_t +#define timeval SlTimeval_t +#define sockaddr SlSockAddr_t +#define in6_addr SlIn6Addr_t +#define sockaddr_in6 SlSockAddrIn6_t +#define in_addr SlInAddr_t +#define sockaddr_in SlSockAddrIn_t + +#define MSG_DONTWAIT SL_MSG_DONTWAIT + +#define FD_SET SL_FD_SET +#define FD_CLR SL_FD_CLR +#define FD_ISSET SL_FD_ISSET +#define FD_ZERO SL_FD_ZERO +#define fd_set SlFdSet_t + +#define socket sl_Socket +#define close sl_Close +#define accept sl_Accept +#define bind sl_Bind +#define listen sl_Listen +#define connect sl_Connect +#define select sl_Select +#define setsockopt sl_SetSockOpt +#define getsockopt sl_GetSockOpt +#define recv sl_Recv +#define recvfrom sl_RecvFrom +#define write sl_Write +#define send sl_Send +#define sendto sl_SendTo +#define gethostbyname sl_NetAppDnsGetHostByName +#define htonl sl_Htonl +#define ntohl sl_Ntohl +#define htons sl_Htons +#define ntohs sl_Ntohs +#endif + +/*****************************************************************************/ +/* Structure/Enum declarations */ +/*****************************************************************************/ + +/* Internet address */ +typedef struct SlInAddr_t +{ +#ifndef s_addr + _u32 s_addr; /* Internet address 32 bits */ +#else + union S_un { + struct { _u8 s_b1,s_b2,s_b3,s_b4; } S_un_b; + struct { _u8 s_w1,s_w2; } S_un_w; + _u32 S_addr; + } S_un; +#endif +}SlInAddr_t; + + +/* sockopt */ +typedef struct +{ + _u32 KeepaliveEnabled; /* 0 = disabled;1 = enabled; default = 1*/ +}SlSockKeepalive_t; + +typedef struct +{ + _u32 ReuseaddrEnabled; /* 0 = disabled; 1 = enabled; default = 1*/ +}SlSockReuseaddr_t; + +typedef struct +{ + _u32 Winsize; /* receive window size for tcp sockets */ +}SlSockWinsize_t; + +typedef struct +{ + _u32 NonblockingEnabled;/* 0 = disabled;1 = enabled;default = 1*/ +}SlSockNonblocking_t; + +typedef struct +{ + _u8 sd; + _u8 type; + _u16 val; +} SlSocketAsyncEvent_t; + +typedef struct +{ + _i16 status; + _u16 sd; + SlSocketAsyncEvent_t socketAsyncEvent; +} SlSockEventData_t; + + +typedef struct +{ + _u32 Event; + SlSockEventData_t EventData; +} SlSockEvent_t; + + +typedef struct +{ + _u32 secureMask; +} SlSockSecureMask; + +typedef struct +{ + _u8 secureMethod; +} SlSockSecureMethod; + +typedef enum +{ + SL_BSD_SECURED_PRIVATE_KEY_IDX = 0, + SL_BSD_SECURED_CERTIFICATE_IDX, + SL_BSD_SECURED_CA_IDX, + SL_BSD_SECURED_DH_IDX +}slBsd_secureSocketFilesIndex_e; + +typedef struct +{ + SlInAddr_t imr_multiaddr; /* The IPv4 multicast address to join */ + SlInAddr_t imr_interface; /* The interface to use for this group */ +} SlSockIpMreq; + + +/* sockopt */ +typedef _u32 SlTime_t; +typedef _u32 SlSuseconds_t; + +typedef struct SlTimeval_t +{ + SlTime_t tv_sec; /* Seconds */ + SlSuseconds_t tv_usec; /* Microseconds */ +}SlTimeval_t; + +typedef _u16 SlSocklen_t; + +/* IpV4 socket address */ +typedef struct SlSockAddr_t +{ + _u16 sa_family; /* Address family (e.g. , AF_INET) */ + _u8 sa_data[14]; /* Protocol- specific address information*/ +}SlSockAddr_t; + + +/* IpV6 or Ipv6 EUI64 */ +typedef struct SlIn6Addr_t +{ + union + { + _u8 _S6_u8[16]; + _u32 _S6_u32[4]; + } _S6_un; +}SlIn6Addr_t; + +typedef struct SlSockAddrIn6_t +{ + _u16 sin6_family; /* AF_INET6 || AF_INET6_EUI_48*/ + _u16 sin6_port; /* Transport layer port. */ + _u32 sin6_flowinfo; /* IPv6 flow information. */ + SlIn6Addr_t sin6_addr; /* IPv6 address. */ + _u32 sin6_scope_id; /* set of interfaces for a scope. */ +}SlSockAddrIn6_t; + +/* Socket address, Internet style. */ + +typedef struct SlSockAddrIn_t +{ + _u16 sin_family; /* Internet Protocol (AF_INET). */ + _u16 sin_port; /* Address port (16 bits). */ + SlInAddr_t sin_addr; /* Internet address (32 bits). */ + _i8 sin_zero[8]; /* Not used. */ +}SlSockAddrIn_t; + +typedef struct +{ + _u32 ip; + _u32 gateway; + _u32 dns; +}SlIpV4AcquiredAsync_t; + +typedef struct +{ + _u32 type; + _u32 ip[4]; + _u32 gateway[4]; + _u32 dns[4]; +}SlIpV6AcquiredAsync_t; + +typedef struct +{ + _u32 ip_address; + _u32 lease_time; + _u8 mac[6]; + _u16 padding; +}SlIpLeasedAsync_t; + +typedef struct +{ + _u32 ip_address; + _u8 mac[6]; + _u16 reason; +}SlIpReleasedAsync_t; + + +typedef union +{ + SlIpV4AcquiredAsync_t ipAcquiredV4; /*SL_NETAPP_IPV4_IPACQUIRED_EVENT*/ + SlIpV6AcquiredAsync_t ipAcquiredV6; /*SL_NETAPP_IPV6_IPACQUIRED_EVENT*/ + _u32 sd; /*SL_SOCKET_TX_FAILED_EVENT*/ + SlIpLeasedAsync_t ipLeased; /* SL_NETAPP_IP_LEASED_EVENT */ + SlIpReleasedAsync_t ipReleased; /* SL_NETAPP_IP_RELEASED_EVENT */ +} SlNetAppEventData_u; + +typedef struct +{ + _u32 Event; + SlNetAppEventData_u EventData; +}SlNetAppEvent_t; + + +typedef struct sock_secureFiles +{ + _u8 secureFiles[4]; +}SlSockSecureFiles_t; + + +typedef struct SlFdSet_t /* The select socket array manager */ +{ + _u32 fd_array[(SL_FD_SETSIZE + 31)/32]; /* Bit map of SOCKET Descriptors */ +} SlFdSet_t; + +typedef struct +{ + _u8 rate; /* Recevied Rate */ + _u8 channel; /* The received channel*/ + _i8 rssi; /* The computed RSSI value in db of current frame */ + _u8 padding; /* pad to align to 32 bits */ + _u32 timestamp; /* Timestamp in microseconds, */ +}SlTransceiverRxOverHead_t; + + + +/*****************************************************************************/ +/* Function prototypes */ +/*****************************************************************************/ + +/*! + + \brief create an endpoint for communication + + The socket function creates a new socket of a certain socket type, identified + by an integer number, and allocates system resources to it. + This function is called by the application layer to obtain a socket handle. + + \param[in] domain specifies the protocol family of the created socket. + For example: + AF_INET for network protocol IPv4 + AF_RF for starting transceiver mode. Notes: + - sending and receiving any packet overriding 802.11 header + - for optimized power consumption the socket will be started in TX + only mode until receive command is activated + AF_INET6 for IPv6 + + + \param[in] type specifies the communication semantic, one of: + SOCK_STREAM (reliable stream-oriented service or Stream Sockets) + SOCK_DGRAM (datagram service or Datagram Sockets) + SOCK_RAW (raw protocols atop the network layer) + when used with AF_RF: + SOCK_DGRAM - L2 socket + SOCK_RAW - L1 socket - bypass WLAN CCA (Clear Channel Assessment) + + \param[in] protocol specifies a particular transport to be used with + the socket. + The most common are IPPROTO_TCP, IPPROTO_SCTP, IPPROTO_UDP, + IPPROTO_DCCP. + The value 0 may be used to select a default + protocol from the selected domain and type + + + \return On success, socket handle that is used for consequent socket operations. + A successful return code should be a positive number (int16) + On error, a negative (int16) value will be returned specifying the error code. + SL_EAFNOSUPPORT - illegal domain parameter + SL_EPROTOTYPE - illegal type parameter + SL_EACCES - permission denied + SL_ENSOCK - exceeded maximal number of socket + SL_ENOMEM - memory allocation error + SL_EINVAL - error in socket configuration + SL_EPROTONOSUPPORT - illegal protocol parameter + SL_EOPNOTSUPP - illegal combination of protocol and type parameters + + + \sa sl_Close + \note belongs to \ref basic_api + \warning +*/ +#if _SL_INCLUDE_FUNC(sl_Socket) +_i16 sl_Socket(_i16 Domain, _i16 Type, _i16 Protocol); +#endif + +/*! + \brief gracefully close socket + + This function causes the system to release resources allocated to a socket. \n + In case of TCP, the connection is terminated. + + \param[in] sd socket handle (received in sl_Socket) + + \return On success, zero is returned. + On error, a negative number is returned. + + \sa sl_Socket + \note belongs to \ref ext_api + \warning +*/ +#if _SL_INCLUDE_FUNC(sl_Close) +_i16 sl_Close(_i16 sd); +#endif + +/*! + \brief Accept a connection on a socket + + This function is used with connection-based socket types (SOCK_STREAM). + It extracts the first connection request on the queue of pending + connections, creates a new connected socket, and returns a new file + descriptor referring to that socket. + The newly created socket is not in the listening state. The + original socket sd is unaffected by this call. + The argument sd is a socket that has been created with + sl_Socket(), bound to a local address with sl_Bind(), and is + listening for connections after a sl_Listen(). The argument \b + \e addr is a pointer to a sockaddr structure. This structure + is filled in with the address of the peer socket, as known to + the communications layer. The exact format of the address + returned addr is determined by the socket's address family. + The \b \e addrlen argument is a value-result argument: it + should initially contain the size of the structure pointed to + by addr, on return it will contain the actual length (in + bytes) of the address returned. + + \param[in] sd socket descriptor (handle) + \param[out] addr the argument addr is a pointer + to a sockaddr structure. This + structure is filled in with the + address of the peer socket, as + known to the communications + layer. The exact format of the + address returned addr is + determined by the socket's + address\n + sockaddr:\n - code for the + address format. On this version + only AF_INET is supported.\n - + socket address, the length + depends on the code format + \param[out] addrlen the addrlen argument is a value-result + argument: it should initially contain the + size of the structure pointed to by addr + + \return On success, a socket handle. + On a non-blocking accept a possible negative value is SL_EAGAIN. + On failure, negative value. + SL_POOL_IS_EMPTY may be return in case there are no resources in the system + In this case try again later or increase MAX_CONCURRENT_ACTIONS + + \sa sl_Socket sl_Bind sl_Listen + \note belongs to \ref server_side + \warning +*/ +#if _SL_INCLUDE_FUNC(sl_Accept) +_i16 sl_Accept(_i16 sd, SlSockAddr_t *addr, SlSocklen_t *addrlen); +#endif + +/*! + \brief assign a name to a socket + + This function gives the socket the local address addr. + addr is addrlen bytes long. Traditionally, this is called + When a socket is created with socket, it exists in a name + space (address family) but has no name assigned. + It is necessary to assign a local address before a SOCK_STREAM + socket may receive connections. + + \param[in] sd socket descriptor (handle) + \param[in] addr specifies the destination + addrs\n sockaddr:\n - code for + the address format. On this + version only AF_INET is + supported.\n - socket address, + the length depends on the code + format + \param[in] addrlen contains the size of the structure pointed to by addr + + \return On success, zero is returned. On error, a negative error code is returned. + + \sa sl_Socket sl_Accept sl_Listen + \note belongs to \ref basic_api + \warning +*/ +#if _SL_INCLUDE_FUNC(sl_Bind) +_i16 sl_Bind(_i16 sd, const SlSockAddr_t *addr, _i16 addrlen); +#endif + +/*! + \brief listen for connections on a socket + + The willingness to accept incoming connections and a queue + limit for incoming connections are specified with listen(), + and then the connections are accepted with accept. + The listen() call applies only to sockets of type SOCK_STREAM + The backlog parameter defines the maximum length the queue of + pending connections may grow to. + + \param[in] sd socket descriptor (handle) + \param[in] backlog specifies the listen queue depth. + + + \return On success, zero is returned. On error, a negative error code is returned. + + \sa sl_Socket sl_Accept sl_Bind + \note belongs to \ref server_side + \warning +*/ +#if _SL_INCLUDE_FUNC(sl_Listen) +_i16 sl_Listen(_i16 sd, _i16 backlog); +#endif + +/*! + \brief Initiate a connection on a socket + + Function connects the socket referred to by the socket + descriptor sd, to the address specified by addr. The addrlen + argument specifies the size of addr. The format of the + address in addr is determined by the address space of the + socket. If it is of type SOCK_DGRAM, this call specifies the + peer with which the socket is to be associated; this address + is that to which datagrams are to be sent, and the only + address from which datagrams are to be received. If the + socket is of type SOCK_STREAM, this call attempts to make a + connection to another socket. The other socket is specified + by address, which is an address in the communications space + of the socket. + + + \param[in] sd socket descriptor (handle) + \param[in] addr specifies the destination addr\n + sockaddr:\n - code for the + address format. On this version + only AF_INET is supported.\n - + socket address, the length + depends on the code format + + \param[in] addrlen contains the size of the structure pointed + to by addr + + \return On success, a socket handle. + On a non-blocking connect a possible negative value is SL_EALREADY. + On failure, negative value. + SL_POOL_IS_EMPTY may be return in case there are no resources in the system + In this case try again later or increase MAX_CONCURRENT_ACTIONS + + \sa sl_Socket + \note belongs to \ref client_side + \warning +*/ +#if _SL_INCLUDE_FUNC(sl_Connect) +_i16 sl_Connect(_i16 sd, const SlSockAddr_t *addr, _i16 addrlen); +#endif + +/*! + \brief Monitor socket activity + + Select allow a program to monitor multiple file descriptors, + waiting until one or more of the file descriptors become + "ready" for some class of I/O operation + + + \param[in] nfds the highest-numbered file descriptor in any of the + three sets, plus 1. + \param[out] readsds socket descriptors list for read monitoring and accept monitoring + \param[out] writesds socket descriptors list for connect monitoring only, write monitoring is not supported + \param[out] exceptsds socket descriptors list for exception monitoring, not supported. + \param[in] timeout is an upper bound on the amount of time elapsed + before select() returns. Null or above 0xffff seconds means + infinity timeout. The minimum timeout is 10 milliseconds, + less than 10 milliseconds will be set automatically to 10 milliseconds. + Max microseconds supported is 0xfffc00. + + \return On success, select() returns the number of + file descriptors contained in the three returned + descriptor sets (that is, the total number of bits that + are set in readfds, writefds, exceptfds) which may be + zero if the timeout expires before anything interesting + happens. On error, a negative value is returned. + readsds - return the sockets on which Read request will + return without delay with valid data. + writesds - return the sockets on which Write request + will return without delay. + exceptsds - return the sockets closed recently. + SL_POOL_IS_EMPTY may be return in case there are no resources in the system + In this case try again later or increase MAX_CONCURRENT_ACTIONS + + \sa sl_Socket + \note If the timeout value set to less than 5ms it will automatically set + to 5ms to prevent overload of the system + belongs to \ref basic_api + + Only one sl_Select can be handled at a time. + Calling this API while the same command is called from another thread, may result + in one of the two scenarios: + 1. The command will wait (internal) until the previous command finish, and then be executed. + 2. There are not enough resources and SL_POOL_IS_EMPTY error will return. + In this case, MAX_CONCURRENT_ACTIONS can be increased (result in memory increase) or try + again later to issue the command. + + \warning +*/ +#if _SL_INCLUDE_FUNC(sl_Select) +_i16 sl_Select(_i16 nfds, SlFdSet_t *readsds, SlFdSet_t *writesds, SlFdSet_t *exceptsds, struct SlTimeval_t *timeout); + + +/*! + \brief Select's SlFdSet_t SET function + + Sets current socket descriptor on SlFdSet_t container +*/ +void SL_FD_SET(_i16 fd, SlFdSet_t *fdset); + +/*! + \brief Select's SlFdSet_t CLR function + + Clears current socket descriptor on SlFdSet_t container +*/ +void SL_FD_CLR(_i16 fd, SlFdSet_t *fdset); + + +/*! + \brief Select's SlFdSet_t ISSET function + + Checks if current socket descriptor is set (TRUE/FALSE) + + \return Returns TRUE if set, FALSE if unset + +*/ +_i16 SL_FD_ISSET(_i16 fd, SlFdSet_t *fdset); + +/*! + \brief Select's SlFdSet_t ZERO function + + Clears all socket descriptors from SlFdSet_t +*/ +void SL_FD_ZERO(SlFdSet_t *fdset); + + + +#endif + +/*! + \brief set socket options + + This function manipulate the options associated with a socket. + Options may exist at multiple protocol levels; they are always + present at the uppermost socket level. + + When manipulating socket options the level at which the option resides + and the name of the option must be specified. To manipulate options at + the socket level, level is specified as SOL_SOCKET. To manipulate + options at any other level the protocol number of the appropriate proto- + col controlling the option is supplied. For example, to indicate that an + option is to be interpreted by the TCP protocol, level should be set to + the protocol number of TCP; + + The parameters optval and optlen are used to access optval - + ues for setsockopt(). For getsockopt() they identify a + buffer in which the value for the requested option(s) are to + be returned. For getsockopt(), optlen is a value-result + parameter, initially containing the size of the buffer + pointed to by option_value, and modified on return to + indicate the actual size of the value returned. If no option + value is to be supplied or returned, option_value may be + NULL. + + \param[in] sd socket handle + \param[in] level defines the protocol level for this option + - <b>SL_SOL_SOCKET</b> Socket level configurations (L4, transport layer) + - <b>SL_IPPROTO_IP</b> IP level configurations (L3, network layer) + - <b>SL_SOL_PHY_OPT</b> Link level configurations (L2, link layer) + \param[in] optname defines the option name to interrogate + - <b>SL_SOL_SOCKET</b> + - <b>SL_SO_KEEPALIVE</b> \n + Enable/Disable periodic keep alive. + Keeps TCP connections active by enabling the periodic transmission of messages \n + Timeout is 5 minutes.\n + Default: Enabled \n + This options takes SlSockKeepalive_t struct as parameter + - <b>SL_SO_RCVTIMEO</b> \n + Sets the timeout value that specifies the maximum amount of time an input function waits until it completes. \n + Default: No timeout \n + This options takes SlTimeval_t struct as parameter + - <b>SL_SO_RCVBUF</b> \n + Sets tcp max recv window size. \n + This options takes SlSockWinsize_t struct as parameter + - <b>SL_SO_NONBLOCKING</b> \n + Sets socket to non-blocking operation Impacts: connect, accept, send, sendto, recv and recvfrom. \n + Default: Blocking. + This options takes SlSockNonblocking_t struct as parameter + - <b>SL_SO_SECMETHOD</b> \n + Sets method to tcp secured socket (SL_SEC_SOCKET) \n + Default: SL_SO_SEC_METHOD_SSLv3_TLSV1_2 \n + This options takes SlSockSecureMethod struct as parameter + - <b>SL_SO_SEC_MASK</b> \n + Sets specific cipher to tcp secured socket (SL_SEC_SOCKET) \n + Default: "Best" cipher suitable to method \n + This options takes SlSockSecureMask struct as parameter + - <b>SL_SO_SECURE_FILES_CA_FILE_NAME</b> \n + Map secured socket to CA file by name \n + This options takes <b>_u8</b> buffer as parameter + - <b>SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME</b> \n + Map secured socket to private key by name \n + This options takes <b>_u8</b> buffer as parameter + - <b>SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME</b> \n + Map secured socket to certificate file by name \n + This options takes <b>_u8</b> buffer as parameter + - <b>SL_SO_SECURE_FILES_DH_KEY_FILE_NAME</b> \n + Map secured socket to Diffie Hellman file by name \n + This options takes <b>_u8</b> buffer as parameter + - <b>SL_SO_CHANGE_CHANNEL</b> \n + Sets channel in transceiver mode. + This options takes <b>_u32</b> as channel number parameter + - <b>SL_IPPROTO_IP</b> + - <b>SL_IP_MULTICAST_TTL</b> \n + Set the time-to-live value of outgoing multicast packets for this socket. \n + This options takes <b>_u8</b> as parameter + - <b>SL_IP_ADD_MEMBERSHIP</b> \n + UDP socket, Join a multicast group. \n + This options takes SlSockIpMreq struct as parameter + - <b>SL_IP_DROP_MEMBERSHIP</b> \n + UDP socket, Leave a multicast group \n + This options takes SlSockIpMreq struct as parameter + - <b>SL_IP_RAW_RX_NO_HEADER</b> \n + Raw socket remove IP header from received data. \n + Default: data includes ip header \n + This options takes <b>_u32</b> as parameter + - <b>SL_IP_HDRINCL</b> \n + RAW socket only, the IPv4 layer generates an IP header when sending a packet unless \n + the IP_HDRINCL socket option is enabled on the socket. \n + When it is enabled, the packet must contain an IP header. \n + Default: disabled, IPv4 header generated by Network Stack \n + This options takes <b>_u32</b> as parameter + - <b>SL_IP_RAW_IPV6_HDRINCL</b> (inactive) \n + RAW socket only, the IPv6 layer generates an IP header when sending a packet unless \n + the IP_HDRINCL socket option is enabled on the socket. When it is enabled, the packet must contain an IP header \n + Default: disabled, IPv4 header generated by Network Stack \n + This options takes <b>_u32</b> as parameter + - <b>SL_SOL_PHY_OPT</b> + - <b>SL_SO_PHY_RATE</b> \n + RAW socket, set WLAN PHY transmit rate \n + The values are based on RateIndex_e \n + This options takes <b>_u32</b> as parameter + - <b>SL_SO_PHY_TX_POWER</b> \n + RAW socket, set WLAN PHY TX power \n + Valid rage is 1-15 \n + This options takes <b>_u32</b> as parameter + - <b>SL_SO_PHY_NUM_FRAMES_TO_TX</b> \n + RAW socket, set number of frames to transmit in transceiver mode. + Default: 1 packet + This options takes <b>_u32</b> as parameter + - <b>SL_SO_PHY_PREAMBLE</b> \n + RAW socket, set WLAN PHY preamble for Long/Short\n + This options takes <b>_u32</b> as parameter + + \param[in] optval specifies a value for the option + \param[in] optlen specifies the length of the + option value + + \return On success, zero is returned. + On error, a negative value is returned. + \sa sl_getsockopt + \note belongs to \ref basic_api + \warning + \par Examples: + \par + <b> SL_SO_KEEPALIVE: </b>(disable Keepalive) + \code + SlSockKeepalive_t enableOption; + enableOption.KeepaliveEnabled = 0; + sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_KEEPALIVE, (_u8 *)&enableOption,sizeof(enableOption)); + \endcode + \par + <b> SL_SO_RCVTIMEO: </b> + \code + struct SlTimeval_t timeVal; + timeVal.tv_sec = 1; // Seconds + timeVal.tv_usec = 0; // Microseconds. 10000 microseconds resolution + sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_RCVTIMEO, (_u8 *)&timeVal, sizeof(timeVal)); // Enable receive timeout + \endcode + \par + <b> SL_SO_RCVBUF: </b> + \code + SlSockWinsize_t size; + size.Winsize = 3000; // bytes + sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_RCVBUF, (_u8 *)&size, sizeof(size)); + \endcode + \par + <b> SL_SO_NONBLOCKING: </b> + \code + SlSockNonblocking_t enableOption; + enableOption.NonblockingEnabled = 1; + sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_NONBLOCKING, (_u8 *)&enableOption,sizeof(enableOption)); // Enable/disable nonblocking mode + \endcode + \par + <b> SL_SO_SECMETHOD:</b> + \code + SlSockSecureMethod method; + method.secureMethod = SL_SO_SEC_METHOD_SSLV3; // security method we want to use + SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, SL_SEC_SOCKET); + sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_SECMETHOD, (_u8 *)&method, sizeof(method)); + \endcode + \par + <b> SL_SO_SECURE_MASK:</b> + \code + SlSockSecureMask cipher; + cipher.secureMask = SL_SEC_MASK_SSL_RSA_WITH_RC4_128_SHA; // cipher type + SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, SL_SEC_SOCKET); + sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_SEC_MASK,(_u8 *)&cipher, sizeof(cipher)); + \endcode + \par + <b> SL_SO_SECURE_FILES_CA_FILE_NAME:</b> + \code + sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SECURE_FILES_CA_FILE_NAME,"exuifaxCaCert.der",strlen("exuifaxCaCert.der")); + \endcode + + \par + <b> SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME:</b> + \code + sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME,"myPrivateKey.der",strlen("myPrivateKey.der")); + \endcode + + \par + <b> SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME:</b> + \code + sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME,"myCertificate.der",strlen("myCertificate.der")); + \endcode + + \par + <b> SL_SO_SECURE_FILES_DH_KEY_FILE_NAME:</b> + \code + sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SECURE_FILES_DH_KEY_FILE_NAME,"myDHinServerMode.der",strlen("myDHinServerMode.der")); + \endcode + + \par + <b> SL_IP_MULTICAST_TTL:</b> + \code + _u8 ttl = 20; + sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_MULTICAST_TTL, &ttl, sizeof(ttl)); + \endcode + + \par + <b> SL_IP_ADD_MEMBERSHIP:</b> + \code + SlSockIpMreq mreq; + sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); + \endcode + + \par + <b> SL_IP_DROP_MEMBERSHIP:</b> + \code + SlSockIpMreq mreq; + sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq)); + \endcode + + \par + <b> SL_SO_CHANGE_CHANNEL:</b> + \code + _u32 newChannel = 6; // range is 1-13 + sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_CHANGE_CHANNEL, &newChannel, sizeof(newChannel)); + \endcode + + \par + <b> SL_IP_RAW_RX_NO_HEADER:</b> + \code + _u32 header = 1; // remove ip header + sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_RAW_RX_NO_HEADER, &header, sizeof(header)); + \endcode + + \par + <b> SL_IP_HDRINCL:</b> + \code + _u32 header = 1; + sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_HDRINCL, &header, sizeof(header)); + \endcode + \par + <b> SL_IP_RAW_IPV6_HDRINCL:</b> + \code + _u32 header = 1; + sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_RAW_IPV6_HDRINCL, &header, sizeof(header)); + \endcode + + \par + <b> SL_SO_PHY_RATE:</b> + \code + _u32 rate = 6; // see wlan.h RateIndex_e for values + sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_RATE, &rate, sizeof(rate)); + \endcode + + \par + <b> SL_SO_PHY_TX_POWER:</b> + \code + _u32 txpower = 1; // valid range is 1-15 + sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_TX_POWER, &txpower, sizeof(txpower)); + \endcode + + \par + <b> SL_SO_PHY_NUM_FRAMES_TO_TX:</b> + \code + _u32 numframes = 1; + sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_NUM_FRAMES_TO_TX, &numframes, sizeof(numframes)); + \endcode + + \par + <b> SL_SO_PHY_PREAMBLE:</b> + \code + _u32 preamble = 1; + sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_PREAMBLE, &preamble, sizeof(preamble)); + \endcode + +*/ +#if _SL_INCLUDE_FUNC(sl_SetSockOpt) +_i16 sl_SetSockOpt(_i16 sd, _i16 level, _i16 optname, const void *optval, SlSocklen_t optlen); +#endif + +/*! + \brief Get socket options + + This function manipulate the options associated with a socket. + Options may exist at multiple protocol levels; they are always + present at the uppermost socket level. + + When manipulating socket options the level at which the option resides + and the name of the option must be specified. To manipulate options at + the socket level, level is specified as SOL_SOCKET. To manipulate + options at any other level the protocol number of the appropriate proto- + col controlling the option is supplied. For example, to indicate that an + option is to be interpreted by the TCP protocol, level should be set to + the protocol number of TCP; + + The parameters optval and optlen are used to access optval - + ues for setsockopt(). For getsockopt() they identify a + buffer in which the value for the requested option(s) are to + be returned. For getsockopt(), optlen is a value-result + parameter, initially containing the size of the buffer + pointed to by option_value, and modified on return to + indicate the actual size of the value returned. If no option + value is to be supplied or returned, option_value may be + NULL. + + + \param[in] sd socket handle + \param[in] level defines the protocol level for this option + \param[in] optname defines the option name to interrogate + \param[out] optval specifies a value for the option + \param[out] optlen specifies the length of the + option value + + \return On success, zero is returned. + On error, a negative value is returned. + \sa sl_SetSockOpt + \note See sl_SetSockOpt + belongs to \ref ext_api + \warning +*/ +#if _SL_INCLUDE_FUNC(sl_GetSockOpt) +_i16 sl_GetSockOpt(_i16 sd, _i16 level, _i16 optname, void *optval, SlSocklen_t *optlen); +#endif + +/*! + \brief read data from TCP socket + + function receives a message from a connection-mode socket + + \param[in] sd socket handle + \param[out] buf Points to the buffer where the + message should be stored. + \param[in] Len Specifies the length in bytes of + the buffer pointed to by the buffer argument. + Range: 1-16000 bytes + \param[in] flags Specifies the type of message + reception. On this version, this parameter is not + supported. + + \return return the number of bytes received, + or a negative value if an error occurred. + using a non-blocking recv a possible negative value is SL_EAGAIN. + SL_POOL_IS_EMPTY may be return in case there are no resources in the system + In this case try again later or increase MAX_CONCURRENT_ACTIONS + + \sa sl_RecvFrom + \note belongs to \ref recv_api + \warning + \par Examples: + \code An example of receiving data using TCP socket: + + SlSockAddrIn_t Addr; + SlSockAddrIn_t LocalAddr; + _i16 AddrSize = sizeof(SlSockAddrIn_t); + _i16 SockID, newSockID; + _i16 Status; + _i8 Buf[RECV_BUF_LEN]; + + LocalAddr.sin_family = SL_AF_INET; + LocalAddr.sin_port = sl_Htons(5001); + LocalAddr.sin_addr.s_addr = 0; + + Addr.sin_family = SL_AF_INET; + Addr.sin_port = sl_Htons(5001); + Addr.sin_addr.s_addr = sl_Htonl(SL_IPV4_VAL(10,1,1,200)); + + SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0); + Status = sl_Bind(SockID, (SlSockAddr_t *)&LocalAddr, AddrSize); + Status = sl_Listen(SockID, 0); + newSockID = sl_Accept(SockID, (SlSockAddr_t*)&Addr, (SlSocklen_t*) &AddrSize); + Status = sl_Recv(newSockID, Buf, 1460, 0); + \endcode + \code Example code for Rx transceiver mode using a raw socket + _i8 buffer[1536]; + _i16 sd; + _u16 size; + SlTransceiverRxOverHead_t *transHeader; + sd = sl_Socket(SL_AF_RF,SL_SOCK_RAW,11); // channel 11 + while(1) + { + size = sl_Recv(sd,buffer,1536,0); + transHeader = (SlTransceiverRxOverHead_t *)buffer; + printf("RSSI is %d frame type is 0x%x size %d\n",transHeader->rssi,buffer[sizeof(SlTransceiverRxOverHead_t)],size); + } + \endcode +*/ +#if _SL_INCLUDE_FUNC(sl_Recv) +_i16 sl_Recv(_i16 sd, void *buf, _i16 Len, _i16 flags); +#endif + +/*! + \brief read data from socket + + function receives a message from a connection-mode or + connectionless-mode socket + + \param[in] sd socket handle + \param[out] buf Points to the buffer where the message should be stored. + \param[in] Len Specifies the length in bytes of the buffer pointed to by the buffer argument. + Range: 1-16000 bytes + \param[in] flags Specifies the type of message + reception. On this version, this parameter is not + supported. + \param[in] from pointer to an address structure + indicating the source + address.\n sockaddr:\n - code + for the address format. On this + version only AF_INET is + supported.\n - socket address, + the length depends on the code + format + \param[in] fromlen source address structure + size. This parameter MUST be set to the size of the structure pointed to by addr. + + + \return return the number of bytes received, + or a negative value if an error occurred. + using a non-blocking recv a possible negative value is SL_EAGAIN. + SL_RET_CODE_INVALID_INPUT (-2) will be returned if fromlen has incorrect length. + SL_POOL_IS_EMPTY may be return in case there are no resources in the system + In this case try again later or increase MAX_CONCURRENT_ACTIONS + + \sa sl_Recv + \note belongs to \ref recv_api + \warning + \par Example: + \code An example of receiving data: + + SlSockAddrIn_t Addr; + SlSockAddrIn_t LocalAddr; + _i16 AddrSize = sizeof(SlSockAddrIn_t); + _i16 SockID; + _i16 Status; + _i8 Buf[RECV_BUF_LEN]; + + LocalAddr.sin_family = SL_AF_INET; + LocalAddr.sin_port = sl_Htons(5001); + LocalAddr.sin_addr.s_addr = 0; + + SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0); + Status = sl_Bind(SockID, (SlSockAddr_t *)&LocalAddr, AddrSize); + Status = sl_RecvFrom(SockID, Buf, 1472, 0, (SlSockAddr_t *)&Addr, (SlSocklen_t*)&AddrSize); + + \endcode +*/ +#if _SL_INCLUDE_FUNC(sl_RecvFrom) +_i16 sl_RecvFrom(_i16 sd, void *buf, _i16 Len, _i16 flags, SlSockAddr_t *from, SlSocklen_t *fromlen); +#endif + +/*! + \brief write data to TCP socket + + This function is used to transmit a message to another socket. + Returns immediately after sending data to device. + In case of TCP failure an async event SL_SOCKET_TX_FAILED_EVENT is going to + be received. + In case of a RAW socket (transceiver mode), extra 4 bytes should be reserved at the end of the + frame data buffer for WLAN FCS + + \param[in] sd socket handle + \param[in] buf Points to a buffer containing + the message to be sent + \param[in] Len message size in bytes. Range: 1-1460 bytes + \param[in] flags Specifies the type of message + transmission. On this version, this parameter is not + supported for TCP. + For transceiver mode, the SL_RAW_RF_TX_PARAMS macro can be used to determine + transmission parameters (channel,rate,tx_power,preamble) + + + \return Return the number of bytes transmitted, + or -1 if an error occurred + + \sa sl_SendTo + \note belongs to \ref send_api + \warning + \par Example: + \code An example of sending data: + + SlSockAddrIn_t Addr; + _i16 AddrSize = sizeof(SlSockAddrIn_t); + _i16 SockID; + _i16 Status; + _i8 Buf[SEND_BUF_LEN]; + + Addr.sin_family = SL_AF_INET; + Addr.sin_port = sl_Htons(5001); + Addr.sin_addr.s_addr = sl_Htonl(SL_IPV4_VAL(10,1,1,200)); + + SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0); + Status = sl_Connect(SockID, (SlSockAddr_t *)&Addr, AddrSize); + Status = sl_Send(SockID, Buf, 1460, 0 ); + + \endcode + */ +#if _SL_INCLUDE_FUNC(sl_Send ) +_i16 sl_Send(_i16 sd, const void *buf, _i16 Len, _i16 flags); +#endif + +/*! + \brief write data to socket + + This function is used to transmit a message to another socket + (connection less socket SOCK_DGRAM, SOCK_RAW). + Returns immediately after sending data to device. + In case of transmission failure an async event SL_SOCKET_TX_FAILED_EVENT is going to + be received. + + \param[in] sd socket handle + \param[in] buf Points to a buffer containing + the message to be sent + \param[in] Len message size in bytes. Range: 1-1460 bytes + \param[in] flags Specifies the type of message + transmission. On this version, this parameter is not + supported + \param[in] to pointer to an address structure + indicating the destination + address.\n sockaddr:\n - code + for the address format. On this + version only AF_INET is + supported.\n - socket address, + the length depends on the code + format + \param[in] tolen destination address structure size + + \return Return the number of transmitted bytes, + or -1 if an error occurred + + \sa sl_Send + \note belongs to \ref send_api + \warning + \par Example: + \code An example of sending data: + + SlSockAddrIn_t Addr; + _i16 AddrSize = sizeof(SlSockAddrIn_t); + _i16 SockID; + _i16 Status; + _i8 Buf[SEND_BUF_LEN]; + + Addr.sin_family = SL_AF_INET; + Addr.sin_port = sl_Htons(5001); + Addr.sin_addr.s_addr = sl_Htonl(SL_IPV4_VAL(10,1,1,200)); + + SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0); + Status = sl_SendTo(SockID, Buf, 1472, 0, (SlSockAddr_t *)&Addr, AddrSize); + + \endcode +*/ +#if _SL_INCLUDE_FUNC(sl_SendTo) +_i16 sl_SendTo(_i16 sd, const void *buf, _i16 Len, _i16 flags, const SlSockAddr_t *to, SlSocklen_t tolen); +#endif + +/*! + \brief Reorder the bytes of a 32-bit unsigned value + + This function is used to Reorder the bytes of a 32-bit unsigned value from processor order to network order. + + \param[in] var variable to reorder + + \return Return the reorder variable, + + \sa sl_SendTo sl_Bind sl_Connect sl_RecvFrom sl_Accept + \note belongs to \ref send_api + \warning +*/ +#if _SL_INCLUDE_FUNC(sl_Htonl ) +_u32 sl_Htonl( _u32 val ); + +#define sl_Ntohl sl_Htonl /* Reorder the bytes of a 16-bit unsigned value from network order to processor orde. */ +#endif + +/*! + \brief Reorder the bytes of a 16-bit unsigned value + + This function is used to Reorder the bytes of a 16-bit unsigned value from processor order to network order. + + \param[in] var variable to reorder + + \return Return the reorder variable, + + \sa sl_SendTo sl_Bind sl_Connect sl_RecvFrom sl_Accept + \note belongs to \ref send_api + \warning +*/ +#if _SL_INCLUDE_FUNC(sl_Htons ) +_u16 sl_Htons( _u16 val ); + +#define sl_Ntohs sl_Htons /* Reorder the bytes of a 16-bit unsigned value from network order to processor orde. */ +#endif + +/*! + + Close the Doxygen group. + @} + + */ + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __SOCKET_H__ */ + + diff --git a/drivers/cc3100/inc/spawn.h b/drivers/cc3100/inc/spawn.h new file mode 100644 index 0000000000..82c112d2e1 --- /dev/null +++ b/drivers/cc3100/inc/spawn.h @@ -0,0 +1,63 @@ +/* + * spawn.h - CC31xx/CC32xx Host Driver Implementation + * + * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +*/ + +#ifndef __NONOS_H__ +#define __NONOS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + +#if (defined (SL_PLATFORM_MULTI_THREADED)) && (!defined (SL_PLATFORM_EXTERNAL_SPAWN)) + +extern void _SlInternalSpawnTaskEntry(); +extern _i16 _SlInternalSpawn(_SlSpawnEntryFunc_t pEntry , void* pValue , _u32 flags); + +#undef sl_Spawn +#define sl_Spawn(pEntry,pValue,flags) _SlInternalSpawn(pEntry,pValue,flags) + +#undef _SlTaskEntry +#define _SlTaskEntry _SlInternalSpawnTaskEntry + + +#endif + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif diff --git a/drivers/cc3100/inc/trace.h b/drivers/cc3100/inc/trace.h new file mode 100644 index 0000000000..9e5ac519c1 --- /dev/null +++ b/drivers/cc3100/inc/trace.h @@ -0,0 +1,202 @@ +/* + * trace.h - CC31xx/CC32xx Host Driver Implementation + * + * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +*/ + + + +#include "simplelink.h" +#include "debug.h" + +#ifndef __SIMPLELINK_TRACE_H__ +#define __SIMPLELINK_TRACE_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +/*****************************************************************************/ +/* Macro declarations */ +/*****************************************************************************/ + +#define SL_SYNC_SCAN_THRESHOLD (( _u32 )2000) + +#define _SL_ASSERT(expr) { ASSERT(expr); } +#define _SL_ERROR(expr, error) { if(!(expr)){return (error); } } + +#define SL_HANDLING_ASSERT 2 +#define SL_HANDLING_ERROR 1 +#define SL_HANDLING_NONE 0 + +#if defined(DEBUG) && !defined(BOOTLOADER) +#define SL_SELF_COND_HANDLING SL_HANDLING_ASSERT +#define SL_PROTOCOL_HANDLING SL_HANDLING_ASSERT +#define SL_DRV_RET_CODE_HANDLING SL_HANDLING_ASSERT +#define SL_NWP_IF_HANDLING SL_HANDLING_ASSERT +#define SL_OSI_RET_OK_HANDLING SL_HANDLING_ASSERT +#define SL_MALLOC_OK_HANDLING SL_HANDLING_ASSERT +#define SL_USER_ARGS_HANDLING SL_HANDLING_ASSERT +#else +#define SL_SELF_COND_HANDLING SL_HANDLING_NONE +#define SL_PROTOCOL_HANDLING SL_HANDLING_NONE +#define SL_DRV_RET_CODE_HANDLING SL_HANDLING_NONE +#define SL_NWP_IF_HANDLING SL_HANDLING_NONE +#define SL_OSI_RET_OK_HANDLING SL_HANDLING_NONE +#define SL_MALLOC_OK_HANDLING SL_HANDLING_NONE +#define SL_USER_ARGS_HANDLING SL_HANDLING_NONE +#endif + +#if (SL_DRV_RET_CODE_HANDLING == SL_HANDLING_ASSERT) +#define VERIFY_RET_OK(Func) {_SlReturnVal_t _RetVal = (Func); _SL_ASSERT((_SlReturnVal_t)SL_OS_RET_CODE_OK == _RetVal)} +#elif (SL_DRV_RET_CODE_HANDLING == SL_HANDLING_ERROR) +#define VERIFY_RET_OK(Func) {_SlReturnVal_t _RetVal = (Func); if (SL_OS_RET_CODE_OK != _RetVal) return _RetVal;} +#else +#define VERIFY_RET_OK(Func) (Func); +#endif + +#if (SL_PROTOCOL_HANDLING == SL_HANDLING_ASSERT) +#define VERIFY_PROTOCOL(expr) _SL_ASSERT(expr) +#elif (SL_PROTOCOL_HANDLING == SL_HANDLING_ERROR) +#define VERIFY_PROTOCOL(expr) _SL_ERROR(expr, SL_RET_CODE_PROTOCOL_ERROR) +#else +#define VERIFY_PROTOCOL(expr) +#endif + +#if (defined(PROTECT_SOCKET_ASYNC_RESP) && (SL_SELF_COND_HANDLING == SL_HANDLING_ASSERT)) +#define VERIFY_SOCKET_CB(expr) _SL_ASSERT(expr) +#elif (defined(PROTECT_SOCKET_ASYNC_RESP) && (SL_SELF_COND_HANDLING == SL_HANDLING_ERROR)) +#define VERIFY_SOCKET_CB(expr) _SL_ERROR(expr, SL_RET_CODE_SELF_ERROR) +#else +#define VERIFY_SOCKET_CB(expr) +#endif + +#if (SL_NWP_IF_HANDLING == SL_HANDLING_ASSERT) +#define NWP_IF_WRITE_CHECK(fd,pBuff,len) { _i16 RetSize, ExpSize = (len); RetSize = sl_IfWrite((fd),(pBuff),ExpSize); _SL_ASSERT(ExpSize == RetSize)} +#define NWP_IF_READ_CHECK(fd,pBuff,len) { _i16 RetSize, ExpSize = (len); RetSize = sl_IfRead((fd),(pBuff),ExpSize); _SL_ASSERT(ExpSize == RetSize)} +#elif (SL_NWP_IF_HANDLING == SL_HANDLING_ERROR) +#define NWP_IF_WRITE_CHECK(fd,pBuff,len) { _SL_ERROR((len == sl_IfWrite((fd),(pBuff),(len))), SL_RET_CODE_NWP_IF_ERROR);} +#define NWP_IF_READ_CHECK(fd,pBuff,len) { _SL_ERROR((len == sl_IfRead((fd),(pBuff),(len))), SL_RET_CODE_NWP_IF_ERROR);} +#else +#define NWP_IF_WRITE_CHECK(fd,pBuff,len) { sl_IfWrite((fd),(pBuff),(len));} +#define NWP_IF_READ_CHECK(fd,pBuff,len) { sl_IfRead((fd),(pBuff),(len));} +#endif + +#if (SL_OSI_RET_OK_HANDLING == SL_HANDLING_ASSERT) +#define OSI_RET_OK_CHECK(Func) {_SlReturnVal_t _RetVal = (Func); _SL_ASSERT((_SlReturnVal_t)SL_OS_RET_CODE_OK == _RetVal)} +#elif (SL_OSI_RET_OK_HANDLING == SL_HANDLING_ERROR) +#define OSI_RET_OK_CHECK(Func) {_SlReturnVal_t _RetVal = (Func); if (SL_OS_RET_CODE_OK != _RetVal) return _RetVal;} +#else +#define OSI_RET_OK_CHECK(Func) (Func); +#endif + +#if (SL_MALLOC_OK_HANDLING == SL_HANDLING_ASSERT) +#define MALLOC_OK_CHECK(Ptr) _SL_ASSERT(NULL != Ptr) +#elif (SL_MALLOC_OK_HANDLING == SL_HANDLING_ERROR) +#define MALLOC_OK_CHECK(Ptr) _SL_ERROR((NULL != Ptr), SL_RET_CODE_MALLOC_ERROR) +#else +#define MALLOC_OK_CHECK(Ptr) +#endif + +#ifdef SL_INC_ARG_CHECK + +#if (SL_USER_ARGS_HANDLING == SL_HANDLING_ASSERT) +#define ARG_CHECK_PTR(Ptr) _SL_ASSERT(NULL != Ptr) +#elif (SL_USER_ARGS_HANDLING == SL_HANDLING_ERROR) +#define ARG_CHECK_PTR(Ptr) _SL_ERROR((NULL != Ptr), SL_RET_CODE_INVALID_INPUT) +#else +#define ARG_CHECK_PTR(Ptr) +#endif + +#else +#define ARG_CHECK_PTR(Ptr) +#endif + +#if defined(DEBUG) && !defined(BOOTLOADER) +#include "std.h" +#define SL_DBG_TRACE_ENABLE +#endif +#ifdef SL_DBG_TRACE_ENABLE +#define SL_TRACE0(level,msg_id,str) +#define SL_TRACE1(level,msg_id,str,p1) +#define SL_TRACE2(level,msg_id,str,p1,p2) +#define SL_TRACE3(level,msg_id,str,p1,p2,p3) +#define SL_TRACE4(level,msg_id,str,p1,p2,p3,p4) +#define SL_ERROR_TRACE(msg_id,str) printf(str) +#define SL_ERROR_TRACE1(msg_id,str,p1) printf(str,(p1)) +#define SL_ERROR_TRACE2(msg_id,str,p1,p2) printf(str,(p1),(p2)) +#define SL_ERROR_TRACE3(msg_id,str,p1,p2,p3) printf(str,(p1),(p2),(p3)) +#define SL_ERROR_TRACE4(msg_id,str,p1,p2,p3,p4) printf(str,(p1),(p2),(p3),(p4)) +#define SL_TRACE_FLUSH() +#else +#define SL_TRACE0(level,msg_id,str) +#define SL_TRACE1(level,msg_id,str,p1) +#define SL_TRACE2(level,msg_id,str,p1,p2) +#define SL_TRACE3(level,msg_id,str,p1,p2,p3) +#define SL_TRACE4(level,msg_id,str,p1,p2,p3,p4) +#define SL_ERROR_TRACE(msg_id,str) +#define SL_ERROR_TRACE1(msg_id,str,p1) +#define SL_ERROR_TRACE2(msg_id,str,p1,p2) +#define SL_ERROR_TRACE3(msg_id,str,p1,p2,p3) +#define SL_ERROR_TRACE4(msg_id,str,p1,p2,p3,p4) +#define SL_TRACE_FLUSH() +#endif + +/* #define SL_DBG_CNT_ENABLE */ +#ifdef SL_DBG_CNT_ENABLE +#define _SL_DBG_CNT_INC(Cnt) g_DbgCnt. ## Cnt++ +#define _SL_DBG_SYNC_LOG(index,value) {if(index < SL_DBG_SYNC_LOG_SIZE){*(_u32 *)&g_DbgCnt.SyncLog[index] = *(_u32 *)(value);}} + +#else +#define _SL_DBG_CNT_INC(Cnt) +#define _SL_DBG_SYNC_LOG(index,value) +#endif + +#define SL_DBG_LEVEL_1 1 +#define SL_DBG_LEVEL_2 2 +#define SL_DBG_LEVEL_3 4 +#define SL_DBG_LEVEL_MASK (SL_DBG_LEVEL_2|SL_DBG_LEVEL_3) + +#define SL_INCLUDE_DBG_FUNC(Name) ((Name ## _DBG_LEVEL) & SL_DBG_LEVEL_MASK) + +#define _SlDrvPrintStat_DBG_LEVEL SL_DBG_LEVEL_3 +#define _SlDrvOtherFunc_DBG_LEVEL SL_DBG_LEVEL_1 + +#ifdef __cplusplus +} +#endif + + +#endif /*__SIMPLELINK_TRACE_H__*/ + diff --git a/drivers/cc3100/inc/wlan.h b/drivers/cc3100/inc/wlan.h new file mode 100644 index 0000000000..a0c73d1926 --- /dev/null +++ b/drivers/cc3100/inc/wlan.h @@ -0,0 +1,1320 @@ +/* + * wlan.h - CC31xx/CC32xx Host Driver Implementation + * + * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +*/ + +#ifndef __WLAN_H__ +#define __WLAN_H__ + +/*****************************************************************************/ +/* Include files */ +/*****************************************************************************/ +#include "simplelink.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/*****************************************************************************/ +/* Macro declarations */ +/*****************************************************************************/ + +/*! + + \addtogroup wlan + @{ + +*/ + +#define SL_BSSID_LENGTH (6) +#define MAXIMAL_SSID_LENGTH (32) + +#define NUM_OF_RATE_INDEXES (20) +#define SIZE_OF_RSSI_HISTOGRAM (6) + +/* WLAN Disconnect Reason Codes */ +#define SL_DISCONNECT_RESERVED_0 (0) +#define SL_DISCONNECT_UNSPECIFIED_REASON (1) +#define SL_PREVIOUS_AUTHENTICATION_NO_LONGER_VALID (2) +#define SL_DEAUTHENTICATED_BECAUSE_SENDING_STATION_IS_LEAVING (3) +#define SL_DISASSOCIATED_DUE_TO_INACTIVITY (4) +#define SL_DISASSOCIATED_BECAUSE_AP_IS_UNABLE_TO_HANDLE_ALL_CURRENTLY_ASSOCIATED_STATIONS (5) +#define SL_CLASS_2_FRAME_RECEIVED_FROM_NONAUTHENTICATED_STATION (6) +#define SL_CLASS_3_FRAME_RECEIVED_FROM_NONASSOCIATED_STATION (7) +#define SL_DISASSOCIATED_BECAUSE_SENDING_STATION_IS_LEAVING_BSS (8) +#define SL_STATION_REQUESTING_ASSOCIATION_IS_NOT_AUTHENTICATED_WITH_RESPONDING_STATION (9) +#define SL_DISASSOCIATED_BECAUSE_THE_INFORMATION_IN_THE_POWER_CAPABILITY_ELEMENT_IS_UNACCEPTABLE (10) +#define SL_DISASSOCIATED_BECAUSE_THE_INFORMATION_IN_THE_SUPPORTED_CHANNELS_ELEMENT_IS_UNACCEPTABLE (11) +#define SL_DISCONNECT_RESERVED_1 (12) +#define SL_INVALID_INFORMATION_ELEMENT (13) +#define SL_MESSAGE_INTEGRITY_CODE_MIC_FAILURE (14) +#define SL_FOUR_WAY_HANDSHAKE_TIMEOUT (15) +#define SL_GROUP_KEY_HANDSHAKE_TIMEOUT (16) +#define SL_RE_ASSOCIATION_REQUEST_PROBE_RESPONSE_BEACON_FRAME (17) +#define SL_INVALID_GROUP_CIPHER (18) +#define SL_INVALID_PAIRWISE_CIPHER (19) +#define SL_INVALID_AKMP (20) +#define SL_UNSUPPORTED_RSN_INFORMATION_ELEMENT_VERSION (21) +#define SL_INVALID_RSN_INFORMATION_ELEMENT_CAPABILITIES (22) +#define SL_IEEE_802_1X_AUTHENTICATION_FAILED (23) +#define SL_CIPHER_SUITE_REJECTED_BECAUSE_OF_THE_SECURITY_POLICY (24) +#define SL_DISCONNECT_RESERVED_2 (25) +#define SL_DISCONNECT_RESERVED_3 (26) +#define SL_DISCONNECT_RESERVED_4 (27) +#define SL_DISCONNECT_RESERVED_5 (28) +#define SL_DISCONNECT_RESERVED_6 (29) +#define SL_DISCONNECT_RESERVED_7 (30) +#define SL_DISCONNECT_RESERVED_8 (31) +#define SL_DISASSOCIATED_FOR_UNSPECIFIED_QOS_RELATED_REASON (32) +#define SL_DISASSOCIATED_BECAUSE_QAP_LACKS_SUFFICIENT_BANDWIDTH_FOR_THIS_QSTA (33) +#define SL_DISASSOCIATED_BECAUSE_EXCESSIVE_NUMBER_OF_FRAMES_NEED_TO_BE_ACKNOWLEDGED (34) +#define SL_DISASSOCIATED_BECAUSE_QSTA_IS_TRANSMITTING_OUTSIDE_THE_LIMITS_OF_ITS_TXOPS (35) +#define SL_REQUESTED_FROM_PEER_QSTA_AS_THE_QSTA_IS_LEAVING_THE_QBSS (36) +#define SL_REQUESTED_FROM_PEER_QSTA_AS_IT_DOES_NO_WANT_TO_USE_THE_MECHANISM (37) +#define SL_REQUESTED_FROM_PEER_QSTA_AS_THE_QSTA_RECEIVED_FRAMES_SETUP_IS_REQUIRED (38) +#define SL_REQUESTED_FROM_PEER_QSTA_DUE_TO_TIMEOUT (39) +#define SL_PEER_QSTA_DOES_NOT_SUPPORT_THE_REQUESTED_CIPHER_SUITE (40) +#define SL_CISCO_DEFINED (98) +#define SL_CISCO_DEFINED_1 (99) +#define SL_ROAMING_TRIGGER_NONE (100) +#define SL_ROAMING_TRIGGER_LOW_QUALITY_FOR_BG_SCAN (101) +#define SL_ROAMING_TRIGGER_HIGH_QUALITY_FOR_BG_SCAN (102) +#define SL_ROAMING_TRIGGER_NORMAL_QUALITY_FOR_BG_SCAN (103) +#define SL_ROAMING_TRIGGER_LOW_TX_RATE (104) +#define SL_ROAMING_TRIGGER_LOW_SNR (105) +#define SL_ROAMING_TRIGGER_LOW_QUALITY (106) +#define SL_ROAMING_TRIGGER_TSPEC_REJECTED (107) +#define SL_ROAMING_TRIGGER_MAX_TX_RETRIES (108) +#define SL_ROAMING_TRIGGER_BSS_LOSS (109) +#define SL_ROAMING_TRIGGER_BSS_LOSS_DUE_TO_MAX_TX_RETRY (110) +#define SL_ROAMING_TRIGGER_SWITCH_CHANNEL (111) +#define SL_ROAMING_TRIGGER_AP_DISCONNECT (112) +#define SL_ROAMING_TRIGGER_SECURITY_ATTACK (113) +#define SL_ROAMING_TRIGGER_MAX (114) +#define SL_USER_INITIATED_DISCONNECTION (200) + +/* Wlan error codes */ +#define SL_ERROR_KEY_ERROR (-3) +#define SL_ERROR_INVALID_ROLE (-71) +#define SL_ERROR_INVALID_SECURITY_TYPE (-84) +#define SL_ERROR_PASSPHRASE_TOO_LONG (-85) +#define SL_ERROR_WPS_NO_PIN_OR_WRONG_PIN_LEN (-87) +#define SL_ERROR_EAP_WRONG_METHOD (-88) +#define SL_ERROR_PASSWORD_ERROR (-89) +#define SL_ERROR_EAP_ANONYMOUS_LEN_ERROR (-90) +#define SL_ERROR_SSID_LEN_ERROR (-91) +#define SL_ERROR_USER_ID_LEN_ERROR (-92) +#define SL_ERROR_ILLEGAL_WEP_KEY_INDEX (-95) +#define SL_ERROR_INVALID_DWELL_TIME_VALUES (-96) +#define SL_ERROR_INVALID_POLICY_TYPE (-97) +#define SL_ERROR_PM_POLICY_INVALID_OPTION (-98) +#define SL_ERROR_PM_POLICY_INVALID_PARAMS (-99) +#define SL_ERROR_WIFI_ALREADY_DISCONNECTED (-129) +#define SL_ERROR_WIFI_NOT_CONNECTED (-59) + + + +#define SL_SEC_TYPE_OPEN (0) +#define SL_SEC_TYPE_WEP (1) +#define SL_SEC_TYPE_WPA (2) /* deprecated */ +#define SL_SEC_TYPE_WPA_WPA2 (2) +#define SL_SEC_TYPE_WPS_PBC (3) +#define SL_SEC_TYPE_WPS_PIN (4) +#define SL_SEC_TYPE_WPA_ENT (5) +#define SL_SEC_TYPE_P2P_PBC (6) +#define SL_SEC_TYPE_P2P_PIN_KEYPAD (7) +#define SL_SEC_TYPE_P2P_PIN_DISPLAY (8) +#define SL_SEC_TYPE_P2P_PIN_AUTO (9) /* NOT Supported yet */ + + + +#define SL_SCAN_SEC_TYPE_OPEN (0) +#define SL_SCAN_SEC_TYPE_WEP (1) +#define SL_SCAN_SEC_TYPE_WPA (2) +#define SL_SCAN_SEC_TYPE_WPA2 (3) + + + +#define TLS (0x1) +#define MSCHAP (0x0) +#define PSK (0x2) +#define TTLS (0x10) +#define PEAP0 (0x20) +#define PEAP1 (0x40) +#define FAST (0x80) + +#define FAST_AUTH_PROVISIONING (0x02) +#define FAST_UNAUTH_PROVISIONING (0x01) +#define FAST_NO_PROVISIONING (0x00) + +#define EAPMETHOD_PHASE2_SHIFT (8) +#define EAPMETHOD_PAIRWISE_CIPHER_SHIFT (19) +#define EAPMETHOD_GROUP_CIPHER_SHIFT (27) + +#define WPA_CIPHER_CCMP (0x1) +#define WPA_CIPHER_TKIP (0x2) +#define CC31XX_DEFAULT_CIPHER (WPA_CIPHER_CCMP | WPA_CIPHER_TKIP) + +#define EAPMETHOD(phase1,phase2,pairwise_cipher,group_cipher) \ +((phase1) | \ + ((phase2) << EAPMETHOD_PHASE2_SHIFT ) |\ + ((_u32)(pairwise_cipher) << EAPMETHOD_PAIRWISE_CIPHER_SHIFT ) |\ + ((_u32)(group_cipher) << EAPMETHOD_GROUP_CIPHER_SHIFT )) + +/* phase1 phase2 pairwise_cipher group_cipher */ +#define SL_ENT_EAP_METHOD_TLS EAPMETHOD(TLS , 0 , CC31XX_DEFAULT_CIPHER , CC31XX_DEFAULT_CIPHER) +#define SL_ENT_EAP_METHOD_TTLS_TLS EAPMETHOD(TTLS , TLS , CC31XX_DEFAULT_CIPHER , CC31XX_DEFAULT_CIPHER) +#define SL_ENT_EAP_METHOD_TTLS_MSCHAPv2 EAPMETHOD(TTLS , MSCHAP , CC31XX_DEFAULT_CIPHER , CC31XX_DEFAULT_CIPHER) +#define SL_ENT_EAP_METHOD_TTLS_PSK EAPMETHOD(TTLS , PSK , CC31XX_DEFAULT_CIPHER , CC31XX_DEFAULT_CIPHER) +#define SL_ENT_EAP_METHOD_PEAP0_TLS EAPMETHOD(PEAP0 , TLS , CC31XX_DEFAULT_CIPHER , CC31XX_DEFAULT_CIPHER) +#define SL_ENT_EAP_METHOD_PEAP0_MSCHAPv2 EAPMETHOD(PEAP0 , MSCHAP , CC31XX_DEFAULT_CIPHER , CC31XX_DEFAULT_CIPHER) +#define SL_ENT_EAP_METHOD_PEAP0_PSK EAPMETHOD(PEAP0 , PSK , CC31XX_DEFAULT_CIPHER , CC31XX_DEFAULT_CIPHER) +#define SL_ENT_EAP_METHOD_PEAP1_TLS EAPMETHOD(PEAP1 , TLS , CC31XX_DEFAULT_CIPHER , CC31XX_DEFAULT_CIPHER) +#define SL_ENT_EAP_METHOD_PEAP1_MSCHAPv2 EAPMETHOD(PEAP1 , MSCHAP , CC31XX_DEFAULT_CIPHER , CC31XX_DEFAULT_CIPHER) +#define SL_ENT_EAP_METHOD_PEAP1_PSK EAPMETHOD(PEAP1 , PSK , CC31XX_DEFAULT_CIPHER , CC31XX_DEFAULT_CIPHER) +#define SL_ENT_EAP_METHOD_FAST_AUTH_PROVISIONING EAPMETHOD(FAST , FAST_AUTH_PROVISIONING , CC31XX_DEFAULT_CIPHER , CC31XX_DEFAULT_CIPHER) +#define SL_ENT_EAP_METHOD_FAST_UNAUTH_PROVISIONING EAPMETHOD(FAST , FAST_UNAUTH_PROVISIONING , CC31XX_DEFAULT_CIPHER , CC31XX_DEFAULT_CIPHER) +#define SL_ENT_EAP_METHOD_FAST_NO_PROVISIONING EAPMETHOD(FAST , FAST_NO_PROVISIONING , CC31XX_DEFAULT_CIPHER , CC31XX_DEFAULT_CIPHER) + +#define SL_LONG_PREAMBLE (0) +#define SL_SHORT_PREAMBLE (1) + +#define SL_RAW_RF_TX_PARAMS_CHANNEL_SHIFT (0) +#define SL_RAW_RF_TX_PARAMS_RATE_SHIFT (6) +#define SL_RAW_RF_TX_PARAMS_POWER_SHIFT (11) +#define SL_RAW_RF_TX_PARAMS_PREAMBLE_SHIFT (15) + +#define SL_RAW_RF_TX_PARAMS(chan,rate,power,preamble) \ + ((chan << SL_RAW_RF_TX_PARAMS_CHANNEL_SHIFT) | \ + (rate << SL_RAW_RF_TX_PARAMS_RATE_SHIFT) | \ + (power << SL_RAW_RF_TX_PARAMS_POWER_SHIFT) | \ + (preamble << SL_RAW_RF_TX_PARAMS_PREAMBLE_SHIFT)) + + +/* wlan config application IDs */ +#define SL_WLAN_CFG_AP_ID (0) +#define SL_WLAN_CFG_GENERAL_PARAM_ID (1) +#define SL_WLAN_CFG_P2P_PARAM_ID (2) + +/* wlan AP Config set/get options */ +#define WLAN_AP_OPT_SSID (0) +#define WLAN_AP_OPT_CHANNEL (3) +#define WLAN_AP_OPT_HIDDEN_SSID (4) +#define WLAN_AP_OPT_SECURITY_TYPE (6) +#define WLAN_AP_OPT_PASSWORD (7) +#define WLAN_GENERAL_PARAM_OPT_COUNTRY_CODE (9) +#define WLAN_GENERAL_PARAM_OPT_STA_TX_POWER (10) +#define WLAN_GENERAL_PARAM_OPT_AP_TX_POWER (11) + +#define WLAN_P2P_OPT_DEV_NAME (12) +#define WLAN_P2P_OPT_DEV_TYPE (13) +#define WLAN_P2P_OPT_CHANNEL_N_REGS (14) +#define WLAN_GENERAL_PARAM_OPT_INFO_ELEMENT (16) +#define WLAN_GENERAL_PARAM_OPT_SCAN_PARAMS (18) /* change the scan channels and RSSI threshold using this configuration option */ + +/* SmartConfig CIPHER options */ +#define SMART_CONFIG_CIPHER_SFLASH (0) /* password is not delivered by the application. The Simple Manager should */ + /* check if the keys are stored in the Flash. */ +#define SMART_CONFIG_CIPHER_AES (1) /* AES (other types are not supported) */ +#define SMART_CONFIG_CIPHER_NONE (0xFF) /* do not check in the flash */ + + +#define SL_POLICY_CONNECTION (0x10) +#define SL_POLICY_SCAN (0x20) +#define SL_POLICY_PM (0x30) +#define SL_POLICY_P2P (0x40) + +#define VAL_2_MASK(position,value) ((1 & (value))<<(position)) +#define MASK_2_VAL(position,mask) (((1 << position) & (mask)) >> (position)) + +#define SL_CONNECTION_POLICY(Auto,Fast,Open,anyP2P,autoSmartConfig) (VAL_2_MASK(0,Auto) | VAL_2_MASK(1,Fast) | VAL_2_MASK(2,Open) | VAL_2_MASK(3,anyP2P) | VAL_2_MASK(4,autoSmartConfig)) +#define SL_SCAN_POLICY_EN(policy) (MASK_2_VAL(0,policy)) +#define SL_SCAN_POLICY(Enable) (VAL_2_MASK(0,Enable)) + + +#define SL_NORMAL_POLICY (0) +#define SL_LOW_LATENCY_POLICY (1) +#define SL_LOW_POWER_POLICY (2) +#define SL_ALWAYS_ON_POLICY (3) +#define SL_LONG_SLEEP_INTERVAL_POLICY (4) + +#define SL_P2P_ROLE_NEGOTIATE (3) +#define SL_P2P_ROLE_GROUP_OWNER (15) +#define SL_P2P_ROLE_CLIENT (0) + +#define SL_P2P_NEG_INITIATOR_ACTIVE (0) +#define SL_P2P_NEG_INITIATOR_PASSIVE (1) +#define SL_P2P_NEG_INITIATOR_RAND_BACKOFF (2) + +#define POLICY_VAL_2_OPTIONS(position,mask,policy) ((mask & policy) << position ) + +#define SL_P2P_POLICY(p2pNegType,p2pNegInitiator) (POLICY_VAL_2_OPTIONS(0,0xF,(p2pNegType > SL_P2P_ROLE_GROUP_OWNER ? SL_P2P_ROLE_GROUP_OWNER : p2pNegType)) | \ + POLICY_VAL_2_OPTIONS(4,0x1,(p2pNegType > SL_P2P_ROLE_GROUP_OWNER ? 1:0)) | \ + POLICY_VAL_2_OPTIONS(5,0x3, p2pNegInitiator)) + + +/* Info elements */ + +#define INFO_ELEMENT_DEFAULT_ID (0) /* 221 will be used */ + +/* info element size is up to 252 bytes (+ 3 bytes of OUI). */ +#define INFO_ELEMENT_MAX_SIZE (252) + +/* For AP - the total length of all info elements is 300 bytes (for example - 4 info elements of 75 bytes each) */ +#define INFO_ELEMENT_MAX_TOTAL_LENGTH_AP (300) +/* For P2P - the total length of all info elements is 150 bytes (for example - 4 info elements of 40 bytes each) */ +#define INFO_ELEMENT_MAX_TOTAL_LENGTH_P2P_GO (160) + +#define INFO_ELEMENT_AP_ROLE (0) +#define INFO_ELEMENT_P2P_GO_ROLE (1) + +/* we support up to 4 info elements per Role. */ +#define MAX_PRIVATE_INFO_ELEMENTS_SUPPROTED (4) + +#define INFO_ELEMENT_DEFAULT_OUI_0 (0x08) +#define INFO_ELEMENT_DEFAULT_OUI_1 (0x00) +#define INFO_ELEMENT_DEFAULT_OUI_2 (0x28) + +#define INFO_ELEMENT_DEFAULT_OUI (0x000000) /* 08, 00, 28 will be used */ + +/*****************************************************************************/ +/* Structure/Enum declarations */ +/*****************************************************************************/ + +typedef enum +{ + RATE_1M = 1, + RATE_2M = 2, + RATE_5_5M = 3, + RATE_11M = 4, + RATE_6M = 6, + RATE_9M = 7, + RATE_12M = 8, + RATE_18M = 9, + RATE_24M = 10, + RATE_36M = 11, + RATE_48M = 12, + RATE_54M = 13, + RATE_MCS_0 = 14, + RATE_MCS_1 = 15, + RATE_MCS_2 = 16, + RATE_MCS_3 = 17, + RATE_MCS_4 = 18, + RATE_MCS_5 = 19, + RATE_MCS_6 = 20, + RATE_MCS_7 = 21, + MAX_NUM_RATES = 0xFF +}SlRateIndex_e; + +typedef enum { + DEV_PW_DEFAULT=0, + DEV_PW_PIN_KEYPAD=1, + DEV_PW_PUSH_BUTTON=4, + DEV_PW_PIN_DISPLAY=5 +} sl_p2p_dev_password_method; + + +typedef struct +{ + _u32 status; + _u32 ssid_len; + _u8 ssid[32]; + _u32 private_token_len; + _u8 private_token[32]; +}slSmartConfigStartAsyncResponse_t; + +typedef struct +{ + _u16 status; + _u16 padding; +}slSmartConfigStopAsyncResponse_t; + +typedef struct +{ + _u16 status; + _u16 padding; +}slWlanConnFailureAsyncResponse_t; + +typedef struct +{ + _u8 connection_type;/* 0-STA,3-P2P_CL */ + _u8 ssid_len; + _u8 ssid_name[32]; + _u8 go_peer_device_name_len; + _u8 go_peer_device_name[32]; + _u8 bssid[6]; + _u8 reason_code; + _u8 padding[2]; +} slWlanConnectAsyncResponse_t; + +typedef struct +{ + _u8 go_peer_device_name[32]; + _u8 mac[6]; + _u8 go_peer_device_name_len; + _u8 wps_dev_password_id; + _u8 own_ssid[32];/* relevant for event sta-connected only */ + _u8 own_ssid_len;/* relevant for event sta-connected only */ + _u8 padding[3]; +}slPeerInfoAsyncResponse_t; + + +typedef union +{ + slSmartConfigStartAsyncResponse_t smartConfigStartResponse; /*SL_WLAN_SMART_CONFIG_COMPLETE_EVENT*/ + slSmartConfigStopAsyncResponse_t smartConfigStopResponse; /*SL_WLAN_SMART_CONFIG_STOP_EVENT */ + slPeerInfoAsyncResponse_t APModeStaConnected; /* SL_WLAN_STA_CONNECTED_EVENT - relevant only in AP mode - holds information regarding a new STA connection */ + slPeerInfoAsyncResponse_t APModestaDisconnected; /* SL_WLAN_STA_DISCONNECTED_EVENT - relevant only in AP mode - holds information regarding a STA disconnection */ + slWlanConnectAsyncResponse_t STAandP2PModeWlanConnected; /* SL_WLAN_CONNECT_EVENT - relevant only in STA and P2P mode - holds information regarding a new connection */ + slWlanConnectAsyncResponse_t STAandP2PModeDisconnected; /* SL_WLAN_DISCONNECT_EVENT - relevant only in STA and P2P mode - holds information regarding a disconnection */ + slPeerInfoAsyncResponse_t P2PModeDevFound; /* SL_WLAN_P2P_DEV_FOUND_EVENT - relevant only in P2P mode */ + slPeerInfoAsyncResponse_t P2PModeNegReqReceived; /* SL_WLAN_P2P_NEG_REQ_RECEIVED_EVENT - relevant only in P2P mode */ + slWlanConnFailureAsyncResponse_t P2PModewlanConnectionFailure; /* SL_WLAN_CONNECTION_FAILED_EVENT - relevant only in P2P mode */ + +} SlWlanEventData_u; + +typedef struct +{ + _u32 Event; + SlWlanEventData_u EventData; +} SlWlanEvent_t; + + +typedef struct +{ + _u32 ReceivedValidPacketsNumber; /* sum of the packets that been received OK (include filtered) */ + _u32 ReceivedFcsErrorPacketsNumber; /* sum of the packets that been dropped due to FCS error */ + _u32 ReceivedPlcpErrorPacketsNumber; /* sum of the packets that been dropped due to PLCP error */ + _i16 AvarageDataCtrlRssi; /* average RSSI for all valid data packets received */ + _i16 AvarageMgMntRssi; /* average RSSI for all valid management packets received */ + _u16 RateHistogram[NUM_OF_RATE_INDEXES]; /* rate histogram for all valid packets received */ + _u16 RssiHistogram[SIZE_OF_RSSI_HISTOGRAM]; /* RSSI histogram from -40 until -87 (all below and above\n RSSI will appear in the first and last cells */ + _u32 StartTimeStamp; /* the time stamp started collecting the statistics in uSec */ + _u32 GetTimeStamp; /* the time stamp called the get statistics command */ +}SlGetRxStatResponse_t; + + +typedef struct +{ + _u8 ssid[MAXIMAL_SSID_LENGTH]; + _u8 ssid_len; + _u8 sec_type; + _u8 bssid[SL_BSSID_LENGTH]; + _i8 rssi; + _i8 reserved[3]; +}Sl_WlanNetworkEntry_t; + + +typedef struct +{ + _u8 Type; + _i8* Key; + _u8 KeyLen; +}SlSecParams_t; + +typedef struct +{ + _i8* User; + _u8 UserLen; + _i8* AnonUser; + _u8 AnonUserLen; + _u8 CertIndex; /* not supported */ + _u32 EapMethod; +}SlSecParamsExt_t; + +typedef struct +{ + _i8 User[32]; + _u8 UserLen; + _i8 AnonUser[32]; + _u8 AnonUserLen; + _u8 CertIndex; //not supported + _u32 EapMethod; +}SlGetSecParamsExt_t; + +typedef enum +{ + ROLE_STA = 0, + ROLE_AP = 2, + ROLE_P2P = 3, + ROLE_STA_ERR = -1, /* Failure to load MAC/PHY in STA role */ + ROLE_AP_ERR = -ROLE_AP, /* Failure to load MAC/PHY in AP role */ + ROLE_P2P_ERR = -ROLE_P2P /* Failure to load MAC/PHY in P2P role */ +}SlWlanMode_t; + +typedef struct +{ + _u32 G_Channels_mask; + _i32 rssiThershold; +}slWlanScanParamCommand_t; + + +typedef struct +{ + _u8 id; + _u8 oui[3]; + _u16 length; + _u8 data[252]; +} sl_protocol_InfoElement_t; + +typedef struct +{ + _u8 index; /* 0 - MAX_PRIVATE_INFO_ELEMENTS_SUPPROTED */ + _u8 role; /* bit0: AP = 0, GO = 1 */ + sl_protocol_InfoElement_t ie; +} sl_protocol_WlanSetInfoElement_t; + + +/*****************************************************************************/ +/* Function prototypes */ +/*****************************************************************************/ + + +/*! + \brief Connect to wlan network as a station + + \param[in] sec_type security types options: \n + - SL_SEC_TYPE_OPEN + - SL_SEC_TYPE_WEP + - SL_SEC_TYPE_WPA_WPA2 + - SL_SEC_TYPE_WPA_ENT + - SL_SEC_TYPE_WPS_PBC + - SL_SEC_TYPE_WPS_PIN + + \param[in] pName up to 32 bytes in case of STA the name is the SSID of the Access Point + \param[in] NameLen name length + \param[in] pMacAddr 6 bytes for MAC address + \param[in] pSecParams Security parameters (use NULL key for SL_SEC_TYPE_OPEN) + \param[in] pSecExtParams Enterprise parameters (set NULL in case Enterprise parameters is not in use) + + \return On success, zero is returned. On error, negative is returned + In case error number (-71) is returned, it indicates a connection was activated while the device it running in AP role + + \sa sl_WlanDisconnect + \note belongs to \ref ext_api + \warning In this version only single enterprise mode could be used + SL_SEC_TYPE_WPA is a deprecated definition, the new definition is SL_SEC_TYPE_WPA_WPA2 +*/ +#if _SL_INCLUDE_FUNC(sl_WlanConnect) +_i16 sl_WlanConnect(_i8* pName, _i16 NameLen, _u8 *pMacAddr, SlSecParams_t* pSecParams , SlSecParamsExt_t* pSecExtParams); +#endif + +/*! + \brief wlan disconnect + + Disconnect connection + + \return 0 disconnected done, other already disconnected + + \sa sl_WlanConnect + \note belongs to \ref ext_api + \warning +*/ +#if _SL_INCLUDE_FUNC(sl_WlanDisconnect) +_i16 sl_WlanDisconnect(void); +#endif + +/*! + \brief add profile + + When auto start is enabled, the device connects to a + station from the profiles table. Up to 7 profiles are + supported. If several profiles configured the device chose + the highest priority profile, within each priority group, + device will chose profile based on security policy, signal + strength, etc parameters. + + + \param[in] pName up to 32 bytes in case of STA the name is the + SSID of the Access Point + in case of P2P the name is the remote device name + \param[in] NameLen name length + \param[in] pMacAddr 6 bytes for MAC address + \param[in] pSecParams Security parameters - security type + (SL_SEC_TYPE_OPEN,SL_SEC_TYPE_WEP,SL_SEC_TYPE_WPA_WPA2, + SL_SEC_TYPE_P2P_PBC,SL_SEC_TYPE_P2P_PIN_KEYPAD,SL_SEC_TYPE_P2P_PIN_DISPLAY, SL_SEC_TYPE_WPA_ENT), key, and key length + in case of p2p security type pin the key refers to pin code + \param[in] pSecExtParams Enterprise parameters - identity, identity length, + Anonymous, Anonymous length, CertIndex (not supported, + certificates need to be placed in a specific file ID), + EapMethod.Use NULL in case Enterprise parameters is not in use + + \param[in] Priority profile priority. Lowest priority: 0 + \param[in] Options Not supported + + \return On success, profile stored index is returned. On error, negative value is returned + + \sa sl_WlanProfileGet , sl_WlanProfileDel + \note belongs to \ref ext_api + \warning Only one Enterprise profile is supported. + Please Note that in case of adding an existing profile (compared by pName,pMACAddr and security type) + the old profile will be deleted and the same index will be returned. + SL_SEC_TYPE_WPA is a deprecated definition, the new definition is SL_SEC_TYPE_WPA_WPA2 + +*/ +#if _SL_INCLUDE_FUNC(sl_WlanProfileAdd) +_i16 sl_WlanProfileAdd(_i8* pName, _i16 NameLen, _u8 *pMacAddr, SlSecParams_t* pSecParams , SlSecParamsExt_t* pSecExtParams, _u32 Priority, _u32 Options); +#endif + +/*! + \brief get profile + + read profile from the device + + \param[in] Index profile stored index, if index does not exists + error is return + \param[out] pName up to 32 bytes, in case of sta mode the name of the Access Point + in case of p2p mode the name of the Remote Device + \param[out] pNameLen name length + \param[out] pMacAddr 6 bytes for MAC address + \param[out] pSecParams security parameters - security type + (LAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or + WLAN_SEC_WPA2, WLAN_SEC_P2P_PBC, WLAN_SEC_P2P_PIN_KEYPAD or WLAN_SEC_P2P_DISPLAY), key and key length are not + in case of p2p security type pin the key refers to pin code + return due to security reasons. + \param[out] pSecExtParams enterprise parameters - identity, identity + length, Anonymous, Anonymous length + CertIndex (not supported), EapMethod. + \param[out] Priority profile priority + + \return On success, Profile security type is returned (0 or positive number). On error, -1 is + returned + + \sa sl_WlanProfileAdd , sl_WlanProfileDel + \note belongs to \ref ext_api + \warning +*/ +#if _SL_INCLUDE_FUNC(sl_WlanProfileGet) +_i16 sl_WlanProfileGet(_i16 Index,_i8* pName, _i16 *pNameLen, _u8 *pMacAddr, SlSecParams_t* pSecParams, SlGetSecParamsExt_t* pSecExtParams, _u32 *pPriority); +#endif + +/*! + \brief Delete WLAN profile + + Delete WLAN profile + + \param[in] index number of profile to delete.Possible values are 0 to 6. + Index value 255 will delete all saved profiles + + \return On success, zero is returned. On error, -1 is + returned + + \sa sl_WlanProfileAdd , sl_WlanProfileGet + \note belongs to \ref ext_api + \warning +*/ +#if _SL_INCLUDE_FUNC(sl_WlanProfileDel) +_i16 sl_WlanProfileDel(_i16 Index); +#endif + +/*! + \brief Set policy values + + \param[in] Type Type of policy to be modified. The Options are:\n + - SL_POLICY_CONNECTION + - SL_POLICY_SCAN + - SL_POLICY_PM + - SL_POLICY_P2P + \param[in] Policy The option value which depends on action type + \param[in] pVal An optional value pointer + \param[in] ValLen An optional value length, in bytes + \return On success, zero is returned. On error, -1 is + returned + \sa sl_WlanPolicyGet + \note belongs to \ref ext_api + \warning + \par + SL_POLICY_CONNECTION type defines three options available to connect the CC31xx device to the AP: \n + + - If Auto Connect is set, the CC31xx device tries to automatically reconnect to one of its stored profiles, each time the connection fails or the device is rebooted.\n + To set this option, use: \n + <b> sl_WlanPolicySet(SL_POLICY_CONNECTION,SL_CONNECTION_POLICY(1,0,0,0,0),NULL,0) </b> + - If Fast Connect is set, the CC31xx device tries to establish a fast connection to AP. \n + To set this option, use: \n + <b> sl_WlanPolicySet(SL_POLICY_CONNECTION,SL_CONNECTION_POLICY(0,1,0,0,0),NULL,0) </b> + - (relevant for P2P mode only) - If Any P2P is set, CC31xx/CC32xx device tries to automatically connect to the first P2P device available, \n + supporting push button only. To set this option, use: \n + <b> sl_WlanPolicySet(SL_POLICY_CONNECTION,SL_CONNECTION_POLICY(0,0,0,1,0),NULL,0) </b> + - For auto smart config upon restart (any command from Host will end this state) use: \n + <b> sl_WlanPolicySet(SL_POLICY_CONNECTION,SL_CONNECTION_POLICY(0,0,0,0,1),NULL,0) </b> \n + The options above could be combined to a single action, if more than one action is required. \n + \par + SL_POLICY_SCAN defines system scan time interval in case there is no connection. Default interval is 10 minutes. \n + After settings scan interval, an immediate scan is activated. The next scan will be based on the interval settings. \n + - For example, setting scan interval to 1 minute interval use: \n + _u32 intervalInSeconds = 60; \n + #define SL_SCAN_ENABLE 1 \n<b> + sl_WlanPolicySet(SL_POLICY_SCAN,SL_SCAN_ENABLE, (_u8 *)&intervalInSeconds,sizeof(intervalInSeconds)); </b>\n + + - For example, disable scan: \n + #define SL_SCAN_DISABLE 0 \n<b> + sl_WlanPolicySet(SL_POLICY_SCAN,SL_SCAN_DISABLE,0,0); </b>\n + \par + SL_POLICY_PM defines a power management policy for Station mode only: + - For setting normal power management (default) policy use: <b> sl_WlanPolicySet(SL_POLICY_PM , SL_NORMAL_POLICY, NULL,0) </b> + - For setting low latency power management policy use: <b> sl_WlanPolicySet(SL_POLICY_PM , SL_LOW_LATENCY_POLICY, NULL,0) </b> + - For setting low power management policy use: <b> sl_WlanPolicySet(SL_POLICY_PM , SL_LOW_POWER_POLICY, NULL,0) </b> + - For setting always on power management policy use: <b> sl_WlanPolicySet(SL_POLICY_PM , SL_ALWAYS_ON_POLICY, NULL,0) </b> + - For setting Long Sleep Interval policy use: \n + _u16 PolicyBuff[4] = {0,0,800,0}; // PolicyBuff[2] is max sleep time in mSec \n<b> + sl_WlanPolicySet(SL_POLICY_PM , SL_LONG_SLEEP_INTERVAL_POLICY, (_u8*)PolicyBuff,sizeof(PolicyBuff)); </b>\n + + SL_POLICY_P2P defines p2p negotiation policy parameters for P2P role: + - To set intent negotiation value, set on of the following: + SL_P2P_ROLE_NEGOTIATE - intent 3 + SL_P2P_ROLE_GROUP_OWNER - intent 15 + SL_P2P_ROLE_CLIENT - intent 0 + - To set negotiation initiator value (initiator policy of first negotiation action frame), set on of the following: + SL_P2P_NEG_INITIATOR_ACTIVE + SL_P2P_NEG_INITIATOR_PASSIVE + SL_P2P_NEG_INITIATOR_RAND_BACKOFF + For example: \n + <b>sl_WlanPolicySet(SL_POLICY_P2P, SL_P2P_POLICY(SL_P2P_ROLE_NEGOTIATE,SL_P2P_NEG_INITIATOR_RAND_BACKOFF),NULL,0) </b> + +*/ +#if _SL_INCLUDE_FUNC(sl_WlanPolicySet) +_i16 sl_WlanPolicySet(_u8 Type , const _u8 Policy, _u8 *pVal,_u8 ValLen); +#endif +/*! + \brief get policy values + + \param[in] Type SL_POLICY_CONNECTION, SL_POLICY_SCAN, SL_POLICY_PM,SL_POLICY_P2P \n + + \param[in] Policy argument may be set to any value \n + + \param[out] The returned values, depends on each policy type, will be stored in the allocated buffer pointed by pVal + with a maximum buffer length set by the calling function and pointed to by argument *pValLen + + \return On success, zero is returned. On error, -1 is returned + + \sa sl_WlanPolicySet + + \note belongs to \ref ext_api + + \warning The value pointed by the argument *pValLen should be set to a value different from 0 and + greater than the buffer length returned from the SL device. Otherwise, an error will be returned. + +*/ +#if _SL_INCLUDE_FUNC(sl_WlanPolicyGet) +_i16 sl_WlanPolicyGet(_u8 Type , _u8 Policy,_u8 *pVal,_u8 *pValLen); +#endif +/*! + \brief Gets the WLAN scan operation results + + Gets scan results , gets entry from scan result table + + \param[in] Index - Starting index identifier (range 0-19) for getting scan results + \param[in] Count - How many entries to fetch. Max is (20-"Index"). + \param[out] pEntries - pointer to an allocated Sl_WlanNetworkEntry_t. + the number of array items should match "Count" + sec_type: SL_SCAN_SEC_TYPE_OPEN, SL_SCAN_SEC_TYPE_WEP, SL_SCAN_SEC_TYPE_WPA or SL_SCAN_SEC_TYPE_WPA2 + + + \return Number of valid networks list items + + \sa + \note belongs to \ref ext_api + \warning This command do not initiate any active scanning action + \par Example: + \code An example of fetching max 10 results: + + Sl_WlanNetworkEntry_t netEntries[10]; + _i16 resultsCount = sl_WlanGetNetworkList(0,10,&netEntries[0]); + for(i=0; i< resultsCount; i++) + { + printf("%s\n",netEntries[i].ssid); + } + \endcode +*/ +#if _SL_INCLUDE_FUNC(sl_WlanGetNetworkList) +_i16 sl_WlanGetNetworkList(_u8 Index, _u8 Count, Sl_WlanNetworkEntry_t *pEntries); +#endif + +/*! + \brief Start collecting wlan RX statistics, for unlimited time. + + \return On success, zero is returned. On error, -1 is returned + + \sa sl_WlanRxStatStop sl_WlanRxStatGet + \note belongs to \ref ext_api + \warning This API is deprecated and should be removed for next release + \par Example: + \code Getting wlan RX statistics: + + void RxStatCollectTwice() + { + SlGetRxStatResponse_t rxStat; + _i16 rawSocket; + _i8 DataFrame[200]; + struct SlTimeval_t timeval; + timeval.tv_sec = 0; // Seconds + timeval.tv_usec = 20000; // Microseconds. 10000 microseconds resolution + + sl_WlanRxStatStart(); // set statistics mode + + rawSocket = sl_Socket(SL_AF_RF, SL_SOCK_RAW, eChannel); + // set timeout - in case we have no activity for the specified channel + sl_SetSockOpt(rawSocket,SL_SOL_SOCKET,SL_SO_RCVTIMEO, &timeval, sizeof(timeval)); // Enable receive timeout + status = sl_Recv(rawSocket, DataFrame, sizeof(DataFrame), 0); + + Sleep(1000); // sleep for 1 sec + sl_WlanRxStatGet(&rxStat,0); // statistics has been cleared upon read + Sleep(1000); // sleep for 1 sec + sl_WlanRxStatGet(&rxStat,0); + + } + \endcode +*/ +#if _SL_INCLUDE_FUNC(sl_WlanRxStatStart) +_i16 sl_WlanRxStatStart(void); +#endif + + +/*! + \brief Stop collecting wlan RX statistic, (if previous called sl_WlanRxStatStart) + + \return On success, zero is returned. On error, -1 is returned + + \sa sl_WlanRxStatStart sl_WlanRxStatGet + \note belongs to \ref ext_api + \warning This API is deprecated and should be removed for next release +*/ +#if _SL_INCLUDE_FUNC(sl_WlanRxStatStop) +_i16 sl_WlanRxStatStop(void); +#endif + + +/*! + \brief Get wlan RX statistics. upon calling this command, the statistics counters will be cleared. + + \param[in] Flags should be 0 ( not applicable right now, will be added the future ) + \param[in] pRxStat a pointer to SlGetRxStatResponse_t filled with Rx statistics results + \return On success, zero is returned. On error, -1 is returned + + \sa sl_WlanRxStatStart sl_WlanRxStatStop + \note belongs to \ref ext_api + \warning +*/ +#if _SL_INCLUDE_FUNC(sl_WlanRxStatGet) +_i16 sl_WlanRxStatGet(SlGetRxStatResponse_t *pRxStat,_u32 Flags); +#endif + + +/*! + \brief Stop Smart Config procedure. Once Smart Config will be stopped, + Asynchronous event will be received - SL_OPCODE_WLAN_SMART_CONFIG_STOP_ASYNC_RESPONSE. + + \param[in] none + \param[out] none + + \return 0 - if Stop Smart Config is about to be executed without errors. + + \sa sl_WlanSmartConfigStart + \note belongs to \ref ext_api + \warning This API is deprecated and should be removed for next release + +*/ +#if _SL_INCLUDE_FUNC(sl_WlanSmartConfigStop) +_i16 sl_WlanSmartConfigStop(void); +#endif + +/*! + \brief Start Smart Config procedure + \par + The target of the procedure is to let the \n + device to gain the network parameters: SSID and Password (if network is secured) \n + and to connect to it once located in the network range. \n + An external application should be used on a device connected to any mobile network. \n + The external application will transmit over the air the network parameters in secured manner.\n + The Password may be decrypted using a Key. \n + The decryption method may be decided in the command or embedded in the Flash. \n + The procedure can be activated for 1-3 group ID in the range of BIT_0 - BIT_15 where the default group ID id 0 (BIT_0) \n + Once Smart Config has ended successfully, Asynchronous event will be received - \n + SL_OPCODE_WLAN_SMART_CONFIG_START_ASYNC_RESPONSE. \n + The Event will hold the SSID and an extra field that might have been delivered as well (i.e. - device name) + + \param[in] groupIdBitmask - each bit represent a group ID that should be searched. + The Default group ID id BIT_0. 2 more group can be searched + in addition. The range is BIT_0 - BIT_15. + \param[in] chiper - 0: check in flash, 1 - AES, 0xFF - do not check in flash + \param[in] publicKeyLen - public key len (used for the default group ID - BIT_0) + \param[in] group1KeyLen - group ID1 length + \param[in] group2KeyLen - group ID2 length + \param[in] publicKey - public key (used for the default group ID - BIT_0) + \param[in] group1Key - group ID1 key + \param[in] group2Key - group ID2 key + + \param[out] none + + \return 0 - if Smart Config started successfully. + + \sa sl_WlanSmartConfigStop + \note belongs to \ref ext_api + \warning + \par + \code An example of starting smart Config on group ID's 0 + 1 + 2 + + sl_WlanSmartConfigStart(7, //group ID's (BIT_0 | BIT_1 | BIT_2) + 1, //decrypt key by AES method + 16, //decryption key length for group ID0 + 16, //decryption key length for group ID1 + 16, //decryption key length for group ID2 + "Key0Key0Key0Key0", //decryption key for group ID0 + "Key1Key1Key1Key1", //decryption key for group ID1 + "Key2Key2Key2Key2" //decryption key for group ID2 + ); + \endcode +*/ +#if _SL_INCLUDE_FUNC(sl_WlanSmartConfigStart) +_i16 sl_WlanSmartConfigStart(const _u32 groupIdBitmask, + const _u8 cipher, + const _u8 publicKeyLen, + const _u8 group1KeyLen, + const _u8 group2KeyLen, + const _u8* publicKey, + const _u8* group1Key, + const _u8* group2Key); +#endif + + +/*! + \brief Wlan set mode + + Setting WLAN mode + + \param[in] mode - WLAN mode to start the CC31xx device. Possible options are: + - ROLE_STA - for WLAN station mode + - ROLE_AP - for WLAN AP mode + - ROLE_P2P -for WLAN P2P mode + \return 0 - if mode was set correctly + \sa sl_Start sl_Stop + \note belongs to \ref ext_api + \warning After setting the mode the system must be restarted for activating the new mode + \par Example: + \code + //Switch from any role to STA: + sl_WlanSetMode(ROLE_STA); + sl_Stop(0); + sl_Start(NULL,NULL,NULL); + \endcode + +*/ +#if _SL_INCLUDE_FUNC(sl_WlanSetMode) +_i16 sl_WlanSetMode(const _u8 mode); +#endif + + +/*! + \brief Internal function for setting WLAN configurations + + \return On success, zero is returned. On error one of the following error codes returned: + - CONF_ERROR (-1) + - CONF_NVMEM_ACCESS_FAILED (-2) + - CONF_OLD_FILE_VERSION (-3) + - CONF_ERROR_NO_SUCH_COUNTRY_CODE (-4) + + + \param[in] ConfigId - configuration id + - <b>SL_WLAN_CFG_AP_ID</b> + - <b>SL_WLAN_CFG_GENERAL_PARAM_ID</b> + - <b>SL_WLAN_CFG_P2P_PARAM_ID</b> + + \param[in] ConfigOpt - configurations option + - <b>SL_WLAN_CFG_AP_ID</b> + - <b>WLAN_AP_OPT_SSID</b> \n + Set SSID for AP mode. \n + This options takes <b>_u8</b> buffer as parameter + - <b>WLAN_AP_OPT_CHANNEL</b> \n + Set channel for AP mode. \n + The channel is dependant on the country code which is set. i.e. for "US" the channel should be in the range of [1-11] \n + This option takes <b>_u8</b> as a parameter + - <b>WLAN_AP_OPT_HIDDEN_SSID</b> \n + Set Hidden SSID Mode for AP mode.Hidden options: \n + 0: disabled \n + 1: Send empty (length=0) SSID in beacon and ignore probe request for broadcast SSID \n + 2: Clear SSID (ASCII 0), but keep the original length (this may be required with some \n + clients that do not support empty SSID) and ignore probe requests for broadcast SSID \n + This option takes <b>_u8</b> as a parameter + - <b>WLAN_AP_OPT_SECURITY_TYPE</b> \n + Set Security type for AP mode. Security options are: + - Open security: SL_SEC_TYPE_OPEN + - WEP security: SL_SEC_TYPE_WEP + - WPA security: SL_SEC_TYPE_WPA_WPA2 \n + This option takes <b>_u8</b> pointer as a parameter + - <b>WLAN_AP_OPT_PASSWORD</b> \n + Set Password for for AP mode (for WEP or for WPA): \n + Password - for WPA: 8 - 63 characters \n + for WEP: 5 / 13 characters (ascii) \n + This options takes <b>_u8</b> buffer as parameter + - <b>SL_WLAN_CFG_GENERAL_PARAM_ID</b> + - <b>WLAN_GENERAL_PARAM_OPT_COUNTRY_CODE</b> \n + Set Country Code for AP mode \n + This options takes <b>_u8</b> 2 bytes buffer as parameter + - <b>WLAN_GENERAL_PARAM_OPT_STA_TX_POWER</b> \n + Set STA mode Tx power level \n + Number between 0-15, as dB offset from max power (0 will set MAX power) \n + This options takes <b>_u8</b> as parameter + - <b>WLAN_GENERAL_PARAM_OPT_AP_TX_POWER</b> + Set AP mode Tx power level \n + Number between 0-15, as dB offset from max power (0 will set MAX power) \n + This options takes <b>_u8</b> as parameter + - <b>WLAN_GENERAL_PARAM_OPT_INFO_ELEMENT</b> + Set Info Element for AP mode. \n + The Application can set up to MAX_PRIVATE_INFO_ELEMENTS_SUPPROTED info elements per Role (AP / P2P GO). \n + To delete an info element use the relevant index and length = 0. \n + The Application can set up to MAX_PRIVATE_INFO_ELEMENTS_SUPPROTED to the same role. \n + However, for AP - no more than INFO_ELEMENT_MAX_TOTAL_LENGTH_AP bytes can be stored for all info elements. \n + For P2P GO - no more than INFO_ELEMENT_MAX_TOTAL_LENGTH_P2P_GO bytes can be stored for all info elements. \n + This option takes sl_protocol_WlanSetInfoElement_t as parameter + - <b>SL_WLAN_CFG_P2P_PARAM_ID</b> + - <b>WLAN_P2P_OPT_DEV_TYPE</b> \n + Set P2P Device type.Maximum length of 17 characters. Device type is published under P2P I.E, \n + allows to make devices easier to recognize. \n + In case no device type is set, the default type is "1-0050F204-1" \n + This options takes <b>_u8</b> buffer as parameter + - <b>WLAN_P2P_OPT_CHANNEL_N_REGS</b> \n + Set P2P Channels. \n + listen channel (either 1/6/11 for 2.4GHz) \n + listen regulatory class (81 for 2.4GHz) \n + oper channel (either 1/6/11 for 2.4GHz) \n + oper regulatory class (81 for 2.4GHz) \n + listen channel and regulatory class will determine the device listen channel during p2p find listen phase \n + oper channel and regulatory class will determine the operating channel preferred by this device (in case it is group owner this will be the operating channel) \n + channels should be one of the social channels (1/6/11). In case no listen/oper channel selected, a random 1/6/11 will be selected. + This option takes pointer to <b>_u8[4]</b> as parameter + + \param[in] ConfigLen - configurations len + + \param[in] pValues - configurations values + + \sa + \note + \warning + \par Examples: + \par + <b> WLAN_AP_OPT_SSID: </b> + \code + _u8 str[33]; + memset(str, 0, 33); + memcpy(str, ssid, len); // ssid string of 32 characters + sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SSID, strlen(ssid), str); + \endcode + \par + <b> WLAN_AP_OPT_CHANNEL: </b> + \code + _u8 val = channel; + sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_CHANNEL, 1, (_u8 *)&val); + \endcode + \par + <b> WLAN_AP_OPT_HIDDEN_SSID: </b> + \code + _u8 val = hidden; + sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_HIDDEN_SSID, 1, (_u8 *)&val); + \endcode + \par + <b> WLAN_AP_OPT_SECURITY_TYPE: </b> + \code + _u8 val = SL_SEC_TYPE_WPA_WPA2; + sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SECURITY_TYPE, 1, (_u8 *)&val); + \endcode + \par + <b> WLAN_AP_OPT_PASSWORD: </b> + \code + _u8 str[65]; + _u16 len = strlen(password); + memset(str, 0, 65); + memcpy(str, password, len); + sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_PASSWORD, len, (_u8 *)str); + \endcode + \par + <b> WLAN_GENERAL_PARAM_OPT_STA_TX_POWER: </b> + \code + _u8 stapower=(_u8)power; + sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, WLAN_GENERAL_PARAM_OPT_STA_TX_POWER,1,(_u8 *)&stapower); + \endcode + \par + <b> WLAN_GENERAL_PARAM_OPT_COUNTRY_CODE: </b> + \code + _u8* str = (_u8 *) country; // string of 2 characters. i.e. - "US" + sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, WLAN_GENERAL_PARAM_OPT_COUNTRY_CODE, 2, str); + \endcode + \par + <b> WLAN_GENERAL_PARAM_OPT_AP_TX_POWER: </b> + \code + _u8 appower=(_u8)power; + sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, WLAN_GENERAL_PARAM_OPT_AP_TX_POWER,1,(_u8 *)&appower); + \endcode + \par + <b> WLAN_P2P_OPT_DEV_TYPE: </b> + \code + _u8 str[17]; + _u16 len = strlen(device_type); + memset(str, 0, 17); + memcpy(str, device_type, len); + sl_WlanSet(SL_WLAN_CFG_P2P_PARAM_ID, WLAN_P2P_OPT_DEV_TYPE, len, str); + \endcode + \par + <b> WLAN_P2P_OPT_CHANNEL_N_REGS: </b> + \code + _u8 str[4]; + str[0] = (_u8)11; // listen channel + str[1] = (_u8)81; // listen regulatory class + str[2] = (_u8)6; // oper channel + str[3] = (_u8)81; // oper regulatory class + sl_WlanSet(SL_WLAN_CFG_P2P_PARAM_ID, WLAN_P2P_OPT_CHANNEL_N_REGS, 4, str); + \endcode + \par + <b> WLAN_GENERAL_PARAM_OPT_INFO_ELEMENT: </b> + \code + sl_protocol_WlanSetInfoElement_t infoele; + infoele.index = Index; // Index of the info element. range: 0 - MAX_PRIVATE_INFO_ELEMENTS_SUPPROTED + infoele.role = Role; // INFO_ELEMENT_AP_ROLE (0) or INFO_ELEMENT_P2P_GO_ROLE (1) + infoele.ie.id = Id; // Info element ID. if INFO_ELEMENT_DEFAULT_ID (0) is set, ID will be set to 221. + // Organization unique ID. If all 3 bytes are zero - it will be replaced with 08,00,28. + infoele.ie.oui[0] = Oui0; // Organization unique ID first Byte + infoele.ie.oui[1] = Oui1; // Organization unique ID second Byte + infoele.ie.oui[2] = Oui2; // Organization unique ID third Byte + infoele.ie.length = Len; // Length of the info element. must be smaller than 253 bytes + memset(infoele.ie.data, 0, INFO_ELEMENT_MAX_SIZE); + if ( Len <= INFO_ELEMENT_MAX_SIZE ) + { + memcpy(infoele.ie.data, IE, Len); // Info element. length of the info element is [0-252] + sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID,WLAN_GENERAL_PARAM_OPT_INFO_ELEMENT,sizeof(sl_protocol_WlanSetInfoElement_t),(_u8* ) &infoele); + } + sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID,WLAN_GENERAL_PARAM_OPT_INFO_ELEMENT,sizeof(sl_protocol_WlanSetInfoElement_t),(_u8* ) &infoele); + \endcode + +*/ +#if _SL_INCLUDE_FUNC(sl_WlanSet) +_i16 sl_WlanSet(_u16 ConfigId ,_u16 ConfigOpt,_u16 ConfigLen, _u8 *pValues); +#endif + +/*! + \brief Internal function for getting WLAN configurations + + \return On success, zero is returned. On error, -1 is + returned + + \param[in] ConfigId - configuration id + - <b>SL_WLAN_CFG_AP_ID</b> + - <b>SL_WLAN_CFG_GENERAL_PARAM_ID</b> + - <b>SL_WLAN_CFG_P2P_PARAM_ID</b> + + \param[out] pConfigOpt - get configurations option + - <b>SL_WLAN_CFG_AP_ID</b> + - <b>WLAN_AP_OPT_SSID</b> \n + Get SSID for AP mode. \n + Get up to 32 characters of SSID \n + This options takes <b>_u8</b> as parameter + - <b>WLAN_AP_OPT_CHANNEL</b> \n + Get channel for AP mode. \n + This option takes <b>_u8</b> as a parameter + - <b>WLAN_AP_OPT_HIDDEN_SSID</b> \n + Get Hidden SSID Mode for AP mode.Hidden options: \n + 0: disabled \n + 1: Send empty (length=0) SSID in beacon and ignore probe request for broadcast SSID \n + 2: Clear SSID (ASCII 0), but keep the original length (this may be required with some \n + clients that do not support empty SSID) and ignore probe requests for broadcast SSID \n + This option takes <b>_u8</b> as a parameter + - <b>WLAN_AP_OPT_SECURITY_TYPE</b> \n + Get Security type for AP mode. Security options are: + - Open security: SL_SEC_TYPE_OPEN + - WEP security: SL_SEC_TYPE_WEP + - WPA security: SL_SEC_TYPE_WPA_WPA2 \n + This option takes <b>_u8</b> as a parameter + - <b>WLAN_AP_OPT_PASSWORD</b> \n + Get Password for for AP mode (for WEP or for WPA): \n + Returns password - string, fills up to 64 characters. \n + This options takes <b>_u8</b> buffer as parameter + - <b>SL_WLAN_CFG_GENERAL_PARAM_ID</b> + - <b> WLAN_GENERAL_PARAM_OPT_SCAN_PARAMS </b> \n + Get scan parameters. + This option uses slWlanScanParamCommand_t as parameter + - <b>WLAN_GENERAL_PARAM_OPT_COUNTRY_CODE</b> \n + Get Country Code for AP mode \n + This options takes <b>_u8</b> buffer as parameter + - <b>WLAN_GENERAL_PARAM_OPT_STA_TX_POWER</b> \n + Get STA mode Tx power level \n + Number between 0-15, as dB offset from max power (0 indicates MAX power) \n + This options takes <b>_u8</b> as parameter + - <b>WLAN_GENERAL_PARAM_OPT_AP_TX_POWER</b> + Get AP mode Tx power level \n + Number between 0-15, as dB offset from max power (0 indicates MAX power) \n + This options takes <b>_u8</b> as parameter + - <b>SL_WLAN_CFG_P2P_PARAM_ID</b> + - <b>WLAN_P2P_OPT_CHANNEL_N_REGS</b> \n + Get P2P Channels. \n + listen channel (either 1/6/11 for 2.4GHz) \n + listen regulatory class (81 for 2.4GHz) \n + oper channel (either 1/6/11 for 2.4GHz) \n + oper regulatory class (81 for 2.4GHz) \n + listen channel and regulatory class will determine the device listen channel during p2p find listen phase \n + oper channel and regulatory class will determine the operating channel preferred by this device (in case it is group owner this will be the operating channel) \n + channels should be one of the social channels (1/6/11). In case no listen/oper channel selected, a random 1/6/11 will be selected. \n + This option takes pointer to <b>_u8[4]</b> as parameter + + \param[out] pConfigLen - The length of the allocated memory as input, when the + function complete, the value of this parameter would be + the len that actually read from the device. + If the device return length that is longer from the input + value, the function will cut the end of the returned structure + and will return SL_ESMALLBUF. + + + \param[out] pValues - get configurations values + + \sa sl_WlanSet + + \note + + \warning + + \par Examples: + \par + <b> WLAN_GENERAL_PARAM_OPT_SCAN_PARAMS: </b> + \code + slWlanScanParamCommand_t ScanParamConfig; + _u16 Option = WLAN_GENERAL_PARAM_OPT_SCAN_PARAMS; + _u16 OptionLen = sizeof(slWlanScanParamCommand_t); + sl_WlanGet(SL_WLAN_CFG_GENERAL_PARAM_ID ,&Option,&OptionLen,(_u8 *)&ScanParamConfig); + \endcode + \par + <b> WLAN_GENERAL_PARAM_OPT_AP_TX_POWER: </b> + \code + _i16 TXPower = 0; + _u16 Option = WLAN_GENERAL_PARAM_OPT_AP_TX_POWER; + _u16 OptionLen = sizeof(_i16); + sl_WlanGet(SL_WLAN_CFG_GENERAL_PARAM_ID ,&Option,&OptionLen,(_u8 *)&TXPower); + \endcode + \par + <b> WLAN_GENERAL_PARAM_OPT_STA_TX_POWER: </b> + \code + _i16 TXPower = 0; + _u16 Option = WLAN_GENERAL_PARAM_OPT_STA_TX_POWER; + _u16 OptionLen = sizeof(_i16); + + sl_WlanGet(SL_WLAN_CFG_GENERAL_PARAM_ID ,&Option,&OptionLen,(_u8 *)&TXPower); + \endcode + \par + <b> WLAN_P2P_OPT_DEV_TYPE: </b> + \code + _i8 device_type[18]; + _u16 len = 18; + _u16 config_opt = WLAN_P2P_OPT_DEV_TYPE; + sl_WlanGet(SL_WLAN_CFG_P2P_PARAM_ID, &config_opt , &len, (_u8* )device_type); + \endcode + \par + <b> WLAN_AP_OPT_SSID: </b> + \code + _i8 ssid[32]; + _u16 len = 32; + _u16 config_opt = WLAN_AP_OPT_SSID; + sl_WlanGet(SL_WLAN_CFG_AP_ID, &config_opt , &len, (_u8* )ssid); + \endcode + \par + <b> WLAN_GENERAL_PARAM_OPT_COUNTRY_CODE: </b> + \code + _i8 country[3]; + _u16 len = 3; + _u16 config_opt = WLAN_GENERAL_PARAM_OPT_COUNTRY_CODE; + sl_WlanGet(SL_WLAN_CFG_GENERAL_PARAM_ID, &config_opt, &len, (_u8* )country); + \endcode + \par + <b> WLAN_AP_OPT_CHANNEL: </b> + \code + _i8 channel; + _u16 len = 1; + _u16 config_opt = WLAN_AP_OPT_CHANNEL; + sl_WlanGet(SL_WLAN_CFG_AP_ID, &config_opt, &len, (_u8* )&channel); + \endcode + \par + <b> WLAN_AP_OPT_HIDDEN_SSID: </b> + \code + _u8 hidden; + _u16 len = 1; + _u16 config_opt = WLAN_AP_OPT_HIDDEN_SSID; + sl_WlanGet(SL_WLAN_CFG_AP_ID, &config_opt, &len, (_u8* )&hidden); + \endcode + \par + <b> WLAN_AP_OPT_SECURITY_TYPE: </b> + \code + _u8 sec_type; + _u16 len = 1; + _u16 config_opt = WLAN_AP_OPT_SECURITY_TYPE; + sl_WlanGet(SL_WLAN_CFG_AP_ID, &config_opt, &len, (_u8* )&sec_type); + \endcode + \par + <b> WLAN_AP_OPT_PASSWORD: </b> + \code + _u8 password[64]; + _u16 len = 64; + memset(password,0,64); + _u16 config_opt = WLAN_AP_OPT_PASSWORD; + sl_WlanGet(SL_WLAN_CFG_AP_ID, &config_opt, &len, (_u8* )password); + + \endcode + \par + <b> WLAN_P2P_OPT_CHANNEL_N_REGS: </b> + \code + _u16 listen_channel,listen_reg,oper_channel,oper_reg; + _u16 len = 4; + _u16 config_opt = WLAN_P2P_OPT_CHANNEL_N_REGS; + _u8 channel_n_regs[4]; + sl_WlanGet(SL_WLAN_CFG_P2P_PARAM_ID, &config_opt, &len, (_u8* )channel_n_regs); + listen_channel = channel_n_regs[0]; + listen_reg = channel_n_regs[1]; + oper_channel = channel_n_regs[2]; + oper_reg = channel_n_regs[3]; + \endcode +*/ + +#if _SL_INCLUDE_FUNC(sl_WlanGet) +_i16 sl_WlanGet(_u16 ConfigId, _u16 *pConfigOpt,_u16 *pConfigLen, _u8 *pValues); +#endif +/*! + + Close the Doxygen group. + @} + + */ + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __WLAN_H__ */ + diff --git a/drivers/cc3100/inc/wlan_rx_filters.h b/drivers/cc3100/inc/wlan_rx_filters.h new file mode 100644 index 0000000000..df48ff5602 --- /dev/null +++ b/drivers/cc3100/inc/wlan_rx_filters.h @@ -0,0 +1,930 @@ +/* + * wlan_rx_filters.h - CC31xx/CC32xx Host Driver Implementation + * + * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +*/ + +#ifndef RX_FILTERS_PREPROCESSOR_CLI_IF_H_ +#define RX_FILTERS_PREPROCESSOR_CLI_IF_H_ + + +/*****************************************************************************/ +/* Include files */ +/*****************************************************************************/ +#include "simplelink.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/*****************************************************************************/ +/* Macro declarations */ +/*****************************************************************************/ + +/*! + * \def SL_RX_FILTER_MAX_FILTERS + * The Max number of filters for 64 filters + */ +#define SL_RX_FILTER_MAX_FILTERS 64 + +/*! + * \def SL_RX_FILTER_MAX_PRE_PREPARED_FILTERS_SETS + * The Max number of software filters + */ +#define SL_RX_FILTER_MAX_PRE_PREPARED_FILTERS_SETS (32) +/*! + * \def SL_RX_FILTER_NUM_OF_FILTER_HEADER_ARGS + * + */ +#define SL_RX_FILTER_NUM_OF_FILTER_HEADER_ARGS (2) +/*! + * \def SL_RX_FILTER_NUM_OF_FILTER_PAYLOAD_ARGS + * + */ +#define SL_RX_FILTER_NUM_OF_FILTER_PAYLOAD_ARGS (2) +/*! + * \def SL_RX_FILTER_NUM_OF_FILTER_PAYLOAD_ARGS + * + */ +#define SL_RX_FILTER_NUM_OF_COMBINATION_TYPE_ARGS (2) +/*! + * \def SL_RX_FILTER_LENGTH_OF_REGX_PATTERN_LENGTH + * + */ +#define SL_RX_FILTER_LENGTH_OF_REGX_PATTERN_LENGTH (32) + + +/* List of possible error numbers */ +#define RXFL_OK (0) /* O.K */ +#define RXFL_OUTPUT_OR_INPUT_BUFFER_LENGTH_TOO_SMALL (76) /* ! The output buffer length is smaller than required for that operation */ +#define RXFL_DEPENDENT_FILTER_SOFTWARE_FILTER_NOT_FIT (75) /* Node filter can't be child of software filter and vice_versa */ +#define RXFL_DEPENDENCY_IS_NOT_PERSISTENT (74) /* Dependency filter is not persistent */ +#define RXFL_SYSTEM_STATE_NOT_SUPPORTED_FOR_THIS_FILTER (72) /* System state is not supported */ +#define RXFL_TRIGGER_USE_REG5_TO_REG8 (71) /* Only counters 5 - 8 are allowed, for Tigger */ +#define RXFL_TRIGGER_USE_REG1_TO_REG4 (70) /* Only counters 1 - 4 are allowed, for trigger */ +#define RXFL_ACTION_USE_REG5_TO_REG8 (69) /* Only counters 5 - 8 are allowed, for action */ +#define RXFL_ACTION_USE_REG1_TO_REG4 (68) /* Only counters 1 - 4 are allowed, for action */ +#define RXFL_FIELD_SUPPORT_ONLY_EQUAL_AND_NOTEQUAL (67) /* Rule compare function Id is out of range */ +#define RXFL_WRONG_MULTICAST_BROADCAST_ADDRESS (66) /* The address should be of type mutlicast or broadcast */ +#define RXFL_THE_FILTER_IS_NOT_OF_HEADER_TYPE (65) /* The filter should be of header type */ +#define RXFL_WRONG_COMPARE_FUNC_FOR_BROADCAST_ADDRESS (64) /* The compare funcion is not suitable for broadcast address */ +#define RXFL_WRONG_MULTICAST_ADDRESS (63) /* The address should be of muticast type */ +#define RXFL_DEPENDENT_FILTER_IS_NOT_PERSISTENT (62) /* The dependency filter is not persistent */ +#define RXFL_DEPENDENT_FILTER_IS_NOT_ENABLED (61) /* The dependency filter is not enabled */ +#define RXFL_FILTER_HAS_CHILDS (60) /* The filter has childs and can't be removed */ +#define RXFL_CHILD_IS_ENABLED (59) /* Can't disable filter while the child is enabled */ +#define RXFL_DEPENDENCY_IS_DISABLED (58) /* Can't enable filetr in case its depndency filter is disabled */ +#define RXFL_NUMBER_OF_CONNECTION_POINTS_EXCEEDED (52) /* Number of connection points exceeded */ +#define RXFL_DEPENDENT_FILTER_DEPENDENCY_ACTION_IS_DROP (51) /* The dependent filter has Drop action, thus the filter can't be created */ +#define RXFL_FILTER_DO_NOT_EXISTS (50) /* The filter doesn't exists */ +#define RXFL_DEPEDENCY_NOT_ON_THE_SAME_LAYER (49) /* The filter and its dependency must be on the same layer */ +#define RXFL_NUMBER_OF_ARGS_EXCEEDED (48) /* Number of arguments excceded */ +#define RXFL_ACTION_NO_REG_NUMBER (47) /* Action require counter number */ +#define RXFL_DEPENDENT_FILTER_LAYER_DO_NOT_FIT (46) /* the filter and its dependency should be from the same layer */ +#define RXFL_DEPENDENT_FILTER_SYSTEM_STATE_DO_NOT_FIT (45) /* The filter and its dependency system state don't fit */ +#define RXFL_DEPENDENT_FILTER_DO_NOT_EXIST_2 (44) /* The parent filter don't exist */ +#define RXFL_DEPENDENT_FILTER_DO_NOT_EXIST_1 (43) /* The parent filter is null */ +#define RXFL_RULE_HEADER_ACTION_TYPE_NOT_SUPPORTED (42) /* The action type is not supported */ +#define RXFL_RULE_HEADER_TRIGGER_COMPARE_FUNC_OUT_OF_RANGE (41) /* The Trigger comparision function is out of range */ +#define RXFL_RULE_HEADER_TRIGGER_OUT_OF_RANGE (40) /* The Trigger is out of range */ +#define RXFL_RULE_HEADER_COMPARE_FUNC_OUT_OF_RANGE (39) /* The rule compare function is out of range */ +#define RXFL_FRAME_TYPE_NOT_SUPPORTED (38) /* ASCII frame type string is illegal */ +#define RXFL_RULE_FIELD_ID_NOT_SUPPORTED (37) /* Rule field ID is out of range */ +#define RXFL_RULE_HEADER_FIELD_ID_ASCII_NOT_SUPPORTED (36) /* This ASCII field ID is not supported */ +#define RXFL_RULE_HEADER_NOT_SUPPORTED (35) /* The header rule is not supported on current release */ +#define RXFL_RULE_HEADER_OUT_OF_RANGE (34) /* The header rule is out of range */ +#define RXFL_RULE_HEADER_COMBINATION_OPERATOR_OUT_OF_RANGE (33) /* Combination function Id is out of ramge */ +#define RXFL_RULE_HEADER_FIELD_ID_OUT_OF_RANGE (32) /* rule field Id is out of range */ +#define RXFL_UPDATE_NOT_SUPPORTED (31) /* Update not supported */ +#define RXFL_NO_FILTERS_ARE_DEFINED (24) /* No filters are defined in the system */ +#define RXFL_NUMBER_OF_FILTER_EXCEEDED (23) /* Number of max filters excceded */ + + +/******************************************************************************/ +/* Type declarations */ +/******************************************************************************/ + +/*! + + + * \typedef SlrxFilterID_t + * Unique filter ID which is allocated by the system , negative number means error + */ +typedef _i8 SlrxFilterID_t; + + +/*! + * \typedef SlrxFilterCompareMask_t + * The mask is used for the rule comparison function + */ +typedef _u8 SlrxFilterCompareMask_t; + +/*! + * \typedef SlrxFilterIdMask_t + * Representation of filters Id as a bit field + * The bit field is used to declare which filters are involved + * in operation. Number of filter can be up to 128 filters. i.e. 128 bits are needed. + * On the current release, up to 64 filters can be defined. + */ +typedef _u8 SlrxFilterIdMask_t[128/8]; + +/*! + * \typedef SlrxFilterPrePreparedFilters_t + * Describes the supported software filter sets, + */ +typedef _u8 SlrxFilterPrePreparedFilters_t; +#define SL_ARP_AUTO_REPLY_PRE_PREPARED_FILTERS (0) +#define SL_MULTICASTSIPV4_DROP_PREPREPARED_FILTERS (1) +#define SL_MULTICASTSIPV6_DROP_PREPREPARED_FILTERS (2) +#define SL_MULTICASTSWIFI_DROP_PREPREPARED_FILTERS (3) + + + +/*! + * \typedef SlrxFilterPrePreparedFiltersMask_t + * Describes the supported software filter sets, + * each bit represents different software filter set + * The filter sets are defined at SlrxFilterPrePreparedFilters_t + */ +typedef _u8 SlrxFilterPrePreparedFiltersMask_t[SL_RX_FILTER_MAX_PRE_PREPARED_FILTERS_SETS/8]; + + +/*! \typedef SlrxFilterRegxPattern_t + * The struct contains the regular expression pattern which is used in case of payload rule. + * Not supported in the current release + */ +typedef struct SlrxFilterRegxPattern_t +{ + _u8 x[SL_RX_FILTER_LENGTH_OF_REGX_PATTERN_LENGTH]; +}SlrxFilterRegxPattern_t; + + +/*! \typedef SlrxFilterAsciiArg_t + * The buffer is used to provide container for ASCII argument, which may be used in case of HEADER rule. + * example for ASCII argument can be : IP = 256.0.67.1 + */ +typedef _u8 SlrxFilterAsciiArg_t; + + +/*! \typedef SlrxFilterBinaryArg_t + * The buffer provides container for binary argument, which may be used in case of HEADER rule + */ +typedef _u8 SlrxFilterBinaryArg_t ; + + +/*! \typedef SlrxFilterActionArg_t + * Provides container for the filter action argument. + * for example: in case action is to send automatic response , the argument is the template to be used for the automatic response. + * + * + */ +typedef _u8 SlrxFilterActionArg_t ; + + + +/*! \typedef SlrxFilterOffset_t + * The offset relative to the packet payload start location. + * Not supported on current release + */ +typedef _u32 SlrxFilterOffset_t; + + + +/*! \typedef SlrxFilterRuleType_t + * Enumerates the different filter types. + * On the current release only HEADER and COMBINATION are supported. + */ +typedef _u8 SlrxFilterRuleType_t; +/* possible values for SlrxFilterRuleType_t */ +#define HEADER (0) +#define COMBINATION (1) +#define EXACT_PATTERN (2) +#define LIKELIHOOD_PATTERN (3) +#define ALWAYS_TRUE (4) +#define NUM_OF_FILTER_TYPES (5) + + +/*! \typedef SlrxFilterFlags_t + * Bit field which sets the behaviour of the RX filter + * + */ + +#define RX_FILTER_BINARY (0x1) +#define RX_FILTER_PERSISTENT (0x8) +#define RX_FILTER_ENABLE (0x10) + +typedef union SlrxFilterFlags_t +{ + + /* struct + { */ + /*! + * The filter argument can be set as binary argument or ASCII arguments. + * When the bit is on the argument are binary. + */ + /* _u8 Binary: 1; */ + /*! + * + */ + /* _u8 AutoSort : 1; */ + /*! + * + */ + /* _u8 AutoFaultDetect : 1; */ + /*! + * When the bit is on it means the the node is enabled . + */ + /* _u8 Enabled : 1; */ + /* _u8 padding : 3; */ + /* + };*/ + + _u8 IntRepresentation; + +}SlrxFilterFlags_t; + +/*! \typedef SlrxFilterCompareFunction_t + * Used as comparison function for the header type arguments + * + */ +typedef _u8 SlrxFilterCompareFunction_t; +/* Possible values for SlrxFilterCompareFunction_t */ +#define COMPARE_FUNC_IN_BETWEEN (0) +#define COMPARE_FUNC_EQUAL (1) +#define COMPARE_FUNC_NOT_EQUAL_TO (2) +#define COMPARE_FUNC_NOT_IN_BETWEEN (3) +#define COMPARE_FUNC_NUM_OF_FILTER_COMPARE_FUNC (4) + +/*! \typedef SlrxFilterCompareFunction_t + * Used as comparison function for the header type arguments + * + */ +typedef _u8 SlrxTriggerCompareFunction_t; +/* Possible values for SlrxTriggerCompareFunction_t */ +#define TRIGGER_COMPARE_FUNC_EQUAL (0) +/* arg1 == protocolVal ,not supported in current release */ +#define TRIGGER_COMPARE_FUNC_NOT_EQUAL_TO (1) +/* arg1 == protocolVal */ +#define TRIGGER_COMPARE_FUNC_SMALLER_THAN (2) +/* arg1 == protocolVal */ +#define TRIGGER_COMPARE_FUNC_BIGGER_THAN (3) +/* definition */ +#define TRIGGER_COMPARE_FUNC_NUM_OF_FILTER_COMPARE_FUNC (4) + + +/*! \typedef SlrxFilterHdrField_t + * Provides list of possible header types which may be defined as part of the rule + * + */ +typedef _u8 SlrxFilterHdrField_t; +/* Possible values for SlrxFilterHdrField_t */ +#define NULL_FIELD_ID_TYPE (0) +/* 802.11 control\data\management */ +#define FRAME_TYPE_FIELD (1) +/* 802.11 beacon\probe\.. */ +#define FRAME_SUBTYPE_FIELD (2) + /* 802.11 bssid type */ +#define BSSID_FIELD (3) + /* */ +#define MAC_SRC_ADDRESS_FIELD (4) + /* */ +#define MAC_DST_ADDRESS_FIELD (5) +/* */ +#define FRAME_LENGTH_FIELD (6) +/* */ +#define PROTOCOL_TYPE_FIELD (7) + /* */ +#define IP_VERSION_FIELD (8) + /* TCP / UDP */ +#define IP_PROTOCOL_FIELD (9) + /* */ +#define IPV4_SRC_ADRRESS_FIELD (10) +/* */ +#define IPV4_DST_ADDRESS_FIELD (11) +/* */ +#define IPV6_SRC_ADRRESS_FIELD (12) +/* */ +#define IPV6_DST_ADDRESS_FIELD (13) + /* */ +#define SRC_PORT_FIELD (14) + /* */ +#define DST_PORT_FIELD (15) + /* Definition */ +#define NUM_OF_FIELD_NAME_FIELD (16) + +/*! \union SlrxFilterHeaderArg_t + * The structure holds the header ARGS which are used in case of HDR rule. + */ +/* -- 36 bytes */ +typedef union SlrxFilterHeaderArg_t +{ + /*----------------------------- Large size ---------------------------------*/ + /*! buffer for binary arguments, number of argument may be up to SL_RX_FILTER_NUM_OF_FILTER_HEADER_ARGS + * example : IPV6 16 bytes, 39 characters + * ipv6 Ascii address: 2001:0db8:3c4d:0015:0000:0000:abcd:ef12 + */ + + SlrxFilterBinaryArg_t RxFilterDB16BytesRuleArgs[SL_RX_FILTER_NUM_OF_FILTER_HEADER_ARGS][16 ]; /* Binary Values for comparition */ + /*! buffer for ASCII arguments, number of argument may be up to SL_RX_FILTER_NUM_OF_FILTER_HEADER_ARGS + * example : IPV6 16 bytes, 39 characters + * ipv6 Ascii address: 2001:0db8:3c4d:0015:0000:0000:abcd:ef12 + * Ascii format for ipV6 is not supported + */ + /*----------------------------- Medium size ---------------------------------*/ + /*! buffer for binary arguments, number of argument may be up to SL_RX_FILTER_NUM_OF_FILTER_HEADER_ARGS + * MAC address: 6 bytes, 17 chars + */ + SlrxFilterBinaryArg_t RxFilterDB6BytesRuleArgs[SL_RX_FILTER_NUM_OF_FILTER_HEADER_ARGS][6]; /* Binary Values for comparition */ + /*! + * ! buffer for ASCII arguments, number of argument may be up to SL_RX_FILTER_NUM_OF_FILTER_HEADER_ARGS + * IP address: 4 bytes, 15 chars + * 2 bytes are added for padding + */ + SlrxFilterAsciiArg_t RxFilterDB18BytesAsciiRuleArgs[SL_RX_FILTER_NUM_OF_FILTER_HEADER_ARGS][18]; /* Ascii Values for comparison */ + /*----------------------------- Small size ---------------------------------*/ + /*! buffer for binary arguments, number of argument may be up to SL_RX_FILTER_NUM_OF_FILTER_HEADER_ARGS + * IP address: 4 bytes, 15 chars + * Port: 2 bytes, chars: 5 chars + */ + SlrxFilterBinaryArg_t RxFilterDB4BytesRuleArgs[SL_RX_FILTER_NUM_OF_FILTER_HEADER_ARGS][4]; /* Binary Values for comparison */ + /*! buffer for ASCII arguments, number of argument may be up to SL_RX_FILTER_NUM_OF_FILTER_HEADER_ARGS + * Port: 2 bytes, chars: 5 chars + */ + SlrxFilterAsciiArg_t RxFilterDB5BytesRuleAsciiArgs[SL_RX_FILTER_NUM_OF_FILTER_HEADER_ARGS][5]; /* Ascii Values for comparison */ + /*----------------------------- 1 byte size ---------------------------------*/ + /*! buffer for binary arguments, number of argument may be up to SL_RX_FILTER_NUM_OF_FILTER_HEADER_ARGS + */ + SlrxFilterBinaryArg_t RxFilterDB1BytesRuleArgs[SL_RX_FILTER_NUM_OF_FILTER_HEADER_ARGS][1]; /* Binary Values for comparison */ +}SlrxFilterHeaderArg_t; + + + +/*! \typedef SlrxFilterRuleHeaderArgsAndMask_t + * Structure which defines the Header Args and mask + */ +/* -- 52 bytes */ +typedef struct SlrxFilterRuleHeaderArgsAndMask_t +{ + /*! Argument for the comparison function */ + /* -- 36 byte */ + SlrxFilterHeaderArg_t RuleHeaderArgs; + + /*! the mask is used in order to enable partial comparison, + * Use the 0xFFFFFFFF in case you don't want to use mask + */ + /* -- 16 bytes */ + SlrxFilterCompareMask_t RuleHeaderArgsMask[16]; + +}SlrxFilterRuleHeaderArgsAndMask_t; + +/*! \typedef SlrxFilterHeaderType_t + * Structure which defines the Header rule + * The header rule defines compare function on the protocol header + * For example destMacAddre is between ( 12:6::78:77, 12:6::78:90 ) + * + */ +/* -- 56 byte */ +typedef struct SlrxFilterHeaderType_t +{ + /*! see :: SlrxFilterRuleHeaderArgsAndMask_t */ + /* -- 52 bytes */ + SlrxFilterRuleHeaderArgsAndMask_t RuleHeaderArgsAndMask; + + /*! Packet HDR field which will be compared to the argument */ + /* -- 1 byte */ + SlrxFilterHdrField_t RuleHeaderfield; + + /* -- 1 byte */ + /*! type of the comparison function + * see :: SlrxFilterCompareFunction_t + */ + SlrxFilterCompareFunction_t RuleCompareFunc; + + /*! padding */ + /* -- 2 bytes */ + _u8 RulePadding[2]; + +}SlrxFilterHeaderType_t; + +/*! \typedef SlrxFilterPayloadType_t + * Structure which defines payload rule. + * Not supported on current release. + */ +/* -- 40 byte */ +typedef struct SlrxFilterPayloadType_t +{ + /*! Not supported on current release */ + /* -- 32 byte */ + SlrxFilterRegxPattern_t RegxPattern; + /*! Not supported on current release */ + /* -- 4 byte */ + SlrxFilterOffset_t LowerOffset; + /*! Not supported on current release */ + /* -- 4 byte */ + SlrxFilterOffset_t UpperOffset; +}SlrxFilterPayloadType_t; + +/*! \typedef SlrxFilterCombinationTypeOperator_t + * Enumerate the optional operators for the combination type + * filterID1 is located in the first arg , filterId2 is the second arg,see ::SlrxFilterCombinationType_t.CombinationFilterId + */ +typedef _u8 SlrxFilterCombinationTypeOperator_t; +/* Possible values for SlrxFilterCombinationTypeOperator_t */ +/*! !filterID1 */ +#define COMBINED_FUNC_NOT (0) +/*! filterID1 && filterID2 */ +#define COMBINED_FUNC_AND (1) +/*! filterID1 && filterID2 */ +#define COMBINED_FUNC_OR (2) + +/*! \typedef SlrxFilterCombinationType_t + * Defines the structure which define the combination type filter + * The combined filter enable to make operation on one or two filter, + * for example !filterId1 or and(filterId2,filterId3). + * + */ +/* -- 4 byte */ +typedef struct SlrxFilterCombinationType_t +{ + /* ! combination operator */ + /* -- 1 byte */ + SlrxFilterCombinationTypeOperator_t CombinationTypeOperator; + /* ! filterID, may be one or two depends on the combination operator type */ + /* -- 2 byte */ + SlrxFilterID_t CombinationFilterId[SL_RX_FILTER_NUM_OF_COMBINATION_TYPE_ARGS]; + /* ! Padding */ + /* -- 1 byte */ + _u8 Padding; +}SlrxFilterCombinationType_t; + + +/*! \typedef SlrxFilterRule_t + * Rule structure composed of behavioral flags and the filter rule definitions + * + */ +/* -- 56 byte */ +typedef union SlrxFilterRule_t +{ + /* ! Header type rule , see explanation on the ::SlrxFilterHeaderType_t structure */ + /* -- 56 byte */ + SlrxFilterHeaderType_t HeaderType; + /* ! Payload rule, not supported in current release */ + /* -- 40 byte */ + SlrxFilterPayloadType_t PayLoadHeaderType; /* future for exact pattern or like hood pattern */ + /* ! Combined type rule , see explanation in ::SlrxFilterCombinationType_t structure */ + /* -- 4 byte */ + SlrxFilterCombinationType_t CombinationType; +}SlrxFilterRule_t; + +/*! \typedef SlrxFilterTriggerRoles_t + * Bit field which represents the roleId possible values + * In the current release only Station/AP roles are supported. + */ +#define RX_FILTER_ROLE_AP (1) +#define RX_FILTER_ROLE_STA (2) +#define RX_FILTER_ROLE_PROMISCUOUS (4) +#define RX_FILTER_ROLE_NULL (0) + +typedef union SlrxFilterTriggerRoles_t +{ +/* struct */ +/* { */ +/* _u8 RoleAP :1; */ +/* _u8 RoleStation :1; */ + /* The filter is activated only in Promiscuous mode */ +/* _u8 PromiscuousMode :1; */ +/* _u8 RoleReserved :5; */ +/* }; */ + /* ! Bit fiels of the Filter role */ + _u8 IntRepresentation; + +}SlrxFilterTriggerRoles_t; + +/*! \typedef SlrxFilterTriggerConnectionStates_t + * Bit field representing the possible values of the When section of the rule + * + */ +#define RX_FILTER_CONNECTION_STATE_STA_CONNECTED (1) +#define RX_FILTER_CONNECTION_STATE_STA_NOT_CONNECTED (2) +#define RX_FILTER_CONNECTION_STATE_STA_HAS_IP (4) +#define RX_FILTER_CONNECTION_STATE_STA_HAS_NO_IP (8) + +typedef union SlrxFilterTriggerConnectionStates_t +{ +/* struct */ +/* { */ +/* _u8 RoleStationWiFiConnected :1; */ +/* _u8 RoleStationWiFiDisconneted:1; */ +/* _u8 RoleStationWiFiHasIp:1; */ +/* _u8 RoleStationWiFiHasNoIp:1; */ +/* _u8 RoleStationWiFiSocketOpened:1; */ +/* _u8 RoleStationWiFiSocketclosed:1; */ +/* }; */ +/* */ + /* ! */ + _u8 IntRepresentation; + +}SlrxFilterTriggerConnectionStates_t; + +/*! \typedef SlrxFilterDBTriggerArg_t + * Provides container for entering the filter 'when' argument. + * The current release support 'When rules' which has no arguments. + * For example : + * When connect to specific AP -- the AP bssid is the argument. + * + */ +typedef _u32 SlrxFilterDBTriggerArg_t; + + + +/*! \typedef SlrxFilterCounterId_t + * the counter ID we have 4 counters + */ +typedef _u8 SlrxFilterCounterId_t; +/* Possible values for SlrxFilterCounterId_t */ +#define NO_TRIGGER (0) +#define RX_FILTER_COUNTER1 (1) +#define RX_FILTER_COUNTER2 (2) +#define RX_FILTER_COUNTER3 (3) +#define RX_FILTER_COUNTER4 (4) +#define RX_FILTER_COUNTER5 (5) +#define RX_FILTER_COUNTER6 (6) +#define RX_FILTER_COUNTER7 (7) +#define RX_FILTER_COUNTER8 (8) +#define MAX_RX_FILTER_COUNTER (9) + + + +/*! \typedef SlrxFilterActionArgs_t + * Possible value for filter action args + * + */ + +typedef _u8 SlrxFilterActionArgs_t; +/* Possible values for SlrxFilterActionArgs_t */ +#define ACTION_ARG_REG_1_4 (0) + /* ! Can be use as counter */ +#define ACTION_ARG_TEMPLATE (1) + /* ! Can be use as counter */ +#define ACTION_ARG_EVENT (2) + +/* ! GPIO number */ +#define ACTION_ARG_GPIO (4) +/*! + * \def SL_RX_FILTER_NUM_OF_BYTES_FOR_ACTIONS_ARGS + * + */ +#define SL_RX_FILTER_NUM_OF_BYTES_FOR_ACTIONS_ARGS (5) + + + + +/*! \typedef SlrxFilterTrigger_t + * The filter trigger, determine when the filter is triggered, + * The filter is triggered in the following condition :\n + * 1. The filter parent is triggered\n + * 2. The requested connection type exists, i.e. wlan_connect\n + * 3. The filter role is the same as the system role\n + * + */ +/* -- 12 byte */ +typedef struct SlrxFilterTrigger_t +{ + /*! The parent filter ID, this is the way to build filter tree. */ + /* NULL value means tree root. + */ + /* -- 1 byte */ + SlrxFilterID_t ParentFilterID; + /* ! See ::SlrxFilterCounterId_t explanation */ + /* -- 1 byte */ + SlrxFilterCounterId_t Trigger; + /* ! See :: SlrxFilterTriggerConnectionStates_t */ + /* -- 1 byte */ + SlrxFilterTriggerConnectionStates_t TriggerArgConnectionState; + /* ! See ::SlrxFilterTriggerRoles_t */ + /* -- 1 byte */ + SlrxFilterTriggerRoles_t TriggerArgRoleStatus; + /* ! The Trigger arguments are in the same order as the Trigger bit field order. */ + /* -- 4 byte */ + SlrxFilterDBTriggerArg_t TriggerArg; + /** The compare function which will be operate for each bit that is turned on in the ::SlrxFilterTrigger_t.Trigger field, + * for example , in case the second bit in the Trigger function is on the second function in the list will be executed. + * + */ + /* -- 1 byte */ + SlrxTriggerCompareFunction_t TriggerCompareFunction; + + /* ! padding */ + /* -- 3 byte */ + _u8 Padding[3]; +} SlrxFilterTrigger_t; + +/*! \typedef SlrxFilterActionType_t + * The actions are executed only if the filter is matched,\n + * In case of false match the packet is transfered to the HOST. \n + * The action is composed of bit field structure, + * up to 2 actions can be defined per filter. + * + */ +#define RX_FILTER_ACTION_NULL (0x0) +#define RX_FILTER_ACTION_DROP (0x1) +#define RX_FILTER_ACTION_GPIO (0x2) +#define RX_FILTER_ACTION_ON_REG_INCREASE (0x4) +#define RX_FILTER_ACTION_ON_REG_DECREASE (0x8) +#define RX_FILTER_ACTION_ON_REG_RESET (0x10) +#define RX_FILTER_ACTION_SEND_TEMPLATE (0x20) /* unsupported */ +#define RX_FILTER_ACTION_EVENT_TO_HOST (0x40) /* unsupported */ + +typedef union SlrxFilterActionType_t +{ +/* struct */ +/* { */ + /* ! No action to execute the packet is dropped,drop is always on leaf. */ + /* ! If not dropped ,The packet is passed to the next filter or in case it is the last filter to the host */ +/* _u8 ActionDrop : 1; */ + /* ! Not Supported in the current release */ +/* _u8 ActionGpio : 1; */ + /*! action can increase counter registers. + * 1 = Increase + * 2 = decrease + * 3 = reset + */ +/* _u8 ActionOnREGIncrease : 1; */ +/* _u8 ActionOnREGDecrease : 1; */ +/* _u8 ActionOnREGReset : 1; */ + + /* ! Not Supported in the current release */ +/* _u8 ActionSendTemplate : 1; */ + /* ! Not Supported in the current release */ +/* _u8 ActionEventToHost: 1; */ +/* _u8 padding: 1; */ +/* }; */ + + _u8 IntRepresentation; + +}SlrxFilterActionType_t; + +/*! \typedef SlrxFilterAction_t + * Several actions can be defined,\n + * The action is executed in case the filter rule is matched. + */ +/* -- 8 byte */ +typedef struct SlrxFilterAction_t +{ + /* -- 1 byte */ + /* ! Determine which actions are supported */ + SlrxFilterActionType_t ActionType; + /* ! Buffer for the action arguments */ + /** + * <b>location 0</b> - The counter to increase + * In case the action is of type "increase" the arg will contain the counter number, + * The counter number values are as in ::SlrxFilterCounterId_t.\n + * <b>location 1</b> - The template arg.\n + * <b>location 2</b> - The event arg.\n + * + */ + /* -- 5 byte */ + SlrxFilterActionArg_t ActionArg[SL_RX_FILTER_NUM_OF_BYTES_FOR_ACTIONS_ARGS]; + + /* ! Padding */ + /* - 2 Bytes */ + _u8 Padding[2]; + +} SlrxFilterAction_t; + + +/*! \struct _WlanRxFilterOperationCommandBuff_t + * The structure is used for the interface HOST NWP.\n + * The supported operation : \n + * ::ENABLE_DISABLE_RX_FILTER,\n + * ::REMOVE_RX_FILTER,\n + * + */ +/* 20 bytes */ +typedef struct _WlanRxFilterOperationCommandBuff_t +{ + /* -- 16 bytes */ + SlrxFilterIdMask_t FilterIdMask; + /* 4 bytes */ + _u8 Padding[4]; +}_WlanRxFilterOperationCommandBuff_t; + + + +/* -- 56 bytes */ +typedef struct _WlanRxFilterUpdateArgsCommandBuff_t +{ + /* -- 1 bytes */ + _u8 FilterId; + + /* -- 1 bytes */ + /* ! the args representation */ + _u8 BinaryRepresentation; + + /* -- 52 byte */ + SlrxFilterRuleHeaderArgsAndMask_t FilterRuleHeaderArgsAndMask; + + /* -- 2 bytes */ + _u8 Padding[2]; +}_WlanRxFilterUpdateArgsCommandBuff_t; + + +/*! \typedef _WlanRxFilterRetrieveEnableStatusCommandResponseBuff_t + * The structure is used for the interface HOST NWP.\n + * + */ +/* -- 16 bytes */ +typedef struct _WlanRxFilterRetrieveEnableStatusCommandResponseBuff_t +{ + + /* ! the filter set bit map */ + /* -- 16 bytes */ + SlrxFilterIdMask_t FilterIdMask; + +}_WlanRxFilterRetrieveEnableStatusCommandResponseBuff_t; + + +/*! \struct _WlanRxFilterPrePreparedFiltersCommandBuff_t + * The function enables to perform operations on pre-prepared filters + * + */ +typedef struct _WlanRxFilterPrePreparedFiltersCommandBuff_t +{ + /* ! the filter set bit map */ + /* -- 4 bytes */ + SlrxFilterPrePreparedFiltersMask_t FilterPrePreparedFiltersMask; + +}_WlanRxFilterPrePreparedFiltersCommandBuff_t; + + +/*! \typedef sl_protocol_WlanRxFilterPrePreparedFiltersCommandResponseBuff_t + * + */ +/*-- 4 bytes */ +typedef struct _WlanRxFilterPrePreparedFiltersCommandResponseBuff_t +{ + /* -- 4 bytes */ + /* ! the filter set bit map */ + SlrxFilterPrePreparedFiltersMask_t FilterPrePreparedFiltersMask; + +}_WlanRxFilterPrePreparedFiltersCommandResponseBuff_t; + + + +typedef _u8 SLrxFilterOperation_t; +#define SL_ENABLE_DISABLE_RX_FILTER (0) +#define SL_REMOVE_RX_FILTER (1) +#define SL_STORE_RX_FILTERS (2) +#define SL_UPDATE_RX_FILTER_ARGS (3) +#define SL_FILTER_RETRIEVE_ENABLE_STATE (4) +#define SL_FILTER_PRE_PREPARED_RETRIEVE_CREATE_REMOVE_STATE (5) +#define SL_FILTER_PRE_PREPARED_SET_CREATE_REMOVE_STATE (6) + + +/* Bit manipulation for 8 bit */ +#define ISBITSET8(x,i) ((x[i>>3] & (0x80>>(i&7)))!=0) /* < Is bit set, 8 bit unsigned numbers = x , location = i */ +#define SETBIT8(x,i) x[i>>3]|=(0x80>>(i&7)); /* < Set bit,8 bit unsigned numbers = x , location = i */ +#define CLEARBIT8(x,i) x[i>>3]&=(0x80>>(i&7))^0xFF; /* < Clear bit,8 bit unsigned numbers = x , location = i */ + + +/*********************************************************************************************/ +/* Function prototypes */ +/*********************************************************************************************/ + +/*! + + \addtogroup wlan + @{ + +*/ + + +/*! + \brief Adds new filter rule to the system + + \param[in] RuleType The rule type + \param[in] FilterFlags Flags which set the type of header rule Args and sets the persistent flag + \param[in] pRule Determine the filter rule logic + \param[in] pTrigger Determine when the rule is triggered also sets rule parent. + \param[in] pAction Sets the action to be executed in case the match functions pass + \param[out] pFilterId The filterId which was created + + \return On success, zero is returned. Otherwise error code is returned + */ +#if _SL_INCLUDE_FUNC(sl_WlanRxFilterAdd) +SlrxFilterID_t sl_WlanRxFilterAdd( SlrxFilterRuleType_t RuleType, + SlrxFilterFlags_t FilterFlags, + const SlrxFilterRule_t* const Rule, + const SlrxFilterTrigger_t* const Trigger, + const SlrxFilterAction_t* const Action, + SlrxFilterID_t* pFilterId); + +#endif + + + + + +/*! + \brief Sets parameters to Rx filters + + \param[in] RxFilterOperation + possible operations : + - SL_ENABLE_DISABLE_RX_FILTER - Enables\disables filter in a filter list + - SL_REMOVE_RX_FILTER - Removes filter from memory ( to remove from flash call SL_STORE_RX_FILTERS after this command) + - SL_STORE_RX_FILTERS - Save the filters for persistent + - SL_UPDATE_RX_FILTER_ARGS - Update the arguments of existing filter + - SL_FILTER_PRE_PREPARED_SET_CREATE_REMOVE_STATE - Change the default creation of the pre-prepared filters + + \param[in] pInputBuffer options: + The buffer input is _WlanRxFilterOperationCommandBuff_t: + - SL_ENABLE_DISABLE_RX_FILTER + - SL_REMOVE_RX_FILTER + - SL_STORE_RX_FILTERS + The buffer input is _WlanRxFilterUpdateArgsCommandBuff_t: + - SL_UPDATE_RX_FILTER_ARGS + The buffer input is _WlanRxFilterPrePreparedFiltersCommandBuff_t: + - SL_FILTER_PRE_PREPARED_SET_CREATE_REMOVE_STATE + + \param[in] InputbufferLength The length in byte of the input buffer + + \return On success, zero is returned. Otherwise error code is returned + */ + +#if _SL_INCLUDE_FUNC(sl_WlanRxFilterSet) +_i16 sl_WlanRxFilterSet( const SLrxFilterOperation_t RxFilterOperation, + const _u8* const pInputBuffer, + _u16 InputbufferLength); +#endif + +/*! + \brief Gets parameters of Rx filters + + \param[in] RxFilterOperation + possible operations : + - SL_FILTER_RETRIEVE_ENABLE_STATE - Retrieves the enable disable status + - SL_FILTER_PRE_PREPARED_RETRIEVE_CREATE_REMOVE_STATE - Retrieves the pre-prepared filters creation status + + \param[in] pOutputBuffer + The buffer input is _WlanRxFilterRetrieveEnableStatusCommandResponseBuff_t: + - SL_FILTER_RETRIEVE_ENABLE_STATE + The buffer input is _WlanRxFilterPrePreparedFiltersCommandResponseBuff_t: + - SL_FILTER_PRE_PREPARED_RETRIEVE_CREATE_REMOVE_STATE + + \param[in] OutputbufferLength The length in byte of the output buffer + + \return On success, zero is returned. Otherwise error code is returned +*/ + +#if _SL_INCLUDE_FUNC(sl_WlanRxFilterGet) +_i16 sl_WlanRxFilterGet(const SLrxFilterOperation_t RxFilterOperation, + _u8* pOutputBuffer, + _u16 OutputbufferLength); +#endif + + +/*! + + Close the Doxygen group. + @} + + */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* RX_FILTERS_PREPROCESSOR_CLI_IF_H_ */ + + diff --git a/drivers/cc3100/src/device.c b/drivers/cc3100/src/device.c new file mode 100644 index 0000000000..95907cf7f9 --- /dev/null +++ b/drivers/cc3100/src/device.c @@ -0,0 +1,535 @@ +/* +* device.c - CC31xx/CC32xx Host Driver Implementation +* +* Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ +* +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the +* distribution. +* +* Neither the name of Texas Instruments Incorporated nor the names of +* its contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + + + +/*****************************************************************************/ +/* Include files */ +/*****************************************************************************/ +#include "simplelink.h" +#include "protocol.h" +#include "flowcont.h" +#include "driver.h" + + +/*****************************************************************************/ +/* Internal functions */ +/*****************************************************************************/ + +_i16 _sl_GetStartResponseConvert(_u32 Status) +{ + switch(Status) + { + case INIT_STA_OK: + return ROLE_STA; + case INIT_STA_ERR: + return ROLE_STA_ERR; + case INIT_AP_OK: + return ROLE_AP; + case INIT_AP_ERR: + return ROLE_AP_ERR; + case INIT_P2P_OK: + return ROLE_P2P; + case INIT_P2P_ERR: + return ROLE_P2P_ERR; + default: + return (_i16)Status; + } +} + +/*****************************************************************************/ +/* API Functions */ +/*****************************************************************************/ + + + +/*****************************************************************************/ +/* sl_Task */ +/*****************************************************************************/ +#if _SL_INCLUDE_FUNC(sl_Task) +void sl_Task(void) +{ +#ifdef _SlTaskEntry + _SlTaskEntry(); +#endif +} +#endif + +/*****************************************************************************/ +/* sl_Start */ +/*****************************************************************************/ +#if _SL_INCLUDE_FUNC(sl_Start) +_i16 sl_Start(const void* pIfHdl, _i8* pDevName, const P_INIT_CALLBACK pInitCallBack) +{ + _i16 ObjIdx = MAX_CONCURRENT_ACTIONS; + InitComplete_t AsyncRsp; + + /* Perform any preprocessing before enable networking services */ + sl_DeviceEnablePreamble(); + + /* ControlBlock init */ + _SlDrvDriverCBInit(); + + /* open the interface: usually SPI or UART */ + if (NULL == pIfHdl) + { + g_pCB->FD = sl_IfOpen((void *)pDevName, 0); + } + else + { + g_pCB->FD = (_SlFd_t)pIfHdl; + } + /* Use Obj to issue the command, if not available try later */ + ObjIdx = _SlDrvWaitForPoolObj(START_STOP_ID,SL_MAX_SOCKETS); + if (MAX_CONCURRENT_ACTIONS == ObjIdx) + { + return SL_POOL_IS_EMPTY; + } + OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); + g_pCB->ObjPool[ObjIdx].pRespArgs = (_u8 *)&AsyncRsp; + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); + + if( g_pCB->FD >= 0) + { + sl_DeviceDisable(); + + sl_IfRegIntHdlr((SL_P_EVENT_HANDLER)_SlDrvRxIrqHandler, NULL); + + if(NULL != pInitCallBack) + { + g_pCB->pInitCallback = pInitCallBack; + } + sl_DeviceEnable(); + + if (NULL == pInitCallBack) + { + OSI_RET_OK_CHECK(sl_SyncObjWait(&g_pCB->ObjPool[ObjIdx].SyncObj, SL_OS_WAIT_FOREVER)); + /*release Pool Object*/ + _SlDrvReleasePoolObj(g_pCB->FunctionParams.AsyncExt.ActionIndex); + return _sl_GetStartResponseConvert(AsyncRsp.Status); + } + } + + return (_i16)g_pCB->FD; + +} +#endif + +/*************************************************************************** +_sl_HandleAsync_InitComplete - handles init complete signalling to +a waiting object +****************************************************************************/ +void _sl_HandleAsync_InitComplete(void *pVoidBuf) +{ + InitComplete_t *pMsgArgs = (InitComplete_t *)_SL_RESP_ARGS_START(pVoidBuf); + + OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); + + if(g_pCB->pInitCallback) + { + g_pCB->pInitCallback(_sl_GetStartResponseConvert(pMsgArgs->Status)); + } + else + { + sl_Memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(InitComplete_t)); + OSI_RET_OK_CHECK(sl_SyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj)); + } + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); + + if(g_pCB->pInitCallback) + { + _SlDrvReleasePoolObj(g_pCB->FunctionParams.AsyncExt.ActionIndex); + } + +} + +/*************************************************************************** +_sl_HandleAsync_Stop - handles stop signalling to +a waiting object +****************************************************************************/ +void _sl_HandleAsync_Stop(void *pVoidBuf) +{ + _BasicResponse_t *pMsgArgs = (_BasicResponse_t *)_SL_RESP_ARGS_START(pVoidBuf); + + VERIFY_SOCKET_CB(NULL != g_pCB->StopCB.pAsyncRsp); + + OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); + + sl_Memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_BasicResponse_t)); + OSI_RET_OK_CHECK(sl_SyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj)); + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); + return; +} + + +/***************************************************************************** +sl_stop +******************************************************************************/ +typedef union +{ + _DevStopCommand_t Cmd; + _BasicResponse_t Rsp; +}_SlStopMsg_u; + +const _SlCmdCtrl_t _SlStopCmdCtrl = +{ + SL_OPCODE_DEVICE_STOP_COMMAND, + sizeof(_DevStopCommand_t), + sizeof(_BasicResponse_t) +}; + +#if _SL_INCLUDE_FUNC(sl_Stop) +_i16 sl_Stop(_u16 timeout) +{ + _i16 RetVal=0; + _SlStopMsg_u Msg; + _BasicResponse_t AsyncRsp; + _i16 ObjIdx = MAX_CONCURRENT_ACTIONS; + /* if timeout is 0 the shutdown is forced immediately */ + if( 0 == timeout ) + { + sl_IfRegIntHdlr(NULL, NULL); + sl_DeviceDisable(); + RetVal = sl_IfClose(g_pCB->FD); + + } + else + { + /* let the device make the shutdown using the defined timeout */ + Msg.Cmd.Timeout = timeout; + /* Use Obj to issue the command, if not available try later */ + ObjIdx = _SlDrvWaitForPoolObj(START_STOP_ID,SL_MAX_SOCKETS); + if (MAX_CONCURRENT_ACTIONS == ObjIdx) + { + return SL_POOL_IS_EMPTY; + } + OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); + + g_pCB->ObjPool[ObjIdx].pRespArgs = (_u8 *)&AsyncRsp; + + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlStopCmdCtrl, &Msg, NULL)); + + if(SL_OS_RET_CODE_OK == (_i16)Msg.Rsp.status) + { + OSI_RET_OK_CHECK(sl_SyncObjWait(&g_pCB->ObjPool[ObjIdx].SyncObj, SL_OS_WAIT_FOREVER)); + Msg.Rsp.status = AsyncRsp.status; + RetVal = Msg.Rsp.status; + } + + _SlDrvReleasePoolObj((_u8)ObjIdx); + + sl_IfRegIntHdlr(NULL, NULL); + sl_DeviceDisable(); + sl_IfClose(g_pCB->FD); + } + _SlDrvDriverCBDeinit(); + + return RetVal; +} +#endif + + +/***************************************************************************** +sl_EventMaskSet +*****************************************************************************/ +typedef union +{ + _DevMaskEventSetCommand_t Cmd; + _BasicResponse_t Rsp; +}_SlEventMaskSetMsg_u; + +const _SlCmdCtrl_t _SlEventMaskSetCmdCtrl = +{ + SL_OPCODE_DEVICE_EVENTMASKSET, + sizeof(_DevMaskEventSetCommand_t), + sizeof(_BasicResponse_t) +}; + +#if _SL_INCLUDE_FUNC(sl_EventMaskSet) +_i16 sl_EventMaskSet(_u8 EventClass , _u32 Mask) +{ + _SlEventMaskSetMsg_u Msg; + + Msg.Cmd.group = EventClass; + Msg.Cmd.mask = Mask; + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlEventMaskSetCmdCtrl, &Msg, NULL)); + + return (_i16)Msg.Rsp.status; +} +#endif + +/****************************************************************************** +sl_EventMaskGet +******************************************************************************/ +typedef union +{ + _DevMaskEventGetCommand_t Cmd; + _DevMaskEventGetResponse_t Rsp; +}_SlEventMaskGetMsg_u; + +const _SlCmdCtrl_t _SlEventMaskGetCmdCtrl = +{ + SL_OPCODE_DEVICE_EVENTMASKGET, + sizeof(_DevMaskEventGetCommand_t), + sizeof(_DevMaskEventGetResponse_t) +}; + +#if _SL_INCLUDE_FUNC(sl_EventMaskGet) +_i16 sl_EventMaskGet(_u8 EventClass, _u32 *pMask) +{ + _SlEventMaskGetMsg_u Msg; + + Msg.Cmd.group = EventClass; + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlEventMaskGetCmdCtrl, &Msg, NULL)); + + *pMask = Msg.Rsp.mask; + return SL_RET_CODE_OK; +} +#endif + + + +/****************************************************************************** +sl_DevGet +******************************************************************************/ + +typedef union +{ + _DeviceSetGet_t Cmd; + _DeviceSetGet_t Rsp; +}_SlDeviceMsgGet_u; + +const _SlCmdCtrl_t _SlDeviceGetCmdCtrl = +{ + SL_OPCODE_DEVICE_DEVICEGET, + sizeof(_DeviceSetGet_t), + sizeof(_DeviceSetGet_t) +}; + +#if _SL_INCLUDE_FUNC(sl_DevGet) +_i32 sl_DevGet(_u8 DeviceGetId, _u8 *pOption,_u8 *pConfigLen, _u8 *pValues) +{ + _SlDeviceMsgGet_u Msg; + _SlCmdExt_t CmdExt; + + if (*pConfigLen == 0) + { + return SL_EZEROLEN; + } + + if( pOption ) + { + CmdExt.TxPayloadLen = 0; + CmdExt.RxPayloadLen = *pConfigLen; + CmdExt.pTxPayload = NULL; + CmdExt.pRxPayload = (_u8 *)pValues; + CmdExt.ActualRxPayloadLen = 0; + + Msg.Cmd.DeviceSetId = DeviceGetId; + + Msg.Cmd.Option = (_u16)*pOption; + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlDeviceGetCmdCtrl, &Msg, &CmdExt)); + + if( pOption ) + { + *pOption = (_u8)Msg.Rsp.Option; + } + + if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen) + { + *pConfigLen = (_u8)CmdExt.RxPayloadLen; + return SL_ESMALLBUF; + } + else + { + *pConfigLen = (_u8)CmdExt.ActualRxPayloadLen; + } + + return (_i16)Msg.Rsp.Status; + } + else + { + return -1; + } +} +#endif + +/****************************************************************************** +sl_DevSet +******************************************************************************/ +typedef union +{ + _DeviceSetGet_t Cmd; + _BasicResponse_t Rsp; +}_SlDeviceMsgSet_u; + +const _SlCmdCtrl_t _SlDeviceSetCmdCtrl = +{ + SL_OPCODE_DEVICE_DEVICESET, + sizeof(_DeviceSetGet_t), + sizeof(_BasicResponse_t) +}; + +#if _SL_INCLUDE_FUNC(sl_DevSet) +_i32 sl_DevSet(_u8 DeviceSetId ,_u8 Option,_u8 ConfigLen, _u8 *pValues) +{ + _SlDeviceMsgSet_u Msg; + _SlCmdExt_t CmdExt; + + CmdExt.TxPayloadLen = (ConfigLen+3) & (~3); + CmdExt.RxPayloadLen = 0; + CmdExt.pTxPayload = (_u8 *)pValues; + CmdExt.pRxPayload = NULL; + + + Msg.Cmd.DeviceSetId = DeviceSetId; + Msg.Cmd.ConfigLen = ConfigLen; + Msg.Cmd.Option = Option; + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlDeviceSetCmdCtrl, &Msg, &CmdExt)); + + return (_i16)Msg.Rsp.status; +} +#endif + + +/****************************************************************************** +_SlDrvDeviceEventHandler - handles internally device async events +******************************************************************************/ +void _SlDrvDeviceEventHandler(void *pArgs) +{ + _SlResponseHeader_t *pHdr = (_SlResponseHeader_t *)pArgs; + + switch(pHdr->GenHeader.Opcode) + { + case SL_OPCODE_DEVICE_INITCOMPLETE: + _sl_HandleAsync_InitComplete(pHdr); + break; + case SL_OPCODE_DEVICE_STOP_ASYNC_RESPONSE: + _sl_HandleAsync_Stop(pHdr); + break; + case SL_OPCODE_DEVICE_DEVICEASYNCFATALERROR: +#ifdef sl_GeneralEvtHdlr + { + _BasicResponse_t *pMsgArgs = (_BasicResponse_t *)_SL_RESP_ARGS_START(pHdr); + SlDeviceEvent_t devHandler; + devHandler.Event = SL_DEVICE_FATAL_ERROR_EVENT; + devHandler.EventData.deviceEvent.status = pMsgArgs->status & 0xFF; + devHandler.EventData.deviceEvent.sender = (SlErrorSender_e)((pMsgArgs->status >> 8) & 0xFF); + sl_GeneralEvtHdlr(&devHandler); + } +#endif + break; + default: + SL_ERROR_TRACE1(MSG_306, "ASSERT: _SlDrvDeviceEventHandler : invalid opcode = 0x%x", pHdr->GenHeader.Opcode); + VERIFY_PROTOCOL(0); + } +} + + +/****************************************************************************** +sl_UartSetMode +******************************************************************************/ +#ifdef SL_IF_TYPE_UART +typedef union +{ + _DevUartSetModeCommand_t Cmd; + _DevUartSetModeResponse_t Rsp; +}_SlUartSetModeMsg_u; + +const _SlCmdCtrl_t _SlUartSetModeCmdCtrl = +{ + SL_OPCODE_DEVICE_SETUARTMODECOMMAND, + sizeof(_DevUartSetModeCommand_t), + sizeof(_DevUartSetModeResponse_t) +}; + + +#if _SL_INCLUDE_FUNC(sl_UartSetMode) +_i16 sl_UartSetMode(const SlUartIfParams_t* pUartParams) +{ + _SlUartSetModeMsg_u Msg; + _u32 magicCode = 0xFFFFFFFF; + + Msg.Cmd.BaudRate = pUartParams->BaudRate; + Msg.Cmd.FlowControlEnable = pUartParams->FlowControlEnable; + + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlUartSetModeCmdCtrl, &Msg, NULL)); + + /* cmd response OK, we can continue with the handshake */ + if (SL_RET_CODE_OK == Msg.Rsp.status) + { + sl_IfMaskIntHdlr(); + + /* Close the comm port */ + sl_IfClose(g_pCB->FD); + + /* Re-open the comm port */ + sl_IfOpen((void * )pUartParams, UART_IF_OPEN_FLAG_RE_OPEN); + + sl_IfUnMaskIntHdlr(); + + /* send the magic code and wait for the response */ + sl_IfWrite(g_pCB->FD, (_u8* )&magicCode, 4); + + magicCode = UART_SET_MODE_MAGIC_CODE; + sl_IfWrite(g_pCB->FD, (_u8* )&magicCode, 4); + + /* clear magic code */ + magicCode = 0; + + /* wait (blocking) till the magic code to be returned from device */ + sl_IfRead(g_pCB->FD, (_u8* )&magicCode, 4); + + /* check for the received magic code matching */ + if (UART_SET_MODE_MAGIC_CODE != magicCode) + { + _SL_ASSERT(0); + } + } + + return (_i16)Msg.Rsp.status; +} +#endif +#endif + + diff --git a/drivers/cc3100/src/driver.c b/drivers/cc3100/src/driver.c new file mode 100644 index 0000000000..62d0aa8f45 --- /dev/null +++ b/drivers/cc3100/src/driver.c @@ -0,0 +1,1520 @@ +/* +* driver.c - CC31xx/CC32xx Host Driver Implementation +* +* Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ +* +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the +* distribution. +* +* Neither the name of Texas Instruments Incorporated nor the names of +* its contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +/*****************************************************************************/ +/* Include files */ +/*****************************************************************************/ +#include "simplelink.h" +#include "protocol.h" +#include "driver.h" +#include "flowcont.h" + +/*****************************************************************************/ +/* Macro declarations */ +/*****************************************************************************/ + +#define _SL_PENDING_RX_MSG(pDriverCB) ((pDriverCB)->RxIrqCnt != (pDriverCB)->RxDoneCnt) + +/* 2 LSB of the N2H_SYNC_PATTERN are for sequence number +only in SPI interface +support backward sync pattern */ +#define N2H_SYNC_PATTERN_SEQ_NUM_BITS ((_u32)0x00000003) /* Bits 0..1 - use the 2 LBS for seq num */ +#define N2H_SYNC_PATTERN_SEQ_NUM_EXISTS ((_u32)0x00000004) /* Bit 2 - sign that sequence number exists in the sync pattern */ +#define N2H_SYNC_PATTERN_MASK ((_u32)0xFFFFFFF8) /* Bits 3..31 - constant SYNC PATTERN */ +#define N2H_SYNC_SPI_BUGS_MASK ((_u32)0x7FFF7F7F) /* Bits 7,15,31 - ignore the SPI (8,16,32 bites bus) error bits */ +#define BUF_SYNC_SPIM(pBuf) ((*(_u32 *)(pBuf)) & N2H_SYNC_SPI_BUGS_MASK) +#define N2H_SYNC_SPIM (N2H_SYNC_PATTERN & N2H_SYNC_SPI_BUGS_MASK) +#define N2H_SYNC_SPIM_WITH_SEQ(TxSeqNum) ((N2H_SYNC_SPIM & N2H_SYNC_PATTERN_MASK) | N2H_SYNC_PATTERN_SEQ_NUM_EXISTS | ((TxSeqNum) & (N2H_SYNC_PATTERN_SEQ_NUM_BITS))) +#define MATCH_WOUT_SEQ_NUM(pBuf) ( BUF_SYNC_SPIM(pBuf) == N2H_SYNC_SPIM ) +#define MATCH_WITH_SEQ_NUM(pBuf, TxSeqNum) ( BUF_SYNC_SPIM(pBuf) == (N2H_SYNC_SPIM_WITH_SEQ(TxSeqNum)) ) +#define N2H_SYNC_PATTERN_MATCH(pBuf, TxSeqNum) \ + ( \ + ( (*((_u32 *)pBuf) & N2H_SYNC_PATTERN_SEQ_NUM_EXISTS) && ( MATCH_WITH_SEQ_NUM(pBuf, TxSeqNum) ) ) || \ + ( !(*((_u32 *)pBuf) & N2H_SYNC_PATTERN_SEQ_NUM_EXISTS) && ( MATCH_WOUT_SEQ_NUM(pBuf ) ) ) \ + ) + +#define OPCODE(_ptr) (((_SlResponseHeader_t *)(_ptr))->GenHeader.Opcode) +#define RSP_PAYLOAD_LEN(_ptr) (((_SlResponseHeader_t *)(_ptr))->GenHeader.Len - _SL_RESP_SPEC_HDR_SIZE) +#define SD(_ptr) (((_SocketAddrResponse_u *)(_ptr))->IpV4.sd) +/* Actual size of Recv/Recvfrom response data */ +#define ACT_DATA_SIZE(_ptr) (((_SocketAddrResponse_u *)(_ptr))->IpV4.statusOrLen) + +#if (SL_MEMORY_MGMT == SL_MEMORY_MGMT_STATIC) +typedef struct +{ + _u32 Align; + _SlDriverCb_t DriverCB; + _u8 AsyncRespBuf[SL_ASYNC_MAX_MSG_LEN]; +}_SlStatMem_t; + +_SlStatMem_t g_StatMem; +#endif + +/*****************************************************************************/ +/* Variables */ +/*****************************************************************************/ +const _SlSyncPattern_t g_H2NSyncPattern = H2N_SYNC_PATTERN; +const _SlSyncPattern_t g_H2NCnysPattern = H2N_CNYS_PATTERN; +const _SlActionLookup_t _SlActionLookupTable[7] = +{ + {ACCEPT_ID, SL_OPCODE_SOCKET_ACCEPTASYNCRESPONSE, (_SlSpawnEntryFunc_t)_sl_HandleAsync_Accept}, + {CONNECT_ID, SL_OPCODE_SOCKET_CONNECTASYNCRESPONSE,(_SlSpawnEntryFunc_t)_sl_HandleAsync_Connect}, + {SELECT_ID, SL_OPCODE_SOCKET_SELECTASYNCRESPONSE,(_SlSpawnEntryFunc_t)_sl_HandleAsync_Select}, + {GETHOSYBYNAME_ID, SL_OPCODE_NETAPP_DNSGETHOSTBYNAMEASYNCRESPONSE,(_SlSpawnEntryFunc_t)_sl_HandleAsync_DnsGetHostByName}, + {GETHOSYBYSERVICE_ID, SL_OPCODE_NETAPP_MDNSGETHOSTBYSERVICEASYNCRESPONSE,(_SlSpawnEntryFunc_t)_sl_HandleAsync_DnsGetHostByService}, + {PING_ID, SL_OPCODE_NETAPP_PINGREPORTREQUESTRESPONSE, (_SlSpawnEntryFunc_t)_sl_HandleAsync_PingResponse}, + {START_STOP_ID, SL_OPCODE_DEVICE_STOP_ASYNC_RESPONSE,(_SlSpawnEntryFunc_t)_sl_HandleAsync_Stop} + +}; + +_SlDriverCb_t* g_pCB = NULL; +P_SL_DEV_PING_CALLBACK pPingCallBackFunc = NULL; +_u8 gFirstCmdMode = 0; + +/*****************************************************************************/ +/* Function prototypes */ +/*****************************************************************************/ +_SlReturnVal_t _SlDrvMsgRead(void); +_SlReturnVal_t _SlDrvMsgWrite(void); +_SlReturnVal_t _SlDrvMsgReadCmdCtx(void); +_SlReturnVal_t _SlDrvMsgReadSpawnCtx(void *pValue); +void _SlDrvClassifyRxMsg(_SlOpcode_t Opcode ); +_SlReturnVal_t _SlDrvRxHdrRead(_u8 *pBuf, _u8 *pAlignSize); +void _SlDrvShiftDWord(_u8 *pBuf); +void _SlDrvDriverCBInit(void); +void _SlAsyncEventGenericHandler(void); +_i16 _SlDrvWaitForPoolObj(_u32 ActionID, _u8 SocketID); +void _SlDrvReleasePoolObj(_u8 pObj); +void _SlDrvObjInit(void); +void _SlDrvObjDeInit(void); +void _SlRemoveFromList(_u8* ListIndex, _u8 ItemIndex); +_SlReturnVal_t _SlFindAndSetActiveObj(_SlOpcode_t Opcode, _u8 Sd); + + +/*****************************************************************************/ +/* Internal functions */ +/*****************************************************************************/ + + + +/***************************************************************************** +_SlDrvDriverCBInit - init Driver Control Block +*****************************************************************************/ +void _SlDrvDriverCBInit(void) +{ + _u8 Idx; + +#if (SL_MEMORY_MGMT == SL_MEMORY_MGMT_STATIC) + g_pCB = &(g_StatMem.DriverCB); +#else + g_pCB = sl_Malloc(sizeof(_SlDriverCb_t)); +#endif + MALLOC_OK_CHECK(g_pCB); + + sl_Memset((g_pCB), 0, sizeof(_SlDriverCb_t)); + + OSI_RET_OK_CHECK( sl_SyncObjCreate(&g_pCB->CmdSyncObj, "CmdSyncObj") ); + sl_SyncObjClear(&g_pCB->CmdSyncObj); + + OSI_RET_OK_CHECK( sl_LockObjCreate(&g_pCB->GlobalLockObj, "GlobalLockObj") ); + + OSI_RET_OK_CHECK( sl_LockObjCreate(&g_pCB->ProtectionLockObj, "ProtectionLockObj") ); + + _SlDrvObjInit(); + + for (Idx = 0; Idx < MAX_CONCURRENT_ACTIONS; Idx++) + { + OSI_RET_OK_CHECK( sl_SyncObjCreate(&g_pCB->ObjPool[Idx].SyncObj, "SyncObj") ); + sl_SyncObjClear(&g_pCB->ObjPool[Idx].SyncObj); + } + _SlDrvFlowContInit(); + gFirstCmdMode = 0; +} + +/***************************************************************************** +_SlDrvDriverCBDeinit - De init Driver Control Block +*****************************************************************************/ +void _SlDrvDriverCBDeinit() +{ + _u8 Idx; + + _SlDrvFlowContDeinit(); + + OSI_RET_OK_CHECK( sl_SyncObjDelete(&g_pCB->CmdSyncObj) ); + + OSI_RET_OK_CHECK( sl_LockObjDelete(&g_pCB->GlobalLockObj) ); + + OSI_RET_OK_CHECK( sl_LockObjDelete(&g_pCB->ProtectionLockObj) ); + for (Idx = 0; Idx < MAX_CONCURRENT_ACTIONS; Idx++) + { + OSI_RET_OK_CHECK( sl_SyncObjDelete(&g_pCB->ObjPool[Idx].SyncObj) ); + } + + _SlDrvObjDeInit(); + +#if (SL_MEMORY_MGMT == SL_MEMORY_MGMT_STATIC) + g_pCB = NULL; +#else + sl_Free(g_pCB); +#endif + + g_pCB = NULL; +} + +/***************************************************************************** +_SlDrvRxIrqHandler - Interrupt handler +*****************************************************************************/ +void _SlDrvRxIrqHandler(void *pValue) +{ + sl_IfMaskIntHdlr(); + + g_pCB->RxIrqCnt++; + + if (TRUE == g_pCB->IsCmdRespWaited) + { + OSI_RET_OK_CHECK( sl_SyncObjSignalFromIRQ(&g_pCB->CmdSyncObj) ); + } + else + { + sl_Spawn((_SlSpawnEntryFunc_t)_SlDrvMsgReadSpawnCtx, NULL, 0); + } +} + +/***************************************************************************** +_SlDrvCmdOp +*****************************************************************************/ +_SlReturnVal_t _SlDrvCmdOp( + _SlCmdCtrl_t *pCmdCtrl , + void *pTxRxDescBuff , + _SlCmdExt_t *pCmdExt) +{ + _SlReturnVal_t RetVal; + + OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->GlobalLockObj, SL_OS_WAIT_FOREVER)); + g_pCB->IsCmdRespWaited = TRUE; + + SL_TRACE0(DBG_MSG, MSG_312, "_SlDrvCmdOp: call _SlDrvMsgWrite"); + /* send the message */ + g_pCB->FunctionParams.pCmdCtrl = pCmdCtrl; + g_pCB->FunctionParams.pTxRxDescBuff = pTxRxDescBuff; + g_pCB->FunctionParams.pCmdExt = pCmdExt; + + RetVal = _SlDrvMsgWrite(); + + if(SL_OS_RET_CODE_OK == RetVal) + { + +#ifndef SL_IF_TYPE_UART + /* Waiting for SPI to stabilize after first command */ + if( 0 == gFirstCmdMode ) + { + volatile _u32 CountVal = 0; + gFirstCmdMode = 1; + CountVal = CPU_FREQ_IN_MHZ*USEC_DELAY; + while( CountVal-- ); + } +#endif + /* wait for respond */ + RetVal = _SlDrvMsgReadCmdCtx(); /* will free global lock */ + SL_TRACE0(DBG_MSG, MSG_314, "_SlDrvCmdOp: exited _SlDrvMsgReadCmdCtx"); + + } + else + { + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->GlobalLockObj)); + } + + return RetVal; +} + +/***************************************************************************** +_SlDrvCmdSend +Send SL command without waiting for command response +This function is unprotected and the caller should make +sure global lock is active +*****************************************************************************/ +_SlReturnVal_t _SlDrvCmdSend( + _SlCmdCtrl_t *pCmdCtrl , + void *pTxRxDescBuff , + _SlCmdExt_t *pCmdExt) +{ + _SlReturnVal_t RetVal; + + g_pCB->IsCmdRespWaited = FALSE; + + SL_TRACE0(DBG_MSG, MSG_312, "_SlDrvCmdSend: call _SlDrvMsgWrite"); + /* send the message */ + g_pCB->FunctionParams.pCmdCtrl = pCmdCtrl; + g_pCB->FunctionParams.pTxRxDescBuff = pTxRxDescBuff; + g_pCB->FunctionParams.pCmdExt = pCmdExt; + + RetVal = _SlDrvMsgWrite(); + + return RetVal; +} + +/***************************************************************************** +_SlDrvDataReadOp +*****************************************************************************/ +_SlReturnVal_t _SlDrvDataReadOp( + _SlSd_t Sd, + _SlCmdCtrl_t *pCmdCtrl , + void *pTxRxDescBuff , + _SlCmdExt_t *pCmdExt) +{ + _SlReturnVal_t RetVal; + _u8 ObjIdx = MAX_CONCURRENT_ACTIONS; + _SlArgsData_t pArgsData; + + /* Validate input arguments */ + VERIFY_PROTOCOL(NULL != pCmdExt->pRxPayload); + + /* If zero bytes is requested, return error. */ + /* This allows us not to fill remote socket's IP address in return arguments */ + VERIFY_PROTOCOL(0 != pCmdExt->RxPayloadLen); + + /* Validate socket */ + if((Sd & BSD_SOCKET_ID_MASK) >= SL_MAX_SOCKETS) + { + return SL_EBADF; + } + + /*Use Obj to issue the command, if not available try later*/ + ObjIdx = (_u8)_SlDrvWaitForPoolObj(RECV_ID, Sd & BSD_SOCKET_ID_MASK); + + if (MAX_CONCURRENT_ACTIONS == ObjIdx) + { + return SL_POOL_IS_EMPTY; + } + + OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); + + pArgsData.pData = pCmdExt->pRxPayload; + pArgsData.pArgs = (_u8 *)pTxRxDescBuff; + g_pCB->ObjPool[ObjIdx].pRespArgs = (_u8 *)&pArgsData; + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); + + + /* Do Flow Control check/update for DataWrite operation */ + OSI_RET_OK_CHECK( sl_LockObjLock(&g_pCB->FlowContCB.TxLockObj, SL_OS_WAIT_FOREVER) ); + + /* Clear SyncObj for the case it was signalled before TxPoolCnt */ + /* dropped below '1' (last Data buffer was taken) */ + /* OSI_RET_OK_CHECK( sl_SyncObjClear(&g_pCB->FlowContCB.TxSyncObj) ); */ + sl_SyncObjClear(&g_pCB->FlowContCB.TxSyncObj); + + if(g_pCB->FlowContCB.TxPoolCnt <= FLOW_CONT_MIN) + { + + /* If TxPoolCnt was increased by other thread at this moment, + TxSyncObj won't wait here */ + OSI_RET_OK_CHECK( sl_SyncObjWait(&g_pCB->FlowContCB.TxSyncObj, SL_OS_WAIT_FOREVER) ); + } + + OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->GlobalLockObj, SL_OS_WAIT_FOREVER)); + + VERIFY_PROTOCOL(g_pCB->FlowContCB.TxPoolCnt > FLOW_CONT_MIN); + g_pCB->FlowContCB.TxPoolCnt--; + + OSI_RET_OK_CHECK( sl_LockObjUnlock(&g_pCB->FlowContCB.TxLockObj) ); + + /* send the message */ + g_pCB->TempProtocolHeader.Opcode = pCmdCtrl->Opcode; + g_pCB->TempProtocolHeader.Len = _SL_PROTOCOL_CALC_LEN(pCmdCtrl,pCmdExt); + g_pCB->FunctionParams.pCmdCtrl = pCmdCtrl; + g_pCB->FunctionParams.pTxRxDescBuff = (_u8 *)pTxRxDescBuff; + g_pCB->FunctionParams.pCmdExt = pCmdExt; + RetVal = _SlDrvMsgWrite(); + + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->GlobalLockObj)); + + if(SL_OS_RET_CODE_OK == RetVal) + { + /* Wait for response message. Will be signalled by _SlDrvMsgRead. */ + OSI_RET_OK_CHECK(sl_SyncObjWait(&g_pCB->ObjPool[ObjIdx].SyncObj, SL_OS_WAIT_FOREVER)); + } + + _SlDrvReleasePoolObj(ObjIdx); + return RetVal; +} + +/* ******************************************************************************/ +/* _SlDrvDataWriteOp */ +/* ******************************************************************************/ +_SlReturnVal_t _SlDrvDataWriteOp( + _SlSd_t Sd, + _SlCmdCtrl_t *pCmdCtrl , + void *pTxRxDescBuff , + _SlCmdExt_t *pCmdExt) +{ + _SlReturnVal_t RetVal = SL_EAGAIN; /* initiated as SL_EAGAIN for the non blocking mode */ + while( 1 ) + { + /* Do Flow Control check/update for DataWrite operation */ + OSI_RET_OK_CHECK( sl_LockObjLock(&g_pCB->FlowContCB.TxLockObj, SL_OS_WAIT_FOREVER) ); + + /* Clear SyncObj for the case it was signalled before TxPoolCnt */ + /* dropped below '1' (last Data buffer was taken) */ + /* OSI_RET_OK_CHECK( sl_SyncObjClear(&g_pCB->FlowContCB.TxSyncObj) ); */ + sl_SyncObjClear(&g_pCB->FlowContCB.TxSyncObj); + + /* we have indication that the last send has failed - socket is no longer valid for operations */ + if(g_pCB->SocketTXFailure & (1<<(Sd & BSD_SOCKET_ID_MASK))) + { + OSI_RET_OK_CHECK( sl_LockObjUnlock(&g_pCB->FlowContCB.TxLockObj) ); + return SL_SOC_ERROR; + } + if(g_pCB->FlowContCB.TxPoolCnt <= FLOW_CONT_MIN + 1) + { + /* we have indication that this socket is set as blocking and we try to */ + /* unblock it - return an error */ + if( g_pCB->SocketNonBlocking >> (Sd & BSD_SOCKET_ID_MASK) ) + { + OSI_RET_OK_CHECK( sl_LockObjUnlock(&g_pCB->FlowContCB.TxLockObj) ); + return RetVal; + } + /* If TxPoolCnt was increased by other thread at this moment, */ + /* TxSyncObj won't wait here */ + OSI_RET_OK_CHECK( sl_SyncObjWait(&g_pCB->FlowContCB.TxSyncObj, SL_OS_WAIT_FOREVER) ); + } + if(g_pCB->FlowContCB.TxPoolCnt > FLOW_CONT_MIN + 1 ) + { + break; + } + else + { + OSI_RET_OK_CHECK( sl_LockObjUnlock(&g_pCB->FlowContCB.TxLockObj) ); + } + } + OSI_RET_OK_CHECK( sl_LockObjLock(&g_pCB->GlobalLockObj, SL_OS_WAIT_FOREVER) ); + + VERIFY_PROTOCOL(g_pCB->FlowContCB.TxPoolCnt > FLOW_CONT_MIN + 1 ); + g_pCB->FlowContCB.TxPoolCnt--; + + OSI_RET_OK_CHECK( sl_LockObjUnlock(&g_pCB->FlowContCB.TxLockObj) ); + + /* send the message */ + g_pCB->TempProtocolHeader.Opcode = pCmdCtrl->Opcode; + g_pCB->TempProtocolHeader.Len = _SL_PROTOCOL_CALC_LEN(pCmdCtrl,pCmdExt); + + g_pCB->FunctionParams.pCmdCtrl = pCmdCtrl; + g_pCB->FunctionParams.pTxRxDescBuff = pTxRxDescBuff; + g_pCB->FunctionParams.pCmdExt = pCmdExt; + RetVal = _SlDrvMsgWrite(); + + OSI_RET_OK_CHECK( sl_LockObjUnlock(&g_pCB->GlobalLockObj) ); + + return RetVal; +} + +/* ******************************************************************************/ +/* _SlDrvMsgWrite */ +/* ******************************************************************************/ +_SlReturnVal_t _SlDrvMsgWrite(void) +{ + VERIFY_PROTOCOL(NULL != g_pCB->FunctionParams.pCmdCtrl); + + g_pCB->TempProtocolHeader.Opcode = g_pCB->FunctionParams.pCmdCtrl->Opcode; + g_pCB->TempProtocolHeader.Len = _SL_PROTOCOL_CALC_LEN(g_pCB->FunctionParams.pCmdCtrl, + g_pCB->FunctionParams.pCmdExt); + /* */ + if (g_pCB->RelayFlagsViaRxPayload == TRUE) + { + g_pCB->TempProtocolHeader.Len = g_pCB->TempProtocolHeader.Len + g_pCB->FunctionParams.pCmdExt->RxPayloadLen; + } + +#ifdef SL_START_WRITE_STAT + sl_IfStartWriteSequence(g_pCB->FD); +#endif + +#ifdef SL_IF_TYPE_UART + /* Write long sync pattern */ + NWP_IF_WRITE_CHECK(g_pCB->FD, (_u8 *)&g_H2NSyncPattern.Long, 2*SYNC_PATTERN_LEN); +#else + /* Write short sync pattern */ + NWP_IF_WRITE_CHECK(g_pCB->FD, (_u8 *)&g_H2NSyncPattern.Short, SYNC_PATTERN_LEN); +#endif + + /* Header */ + NWP_IF_WRITE_CHECK(g_pCB->FD, (_u8 *)&g_pCB->TempProtocolHeader, _SL_CMD_HDR_SIZE); + + /* Descriptors */ + if (g_pCB->FunctionParams.pTxRxDescBuff && g_pCB->FunctionParams.pCmdCtrl->TxDescLen > 0) + { + NWP_IF_WRITE_CHECK(g_pCB->FD, g_pCB->FunctionParams.pTxRxDescBuff, + _SL_PROTOCOL_ALIGN_SIZE(g_pCB->FunctionParams.pCmdCtrl->TxDescLen)); + } + + /* A special mode where Rx payload and Rx length are used as Tx as well */ + /* This mode requires no Rx payload on the response and currently used by fs_Close and sl_Send on */ + /* transceiver mode */ + if (g_pCB->RelayFlagsViaRxPayload == TRUE ) + { + g_pCB->RelayFlagsViaRxPayload = FALSE; + NWP_IF_WRITE_CHECK(g_pCB->FD, g_pCB->FunctionParams.pCmdExt->pRxPayload, + _SL_PROTOCOL_ALIGN_SIZE(g_pCB->FunctionParams.pCmdExt->RxPayloadLen)); + } + + /* Payload */ + if (g_pCB->FunctionParams.pCmdExt && g_pCB->FunctionParams.pCmdExt->TxPayloadLen > 0) + { + /* If the message has payload, it is mandatory that the message's arguments are protocol aligned. */ + /* Otherwise the aligning of arguments will create a gap between arguments and payload. */ + VERIFY_PROTOCOL(_SL_IS_PROTOCOL_ALIGNED_SIZE(g_pCB->FunctionParams.pCmdCtrl->TxDescLen)); + + NWP_IF_WRITE_CHECK(g_pCB->FD, g_pCB->FunctionParams.pCmdExt->pTxPayload, + _SL_PROTOCOL_ALIGN_SIZE(g_pCB->FunctionParams.pCmdExt->TxPayloadLen)); + } + + + _SL_DBG_CNT_INC(MsgCnt.Write); + +#ifdef SL_START_WRITE_STAT + sl_IfEndWriteSequence(g_pCB->FD); +#endif + + return SL_OS_RET_CODE_OK; +} + +/* ******************************************************************************/ +/* _SlDrvMsgRead */ +/* ******************************************************************************/ +_SlReturnVal_t _SlDrvMsgRead(void) +{ + /* alignment for small memory models */ + union + { + _u8 TempBuf[_SL_RESP_HDR_SIZE]; + _u32 DummyBuf[2]; + } uBuf; + _u8 TailBuffer[4]; + _u16 LengthToCopy; + _u16 AlignedLengthRecv; + _u8 AlignSize; + + VERIFY_RET_OK(_SlDrvRxHdrRead((_u8*)(uBuf.TempBuf), &AlignSize)); + + /* 'Init Compelete' message bears no valid FlowControl info */ + if(SL_OPCODE_DEVICE_INITCOMPLETE != OPCODE(uBuf.TempBuf)) + { + g_pCB->FlowContCB.TxPoolCnt = ((_SlResponseHeader_t *)uBuf.TempBuf)->TxPoolCnt; + g_pCB->SocketNonBlocking = ((_SlResponseHeader_t *)uBuf.TempBuf)->SocketNonBlocking; + g_pCB->SocketTXFailure = ((_SlResponseHeader_t *)uBuf.TempBuf)->SocketTXFailure; + + if(g_pCB->FlowContCB.TxPoolCnt > FLOW_CONT_MIN) + { + OSI_RET_OK_CHECK(sl_SyncObjSignal(&g_pCB->FlowContCB.TxSyncObj)); + } + } + + _SlDrvClassifyRxMsg(OPCODE(uBuf.TempBuf)); + + switch(g_pCB->FunctionParams.AsyncExt.RxMsgClass) + { + case ASYNC_EVT_CLASS: + + VERIFY_PROTOCOL(NULL == g_pCB->FunctionParams.AsyncExt.pAsyncBuf); + +#if (SL_MEMORY_MGMT == SL_MEMORY_MGMT_STATIC) + g_pCB->FunctionParams.AsyncExt.pAsyncBuf = g_StatMem.AsyncRespBuf; +#else + g_pCB->FunctionParams.AsyncExt.pAsyncBuf = sl_Malloc(SL_ASYNC_MAX_MSG_LEN); +#endif + MALLOC_OK_CHECK(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); + + sl_Memcpy(g_pCB->FunctionParams.AsyncExt.pAsyncBuf, uBuf.TempBuf, _SL_RESP_HDR_SIZE); + + /* This is an Async message. Read the rest of it. */ + if (_SL_PROTOCOL_ALIGN_SIZE(RSP_PAYLOAD_LEN(uBuf.TempBuf)) <= SL_ASYNC_MAX_PAYLOAD_LEN) + { + AlignedLengthRecv = _SL_PROTOCOL_ALIGN_SIZE(RSP_PAYLOAD_LEN(uBuf.TempBuf)); + } + else + { + AlignedLengthRecv = _SL_PROTOCOL_ALIGN_SIZE(SL_ASYNC_MAX_PAYLOAD_LEN); + } + + if (RSP_PAYLOAD_LEN(uBuf.TempBuf) > 0) + { + NWP_IF_READ_CHECK(g_pCB->FD, + g_pCB->FunctionParams.AsyncExt.pAsyncBuf + _SL_RESP_HDR_SIZE, + AlignedLengthRecv); + } + /* In case ASYNC RX buffer length is smaller then the received data length, dump the rest */ + if ((_SL_PROTOCOL_ALIGN_SIZE(RSP_PAYLOAD_LEN(uBuf.TempBuf)) > SL_ASYNC_MAX_PAYLOAD_LEN)) + { + AlignedLengthRecv = _SL_PROTOCOL_ALIGN_SIZE(RSP_PAYLOAD_LEN(uBuf.TempBuf)) - SL_ASYNC_MAX_PAYLOAD_LEN; + while (AlignedLengthRecv > 0) + { + NWP_IF_READ_CHECK(g_pCB->FD,TailBuffer,4); + AlignedLengthRecv = AlignedLengthRecv - 4; + } + } + OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); + + if ((SL_OPCODE_SOCKET_ACCEPTASYNCRESPONSE == OPCODE(uBuf.TempBuf)) || (SL_OPCODE_SOCKET_ACCEPTASYNCRESPONSE_V6 == OPCODE(uBuf.TempBuf)) || (SL_OPCODE_SOCKET_CONNECTASYNCRESPONSE == OPCODE(uBuf.TempBuf))) + { + /* go over the active list if exist to find obj waiting for this Async event */ + _SlFindAndSetActiveObj(OPCODE(uBuf.TempBuf),(((_SocketResponse_t *)(g_pCB->FunctionParams.AsyncExt.pAsyncBuf + _SL_RESP_HDR_SIZE))->sd) & BSD_SOCKET_ID_MASK); + } + else + { + _SlFindAndSetActiveObj(OPCODE(uBuf.TempBuf),SL_MAX_SOCKETS); + } + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); + + break; + + case RECV_RESP_CLASS: + { + _u8 ExpArgSize; /* Expected size of Recv/Recvfrom arguments */ + + switch(OPCODE(uBuf.TempBuf)) + { + case SL_OPCODE_SOCKET_RECVFROMASYNCRESPONSE: + ExpArgSize = RECVFROM_IPV4_ARGS_SIZE; + break; + case SL_OPCODE_SOCKET_RECVFROMASYNCRESPONSE_V6: + ExpArgSize = RECVFROM_IPV6_ARGS_SIZE; + break; + default: + /* SL_OPCODE_SOCKET_RECVASYNCRESPONSE: */ + ExpArgSize = RECV_ARGS_SIZE; + } + + /* Read first 4 bytes of Recv/Recvfrom response to get SocketId and actual */ + /* response data length */ + NWP_IF_READ_CHECK(g_pCB->FD, &uBuf.TempBuf[4], RECV_ARGS_SIZE); + + /* Validate Socket ID and Received Length value. */ + VERIFY_PROTOCOL((SD(&uBuf.TempBuf[4])& BSD_SOCKET_ID_MASK) < SL_MAX_SOCKETS); + + OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); + + /* go over the active list if exist to find obj waiting for this Async event */ + VERIFY_RET_OK(_SlFindAndSetActiveObj(OPCODE(uBuf.TempBuf),SD(&uBuf.TempBuf[4]) & BSD_SOCKET_ID_MASK)); + + /* Verify data is waited on this socket. The pArgs should have been set by _SlDrvDataReadOp(). */ + VERIFY_SOCKET_CB(NULL != ((_SlArgsData_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pData))->pArgs); + + sl_Memcpy( ((_SlArgsData_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->pArgs, &uBuf.TempBuf[4], RECV_ARGS_SIZE); + + if(ExpArgSize > RECV_ARGS_SIZE) + { + NWP_IF_READ_CHECK(g_pCB->FD, + ((_SlArgsData_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->pArgs + RECV_ARGS_SIZE, + ExpArgSize - RECV_ARGS_SIZE); + } + + /* Here g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pData contains requested(expected) Recv/Recvfrom DataSize. */ + /* Overwrite requested DataSize with actual one. */ + /* If error is received, this information will be read from arguments. */ + if(ACT_DATA_SIZE(&uBuf.TempBuf[4]) > 0) + { + VERIFY_SOCKET_CB(NULL != ((_SlArgsData_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->pData); + + /* Read 4 bytes aligned from interface */ + /* therefore check the requested length and read only */ + /* 4 bytes aligned data. The rest unaligned (if any) will be read */ + /* and copied to a TailBuffer */ + LengthToCopy = ACT_DATA_SIZE(&uBuf.TempBuf[4]) & (3); + AlignedLengthRecv = ACT_DATA_SIZE(&uBuf.TempBuf[4]) & (~3); + if( AlignedLengthRecv >= 4) + { + NWP_IF_READ_CHECK(g_pCB->FD,((_SlArgsData_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->pData,AlignedLengthRecv ); + } + /* copy the unaligned part, if any */ + if( LengthToCopy > 0) + { + NWP_IF_READ_CHECK(g_pCB->FD,TailBuffer,4); + /* copy TailBuffer unaligned part (1/2/3 bytes) */ + sl_Memcpy(((_SlArgsData_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->pData + AlignedLengthRecv,TailBuffer,LengthToCopy); + } + } + OSI_RET_OK_CHECK(sl_SyncObjSignal(&(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj))); + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); + } + break; + + case CMD_RESP_CLASS: + + /* Some commands pass a maximum arguments size. */ + /* In this case Driver will send extra dummy patterns to NWP if */ + /* the response message is smaller than maximum. */ + /* When RxDescLen is not exact, using RxPayloadLen is forbidden! */ + /* If such case cannot be avoided - parse message here to detect */ + /* arguments/payload border. */ + NWP_IF_READ_CHECK(g_pCB->FD, + g_pCB->FunctionParams.pTxRxDescBuff, + _SL_PROTOCOL_ALIGN_SIZE(g_pCB->FunctionParams.pCmdCtrl->RxDescLen)); + + if((NULL != g_pCB->FunctionParams.pCmdExt) && (0 != g_pCB->FunctionParams.pCmdExt->RxPayloadLen)) + { + /* Actual size of command's response payload: <msg_payload_len> - <rsp_args_len> */ + _i16 ActDataSize = RSP_PAYLOAD_LEN(uBuf.TempBuf) - g_pCB->FunctionParams.pCmdCtrl->RxDescLen; + + g_pCB->FunctionParams.pCmdExt->ActualRxPayloadLen = ActDataSize; + + /* Check that the space prepared by user for the response data is sufficient. */ + if(ActDataSize <= 0) + { + g_pCB->FunctionParams.pCmdExt->RxPayloadLen = 0; + } + else + { + /* In case the user supplied Rx buffer length which is smaller then the received data length, copy according to user length */ + if (ActDataSize > g_pCB->FunctionParams.pCmdExt->RxPayloadLen) + { + LengthToCopy = g_pCB->FunctionParams.pCmdExt->RxPayloadLen & (3); + AlignedLengthRecv = g_pCB->FunctionParams.pCmdExt->RxPayloadLen & (~3); + } + else + { + LengthToCopy = ActDataSize & (3); + AlignedLengthRecv = ActDataSize & (~3); + } + /* Read 4 bytes aligned from interface */ + /* therefore check the requested length and read only */ + /* 4 bytes aligned data. The rest unaligned (if any) will be read */ + /* and copied to a TailBuffer */ + + if( AlignedLengthRecv >= 4) + { + NWP_IF_READ_CHECK(g_pCB->FD, + g_pCB->FunctionParams.pCmdExt->pRxPayload, + AlignedLengthRecv ); + + } + /* copy the unaligned part, if any */ + if( LengthToCopy > 0) + { + NWP_IF_READ_CHECK(g_pCB->FD,TailBuffer,4); + /* copy TailBuffer unaligned part (1/2/3 bytes) */ + sl_Memcpy(g_pCB->FunctionParams.pCmdExt->pRxPayload + AlignedLengthRecv, + TailBuffer, + LengthToCopy); + ActDataSize = ActDataSize-4; + } + /* In case the user supplied Rx buffer length which is smaller then the received data length, dump the rest */ + if (ActDataSize > g_pCB->FunctionParams.pCmdExt->RxPayloadLen) + { + /* calculate the rest of the data size to dump */ + AlignedLengthRecv = ActDataSize - (g_pCB->FunctionParams.pCmdExt->RxPayloadLen & (~3)); + while( AlignedLengthRecv > 0) + { + NWP_IF_READ_CHECK(g_pCB->FD,TailBuffer, 4 ); + AlignedLengthRecv = AlignedLengthRecv - 4; + } + } + } + } + break; + + default: + /* DUMMY_MSG_CLASS: Flow control message has no payload. */ + break; + } + + if(AlignSize > 0) + { + NWP_IF_READ_CHECK(g_pCB->FD, uBuf.TempBuf, AlignSize); + } + + _SL_DBG_CNT_INC(MsgCnt.Read); + + /* Unmask Interrupt call */ + sl_IfUnMaskIntHdlr(); + + return SL_OS_RET_CODE_OK; +} + +/* ******************************************************************************/ +/* _SlAsyncEventGenericHandler */ +/* ******************************************************************************/ +void _SlAsyncEventGenericHandler(void) +{ + _SlResponseHeader_t *pHdr = (_SlResponseHeader_t *)g_pCB->FunctionParams.AsyncExt.pAsyncBuf; + SlWlanEvent_t wlanEvent; + SlNetAppEvent_t netAppEvent; + SlSockEvent_t sockAppEvent; + + if (NULL != g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler) + { + switch(pHdr->GenHeader.Opcode) + { + case SL_OPCODE_WLAN_P2P_DEV_FOUND: + { + slPeerInfoAsyncResponse_t* pResp = (slPeerInfoAsyncResponse_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); + wlanEvent.Event = SL_WLAN_P2P_DEV_FOUND_EVENT; + sl_Memcpy(wlanEvent.EventData.P2PModeDevFound.mac,pResp->mac, 6); + sl_Memcpy(wlanEvent.EventData.P2PModeDevFound.go_peer_device_name,pResp->go_peer_device_name,pResp->go_peer_device_name_len); + wlanEvent.EventData.P2PModeDevFound.go_peer_device_name_len = pResp->go_peer_device_name_len; + g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&wlanEvent); + break; + } + + case SL_OPCODE_WLAN_P2P_NEG_REQ_RECEIVED: + { + slPeerInfoAsyncResponse_t* pResp = (slPeerInfoAsyncResponse_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); + + wlanEvent.Event = SL_WLAN_P2P_NEG_REQ_RECEIVED_EVENT; + sl_Memcpy(wlanEvent.EventData.P2PModeNegReqReceived.mac,pResp->mac, 6); + sl_Memcpy(wlanEvent.EventData.P2PModeNegReqReceived.go_peer_device_name,pResp->go_peer_device_name,pResp->go_peer_device_name_len); + wlanEvent.EventData.P2PModeNegReqReceived.go_peer_device_name_len = pResp->go_peer_device_name_len; + wlanEvent.EventData.P2PModeNegReqReceived.wps_dev_password_id = pResp->wps_dev_password_id; + g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&wlanEvent); + break; + } + case SL_OPCODE_WLAN_CONNECTION_FAILED: + { + slWlanConnFailureAsyncResponse_t * pResp = (slWlanConnFailureAsyncResponse_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); + + wlanEvent.Event = SL_WLAN_CONNECTION_FAILED_EVENT; + wlanEvent.EventData.P2PModewlanConnectionFailure.status = pResp->status; + + g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&wlanEvent); + break; + } + + case SL_OPCODE_WLAN_WLANASYNCCONNECTEDRESPONSE: + { + slWlanConnectAsyncResponse_t *pWlanResp = (slWlanConnectAsyncResponse_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); + sl_Memset(&wlanEvent.EventData.STAandP2PModeWlanConnected,0,sizeof(slWlanConnectAsyncResponse_t)); + wlanEvent.Event = SL_WLAN_CONNECT_EVENT; + wlanEvent.EventData.STAandP2PModeWlanConnected.connection_type = pWlanResp->connection_type; + sl_Memcpy(wlanEvent.EventData.STAandP2PModeWlanConnected.bssid, pWlanResp->bssid, 6); + sl_Memcpy(wlanEvent.EventData.STAandP2PModeWlanConnected.go_peer_device_name,pWlanResp->go_peer_device_name,pWlanResp->go_peer_device_name_len); + sl_Memcpy(wlanEvent.EventData.STAandP2PModeWlanConnected.ssid_name, pWlanResp->ssid_name, pWlanResp->ssid_len); + wlanEvent.EventData.STAandP2PModeWlanConnected.ssid_len = pWlanResp->ssid_len; + wlanEvent.EventData.STAandP2PModeWlanConnected.go_peer_device_name_len = pWlanResp->go_peer_device_name_len; + + g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&wlanEvent); + break; + } + case SL_OPCODE_WLAN_WLANASYNCDISCONNECTEDRESPONSE: + { + slWlanConnectAsyncResponse_t *pWlanResp = (slWlanConnectAsyncResponse_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); + sl_Memset(&wlanEvent.EventData.STAandP2PModeDisconnected,0,sizeof(slWlanConnectAsyncResponse_t)); + wlanEvent.Event = SL_WLAN_DISCONNECT_EVENT; + wlanEvent.EventData.STAandP2PModeDisconnected.connection_type = pWlanResp->connection_type; + sl_Memcpy(wlanEvent.EventData.STAandP2PModeDisconnected.bssid, pWlanResp->bssid, 6); + sl_Memcpy(wlanEvent.EventData.STAandP2PModeDisconnected.go_peer_device_name,pWlanResp->go_peer_device_name,pWlanResp->go_peer_device_name_len); + sl_Memcpy(wlanEvent.EventData.STAandP2PModeDisconnected.ssid_name, pWlanResp->ssid_name, pWlanResp->ssid_len); + wlanEvent.EventData.STAandP2PModeDisconnected.ssid_len = pWlanResp->ssid_len; + wlanEvent.EventData.STAandP2PModeDisconnected.reason_code = pWlanResp->reason_code; + wlanEvent.EventData.STAandP2PModeDisconnected.go_peer_device_name_len = pWlanResp->go_peer_device_name_len; + g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&wlanEvent); + break; + } + case SL_OPCODE_NETAPP_IPACQUIRED: + { + SlIpV4AcquiredAsync_t *pIpV4 = (SlIpV4AcquiredAsync_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); + netAppEvent.Event = SL_NETAPP_IPV4_IPACQUIRED_EVENT; + netAppEvent.EventData.ipAcquiredV4.ip = pIpV4->ip; + netAppEvent.EventData.ipAcquiredV4.gateway = pIpV4->gateway; + netAppEvent.EventData.ipAcquiredV4.dns = pIpV4->dns; + g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&netAppEvent); + } + break; + case SL_OPCODE_NETAPP_IPACQUIRED_V6: + { + SlIpV6AcquiredAsync_t *pIpV6 = (SlIpV6AcquiredAsync_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); + netAppEvent.Event = SL_NETAPP_IPV6_IPACQUIRED_EVENT; + sl_Memcpy((void *)&netAppEvent.EventData.ipAcquiredV6.ip[0],(void *)&pIpV6->ip[0],sizeof(pIpV6->ip[0])*4); + g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&netAppEvent); + } + break; + + case SL_OPCODE_NETAPP_IP_LEASED: + { + SlIpLeasedAsync_t *pIpV4 = (SlIpLeasedAsync_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); + netAppEvent.Event = SL_NETAPP_IP_LEASED_EVENT; + netAppEvent.EventData.ipLeased.ip_address = pIpV4->ip_address; + netAppEvent.EventData.ipLeased.lease_time = pIpV4->lease_time; + sl_Memcpy(netAppEvent.EventData.ipLeased.mac, pIpV4->mac, 6); + + g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&netAppEvent); + } + break; + + case SL_OPCODE_NETAPP_IP_RELEASED: + { + SlIpReleasedAsync_t *pIpV4 = (SlIpReleasedAsync_t *)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); + netAppEvent.Event = SL_NETAPP_IP_RELEASED_EVENT; + netAppEvent.EventData.ipReleased.ip_address = pIpV4->ip_address; + netAppEvent.EventData.ipReleased.reason = pIpV4->reason; + sl_Memcpy(netAppEvent.EventData.ipReleased.mac, pIpV4->mac, 6); + + g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&netAppEvent); + } + break; + + case SL_OPCODE_SOCKET_TXFAILEDASYNCRESPONSE: + { + SlSockEventData_t *txfailparams = (SlSockEventData_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); + sockAppEvent.Event = SL_SOCKET_TX_FAILED_EVENT; + sl_Memcpy((void *)&sockAppEvent.EventData,(void *)txfailparams,sizeof(SlSockEventData_t)); + g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&sockAppEvent); + } + break; + + case SL_OPCODE_SOCKET_SOCKETASYNCEVENT: + { + SlSockEventData_t *socketAsyncEvent = (SlSockEventData_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); + sockAppEvent.Event = SL_SOCKET_ASYNC_EVENT; + sockAppEvent.EventData.socketAsyncEvent.sd = socketAsyncEvent->socketAsyncEvent.sd; + sockAppEvent.EventData.socketAsyncEvent.type = socketAsyncEvent->socketAsyncEvent.type; /* one of the possible types of socket */ + sockAppEvent.EventData.socketAsyncEvent.val = socketAsyncEvent->socketAsyncEvent.val; + g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&sockAppEvent); + } + break; + + case SL_OPCODE_WLAN_SMART_CONFIG_START_ASYNC_RESPONSE: + { + slSmartConfigStartAsyncResponse_t *pResp = (slSmartConfigStartAsyncResponse_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); + + wlanEvent.Event = SL_WLAN_SMART_CONFIG_COMPLETE_EVENT; + wlanEvent.EventData.smartConfigStartResponse.status = pResp->status; + wlanEvent.EventData.smartConfigStartResponse.ssid_len = pResp->ssid_len; + wlanEvent.EventData.smartConfigStartResponse.private_token_len = pResp->private_token_len; + + sl_Memset(wlanEvent.EventData.smartConfigStartResponse.ssid, 0x00, sizeof(wlanEvent.EventData.smartConfigStartResponse.ssid)); + sl_Memcpy(wlanEvent.EventData.smartConfigStartResponse.ssid, pResp->ssid, pResp->ssid_len); + /* if private data exist */ + if (pResp->private_token_len) + { + sl_Memset(wlanEvent.EventData.smartConfigStartResponse.private_token, 0x00, sizeof(wlanEvent.EventData.smartConfigStartResponse.private_token)); + sl_Memcpy(wlanEvent.EventData.smartConfigStartResponse.private_token, pResp->private_token, pResp->private_token_len); + } + + g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&wlanEvent); + } + break; + + case SL_OPCODE_WLAN_SMART_CONFIG_STOP_ASYNC_RESPONSE: + { + slSmartConfigStopAsyncResponse_t *pResp = (slSmartConfigStopAsyncResponse_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); + + wlanEvent.Event = SL_WLAN_SMART_CONFIG_STOP_EVENT; + wlanEvent.EventData.smartConfigStopResponse.status = pResp->status; + + g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&wlanEvent); + } + break; + + case SL_OPCODE_WLAN_STA_CONNECTED: + { + slPeerInfoAsyncResponse_t* pResp = (slPeerInfoAsyncResponse_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); + sl_Memset(&wlanEvent.EventData.APModeStaConnected,0,sizeof(slPeerInfoAsyncResponse_t)); + wlanEvent.Event = SL_WLAN_STA_CONNECTED_EVENT; + sl_Memcpy(wlanEvent.EventData.APModeStaConnected.mac,pResp->mac, 6); + sl_Memcpy(wlanEvent.EventData.APModeStaConnected.go_peer_device_name,pResp->go_peer_device_name,pResp->go_peer_device_name_len); + wlanEvent.EventData.APModeStaConnected.go_peer_device_name_len = pResp->go_peer_device_name_len; + + sl_Memcpy(wlanEvent.EventData.APModeStaConnected.own_ssid,pResp->own_ssid,pResp->own_ssid_len); + wlanEvent.EventData.APModeStaConnected.own_ssid_len = pResp->own_ssid_len; + g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&wlanEvent); + } + break; + + case SL_OPCODE_WLAN_STA_DISCONNECTED: + { + slPeerInfoAsyncResponse_t* pResp = (slPeerInfoAsyncResponse_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); + sl_Memset(&wlanEvent.EventData.APModestaDisconnected,0,sizeof(slPeerInfoAsyncResponse_t)); + wlanEvent.Event = SL_WLAN_STA_DISCONNECTED_EVENT; + sl_Memcpy(wlanEvent.EventData.APModestaDisconnected.mac,pResp->mac, 6); + sl_Memcpy(wlanEvent.EventData.APModestaDisconnected.go_peer_device_name,pResp->go_peer_device_name,pResp->go_peer_device_name_len); + wlanEvent.EventData.APModestaDisconnected.go_peer_device_name_len = pResp->go_peer_device_name_len; + g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&wlanEvent); + } + break; + + case SL_OPCODE_NETAPP_PINGREPORTREQUESTRESPONSE: + { + _sl_HandleAsync_PingResponse((void *)g_pCB->FunctionParams.AsyncExt.pAsyncBuf); + } + break; + + + default: + g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); + break; + } + } +} + + +/* ******************************************************************************/ +/* _SlDrvMsgReadCmdCtx */ +/* ******************************************************************************/ +_SlReturnVal_t _SlDrvMsgReadCmdCtx(void) +{ + + /* after command response is received and isCmdRespWaited */ + /* flag is set FALSE, it is necessary to read out all */ + /* Async messages in Commands context, because ssiDma_IsrHandleSignalFromSlave */ + /* could have dispatched some Async messages to g_NwpIf.CmdSyncObj */ + /* after command response but before this response has been processed */ + /* by spi_singleRead and isCmdRespWaited was set FALSE. */ + while (TRUE == g_pCB->IsCmdRespWaited) + { + if(_SL_PENDING_RX_MSG(g_pCB)) + { + g_pCB->FunctionParams.AsyncExt.pAsyncBuf = NULL;/* buffer must be allocated by _SlDrvMsgRead */ + g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler= NULL; + g_pCB->FunctionParams.AsyncExt.RxMsgClass = (_SlRxMsgClass_e)(-1);/* init to illegal value and verify it's overwritten with the valid one */ + + VERIFY_RET_OK(_SlDrvMsgRead()); + g_pCB->RxDoneCnt++; + + if (CMD_RESP_CLASS == g_pCB->FunctionParams.AsyncExt.RxMsgClass) + { + g_pCB->IsCmdRespWaited = FALSE; + + /* In case CmdResp has been read without waiting on CmdSyncObj - that */ + /* Sync object. That to prevent old signal to be processed. */ + sl_SyncObjClear(&g_pCB->CmdSyncObj); + } + else if (ASYNC_EVT_CLASS == g_pCB->FunctionParams.AsyncExt.RxMsgClass) + { + /* If Async event has been read in CmdResp context, check whether */ + /* there is a handler for this event. If there is, spawn specific */ + /* handler. Otherwise free the event's buffer. */ + /* This way there will be no "dry shots" from CmdResp context to */ + /* temporary context, i.e less waste of CPU and faster buffer */ + /* release. */ + _SlAsyncEventGenericHandler(); + +#if (SL_MEMORY_MGMT == SL_MEMORY_MGMT_STATIC) + g_pCB->FunctionParams.AsyncExt.pAsyncBuf = NULL; +#else + sl_Free(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); +#endif + } + } + else + { + /* CmdSyncObj will be signaled by IRQ */ + OSI_RET_OK_CHECK(sl_SyncObjWait(&g_pCB->CmdSyncObj, SL_OS_WAIT_FOREVER)); + } + } + + /* If there are more pending Rx Msgs after CmdResp is received, */ + /* that means that these are Async, Dummy or Read Data Msgs. */ + /* Spawn _SlDrvMsgReadSpawnCtx to trigger reading these messages from */ + /* Temporary context. */ + /* sl_Spawn is activated, using a different context */ + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->GlobalLockObj)); + if(_SL_PENDING_RX_MSG(g_pCB)) + { + sl_Spawn((_SlSpawnEntryFunc_t)_SlDrvMsgReadSpawnCtx, NULL, 0); + } + + return SL_OS_RET_CODE_OK; +} + +/* ******************************************************************************/ +/* _SlDrvMsgReadSpawnCtx */ +/* ******************************************************************************/ +_SlReturnVal_t _SlDrvMsgReadSpawnCtx(void *pValue) +{ +#ifdef SL_POLLING_MODE_USED + _i16 retCode = OSI_OK; + /* for polling based systems */ + do + { + retCode = sl_LockObjLock(&g_pCB->GlobalLockObj, 0); + if ( OSI_OK != retCode ) + { + if (TRUE == g_pCB->IsCmdRespWaited) + { + OSI_RET_OK_CHECK( sl_SyncObjSignal(&g_pCB->CmdSyncObj) ); + return SL_RET_CODE_OK; + } + } + + } + while (OSI_OK != retCode); + +#else + OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->GlobalLockObj, SL_OS_WAIT_FOREVER) ); +#endif + + g_pCB->FunctionParams.AsyncExt.pAsyncBuf = NULL;/* buffer must be allocated by _SlDrvMsgRead */ + g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler= NULL; + g_pCB->FunctionParams.AsyncExt.RxMsgClass = CMD_RESP_CLASS;/* init to illegal value and verify it's overwritten with the valid one */ + + /* Messages might have been read by CmdResp context. Therefore after */ + /* getting LockObj, check again where the Pending Rx Msg is still present. */ + if(FALSE == (_SL_PENDING_RX_MSG(g_pCB))) + { + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->GlobalLockObj)); + return SL_RET_CODE_OK; + } + + VERIFY_RET_OK(_SlDrvMsgRead()); + + g_pCB->RxDoneCnt++; + + switch(g_pCB->FunctionParams.AsyncExt.RxMsgClass) + { + case ASYNC_EVT_CLASS: + /* If got here and protected by LockObj a message is waiting */ + /* to be read */ + VERIFY_PROTOCOL(NULL != g_pCB->FunctionParams.AsyncExt.pAsyncBuf); + + _SlAsyncEventGenericHandler(); + +#if (SL_MEMORY_MGMT == SL_MEMORY_MGMT_STATIC) + g_pCB->FunctionParams.AsyncExt.pAsyncBuf = NULL; +#else + sl_Free(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); +#endif + break; + case DUMMY_MSG_CLASS: + case RECV_RESP_CLASS: + /* These types are legal in this context. Do nothing */ + break; + case CMD_RESP_CLASS: + /* Command response is illegal in this context. */ + /* No 'break' here: Assert! */ + default: + VERIFY_PROTOCOL(0); + } + + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->GlobalLockObj)); + + return(SL_RET_CODE_OK); +} + +/* ******************************************************************************/ +/* _SlDrvClassifyRxMsg */ +/* ******************************************************************************/ +void _SlDrvClassifyRxMsg( + _SlOpcode_t Opcode) +{ + + g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler = NULL; + + /* Async event has received */ + if (0 == (SL_OPCODE_SYNC & Opcode)) + { + if (SL_OPCODE_DEVICE_DEVICEASYNCDUMMY == Opcode) + { + g_pCB->FunctionParams.AsyncExt.RxMsgClass = DUMMY_MSG_CLASS; + } + else if ( (SL_OPCODE_SOCKET_RECVASYNCRESPONSE == Opcode) || (SL_OPCODE_SOCKET_RECVFROMASYNCRESPONSE == Opcode) || (SL_OPCODE_SOCKET_RECVFROMASYNCRESPONSE_V6 == Opcode) ) + { + g_pCB->FunctionParams.AsyncExt.RxMsgClass = RECV_RESP_CLASS; + } + else + { + g_pCB->FunctionParams.AsyncExt.RxMsgClass = ASYNC_EVT_CLASS; + + /* set silo handler */ + if (SL_OPCODE_SILO_DEVICE == (Opcode & SL_OPCODE_SILO_MASK)) + { + g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler = _SlDrvDeviceEventHandler; + } + else if (SL_OPCODE_SILO_WLAN == (Opcode & SL_OPCODE_SILO_MASK)) + { +#ifdef sl_WlanEvtHdlr + g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler = (_SlSpawnEntryFunc_t)sl_WlanEvtHdlr; +#endif + } + else if (SL_OPCODE_SILO_SOCKET == (Opcode & SL_OPCODE_SILO_MASK)) + { + +#ifdef sl_SockEvtHdlr + g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler = (_SlSpawnEntryFunc_t)sl_SockEvtHdlr; +#endif + } + else if (SL_OPCODE_SILO_NETAPP == (Opcode & SL_OPCODE_SILO_MASK)) + { + + if ((SL_OPCODE_NETAPP_HTTPGETTOKENVALUE == Opcode) || (SL_OPCODE_NETAPP_HTTPPOSTTOKENVALUE == Opcode)) + { + g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler = _SlDrvNetAppEventHandler; + } +#ifdef sl_NetAppEvtHdlr + else + { + g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler = (_SlSpawnEntryFunc_t)sl_NetAppEvtHdlr; + } +#endif + } + /* else if (SL_OPCODE_SILO_NVMEM == (Opcode & SL_OPCODE_SILO_MASK)) */ + /* { */ + /* } */ + /* else if (SL_OPCODE_SILO_NETCFG == (Opcode & SL_OPCODE_SILO_MASK)) */ + /* { */ + /* } */ + else + { + SL_ERROR_TRACE1(MSG_311, "ASSERT: _SlDrvClassifyRxMsg : invalid opcode = 0x%x", Opcode); + } + } + } + else + { + /* These may be Command responses only */ + g_pCB->FunctionParams.AsyncExt.RxMsgClass = CMD_RESP_CLASS; + } + +} + +/* ******************************************************************************/ +/* _SlDrvShiftDWord */ +/* ******************************************************************************/ +void _SlDrvShiftDWord(_u8 *pBuf) +{ + _u8 ShiftIdx; + for(ShiftIdx = 0; ShiftIdx< 7; ShiftIdx++) + { + pBuf[ShiftIdx] = pBuf[ShiftIdx+1]; + } + pBuf[7] = 0; +} + +/* ******************************************************************************/ +/* _SlDrvRxHdrRead */ +/* ******************************************************************************/ +_SlReturnVal_t _SlDrvRxHdrRead(_u8 *pBuf, _u8 *pAlignSize) +{ + _u32 SyncCnt = 0; + +#ifndef SL_IF_TYPE_UART + /* 1. Write CNYS pattern to NWP when working in SPI mode only */ + NWP_IF_WRITE_CHECK(g_pCB->FD, (_u8 *)&g_H2NCnysPattern.Short, SYNC_PATTERN_LEN); +#endif + + /* 2. Read 4 bytes (protocol aligned) */ + NWP_IF_READ_CHECK(g_pCB->FD, &pBuf[0], 4); + _SL_DBG_SYNC_LOG(SyncCnt,pBuf); + + /* Wait for SYNC_PATTERN_LEN from the device */ + while ( ! N2H_SYNC_PATTERN_MATCH(pBuf, g_pCB->TxSeqNum) ) + { + /* 3. Debug limit of scan */ + VERIFY_PROTOCOL(SyncCnt < SL_SYNC_SCAN_THRESHOLD); + + /* 4. Read next 4 bytes to Low 4 bytes of buffer */ + if(0 == (SyncCnt % (_u32)SYNC_PATTERN_LEN)) + { + NWP_IF_READ_CHECK(g_pCB->FD, &pBuf[4], 4); + _SL_DBG_SYNC_LOG(SyncCnt,pBuf); + } + + /* 5. Shift Buffer Up for checking if the sync is shifted */ + _SlDrvShiftDWord(pBuf); + + SyncCnt++; + } + + /* 5. Sync pattern found. If needed, complete number of read bytes to multiple of 4 (protocol align) */ + SyncCnt %= SYNC_PATTERN_LEN; + + if(SyncCnt > 0) + { + *(_u32 *)&pBuf[0] = *(_u32 *)&pBuf[4]; + NWP_IF_READ_CHECK(g_pCB->FD, &pBuf[SYNC_PATTERN_LEN - SyncCnt], (_u16)SyncCnt); + } + else + { + NWP_IF_READ_CHECK(g_pCB->FD, &pBuf[0], 4); + } + + /* 6. Scan for Double pattern. */ + while ( N2H_SYNC_PATTERN_MATCH(pBuf, g_pCB->TxSeqNum) ) + { + _SL_DBG_CNT_INC(Work.DoubleSyncPattern); + NWP_IF_READ_CHECK(g_pCB->FD, &pBuf[0], SYNC_PATTERN_LEN); + } + g_pCB->TxSeqNum++; + + /* 7. Here we've read Generic Header (4 bytes). Read the Resp Specific header (4 more bytes). */ + NWP_IF_READ_CHECK(g_pCB->FD, &pBuf[SYNC_PATTERN_LEN], _SL_RESP_SPEC_HDR_SIZE); + + /* 8. Here we've read the entire Resp Header. */ + /* Return number bytes needed to be sent after read for NWP Rx 4-byte alignment (protocol alignment) */ + *pAlignSize = (_u8)((SyncCnt > 0) ? (SYNC_PATTERN_LEN - SyncCnt) : 0); + + return SL_RET_CODE_OK; +} + +/* ***************************************************************************** */ +/* _SlDrvBasicCmd */ +/* ***************************************************************************** */ +typedef union +{ + _BasicResponse_t Rsp; +}_SlBasicCmdMsg_u; + +_i16 _SlDrvBasicCmd(_SlOpcode_t Opcode) +{ + _SlBasicCmdMsg_u Msg = {{0, 0}}; + _SlCmdCtrl_t CmdCtrl; + + CmdCtrl.Opcode = Opcode; + CmdCtrl.TxDescLen = 0; + CmdCtrl.RxDescLen = sizeof(_BasicResponse_t); + + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&CmdCtrl, &Msg, NULL)); + + return (_i16)Msg.Rsp.status; +} + +/* ***************************************************************************** */ +/* _SlDrvWaitForPoolObj */ +/* ***************************************************************************** */ +_i16 _SlDrvWaitForPoolObj(_u32 ActionID, _u8 SocketID) +{ + _u8 CurrObjIndex = MAX_CONCURRENT_ACTIONS; + + OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); + + /* Get free object */ + if (MAX_CONCURRENT_ACTIONS > g_pCB->FreePoolIdx) + { + /* save the current obj index */ + CurrObjIndex = g_pCB->FreePoolIdx; + /* set the new free index */ + if (MAX_CONCURRENT_ACTIONS > g_pCB->ObjPool[CurrObjIndex].NextIndex) + { + g_pCB->FreePoolIdx = g_pCB->ObjPool[CurrObjIndex].NextIndex; + } + else + { + /* No further free actions available */ + g_pCB->FreePoolIdx = MAX_CONCURRENT_ACTIONS; + } + } + else + { + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); + return CurrObjIndex; + } + g_pCB->ObjPool[CurrObjIndex].ActionID = (_u8)ActionID; + if (SL_MAX_SOCKETS > SocketID) + { + g_pCB->ObjPool[CurrObjIndex].AdditionalData = SocketID; + } + /*In case this action is socket related, SocketID bit will be on + In case SocketID is set to SL_MAX_SOCKETS, the socket is not relevant to the action. In that case ActionID bit will be on */ + while ( ( (SL_MAX_SOCKETS > SocketID) && (g_pCB->ActiveActionsBitmap & (1<<SocketID)) ) || ( (g_pCB->ActiveActionsBitmap & (1<<ActionID)) && (SL_MAX_SOCKETS == SocketID) ) ) + { + //action in progress - move to pending list + g_pCB->ObjPool[CurrObjIndex].NextIndex = g_pCB->PendingPoolIdx; + g_pCB->PendingPoolIdx = CurrObjIndex; + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); + //wait for action to be free + OSI_RET_OK_CHECK(sl_SyncObjWait(&g_pCB->ObjPool[CurrObjIndex].SyncObj, SL_OS_WAIT_FOREVER)); + //set params and move to active (remove from pending list at _SlDrvReleasePoolObj) + OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); + } + /*mark as active. Set socket as active if action is on socket, otherwise mark action as active*/ + if (SL_MAX_SOCKETS > SocketID) + { + g_pCB->ActiveActionsBitmap |= (1<<SocketID); + } + else + { + g_pCB->ActiveActionsBitmap |= (1<<ActionID); + } + /* move to active list */ + g_pCB->ObjPool[CurrObjIndex].NextIndex = g_pCB->ActivePoolIdx; + g_pCB->ActivePoolIdx = CurrObjIndex; + /* unlock */ + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); + return CurrObjIndex; +} + +/* ******************************************************************************/ +/* _SlDrvReleasePoolObj */ +/* ******************************************************************************/ +void _SlDrvReleasePoolObj(_u8 ObjIdx) +{ + _u8 PendingIndex; + + OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); + + /* go over the pending list and release other pending action if needed */ + PendingIndex = g_pCB->PendingPoolIdx; + while(MAX_CONCURRENT_ACTIONS > PendingIndex) + { + /* In case this action is socket related, SocketID is in use, otherwise will be set to SL_MAX_SOCKETS */ + if ( (g_pCB->ObjPool[PendingIndex].ActionID == g_pCB->ObjPool[ObjIdx].ActionID) && + ( (SL_MAX_SOCKETS == (g_pCB->ObjPool[PendingIndex].AdditionalData & BSD_SOCKET_ID_MASK)) || + ((SL_MAX_SOCKETS > (g_pCB->ObjPool[ObjIdx].AdditionalData & BSD_SOCKET_ID_MASK)) && ( (g_pCB->ObjPool[PendingIndex].AdditionalData & BSD_SOCKET_ID_MASK) == (g_pCB->ObjPool[ObjIdx].AdditionalData & BSD_SOCKET_ID_MASK) ))) ) + { + /* remove from pending list */ + _SlRemoveFromList(&g_pCB->PendingPoolIdx, PendingIndex); + OSI_RET_OK_CHECK(sl_SyncObjSignal(&(g_pCB->ObjPool[PendingIndex].SyncObj))); + break; + } + PendingIndex = g_pCB->ObjPool[PendingIndex].NextIndex; + } + + if (SL_MAX_SOCKETS > (g_pCB->ObjPool[ObjIdx].AdditionalData & BSD_SOCKET_ID_MASK)) + { + /* unset socketID */ + g_pCB->ActiveActionsBitmap &= ~(1<<(g_pCB->ObjPool[ObjIdx].AdditionalData & BSD_SOCKET_ID_MASK)); + } + else + { + /* unset actionID */ + g_pCB->ActiveActionsBitmap &= ~(1<<g_pCB->ObjPool[ObjIdx].ActionID); + } + + /* delete old data */ + g_pCB->ObjPool[ObjIdx].pRespArgs = NULL; + g_pCB->ObjPool[ObjIdx].ActionID = 0; + g_pCB->ObjPool[ObjIdx].AdditionalData = SL_MAX_SOCKETS; + + /* remove from active list */ + _SlRemoveFromList(&g_pCB->ActivePoolIdx, ObjIdx); + /* move to free list */ + g_pCB->ObjPool[ObjIdx].NextIndex = g_pCB->FreePoolIdx; + g_pCB->FreePoolIdx = ObjIdx; + + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); +} + + + +/* ******************************************************************************/ +/* _SlDrvObjInit */ +/* ******************************************************************************/ +void _SlDrvObjInit(void) +{ + _u8 Idx; + + sl_Memset(&g_pCB->ObjPool[0],0,MAX_CONCURRENT_ACTIONS*sizeof(_SlPoolObj_t)); + /* place all Obj in the free list */ + g_pCB->FreePoolIdx = 0; + for (Idx = 0 ; Idx < MAX_CONCURRENT_ACTIONS ; Idx++) + { + g_pCB->ObjPool[Idx].NextIndex = Idx + 1; + g_pCB->ObjPool[Idx].AdditionalData = SL_MAX_SOCKETS; + } + + g_pCB->ActivePoolIdx = MAX_CONCURRENT_ACTIONS; + g_pCB->PendingPoolIdx = MAX_CONCURRENT_ACTIONS; + +} + +/* ******************************************************************************/ +/* _SlDrvObjDeInit */ +/* ******************************************************************************/ +void _SlDrvObjDeInit(void) +{ + g_pCB->FreePoolIdx = 0; + g_pCB->PendingPoolIdx = MAX_CONCURRENT_ACTIONS; + g_pCB->ActivePoolIdx = MAX_CONCURRENT_ACTIONS; + +} + +/* ******************************************************************************/ +/* _SlRemoveFromList */ +/* ******************************************************************************/ +void _SlRemoveFromList(_u8 *ListIndex, _u8 ItemIndex) +{ + _u8 Idx; + /* only one item in the list */ + if (MAX_CONCURRENT_ACTIONS == g_pCB->ObjPool[*ListIndex].NextIndex) + { + *ListIndex = MAX_CONCURRENT_ACTIONS; + } + /* need to remove the first item in the list and therefore update the global which holds this index */ + else if (*ListIndex == ItemIndex) + { + *ListIndex = g_pCB->ObjPool[ItemIndex].NextIndex; + } + else + { + Idx = *ListIndex; + while(MAX_CONCURRENT_ACTIONS > Idx) + { + /* remove from list */ + if (g_pCB->ObjPool[Idx].NextIndex == ItemIndex) + { + g_pCB->ObjPool[Idx].NextIndex = g_pCB->ObjPool[ItemIndex].NextIndex; + break; + } + Idx = g_pCB->ObjPool[Idx].NextIndex; + } + } +} + + +/* ******************************************************************************/ +/* _SlFindAndSetActiveObj */ +/* ******************************************************************************/ +_SlReturnVal_t _SlFindAndSetActiveObj(_SlOpcode_t Opcode, _u8 Sd) +{ + _u8 ActiveIndex; + + ActiveIndex = g_pCB->ActivePoolIdx; + /* go over the active list if exist to find obj waiting for this Async event */ + while (MAX_CONCURRENT_ACTIONS > ActiveIndex) + { + /* unset the Ipv4\IPv6 bit in the opcode if family bit was set */ + if (g_pCB->ObjPool[ActiveIndex].AdditionalData & SL_NETAPP_FAMILY_MASK) + { + Opcode &= ~SL_OPCODE_IPV6; + } + + if ((g_pCB->ObjPool[ActiveIndex].ActionID == RECV_ID) && (Sd == g_pCB->ObjPool[ActiveIndex].AdditionalData) && + ( (SL_OPCODE_SOCKET_RECVASYNCRESPONSE == Opcode) || (SL_OPCODE_SOCKET_RECVFROMASYNCRESPONSE == Opcode) || (SL_OPCODE_SOCKET_RECVFROMASYNCRESPONSE_V6 == Opcode) ) ) + { + g_pCB->FunctionParams.AsyncExt.ActionIndex = ActiveIndex; + return SL_RET_CODE_OK; + } + /* In case this action is socket related, SocketID is in use, otherwise will be set to SL_MAX_SOCKETS */ + if ( (_SlActionLookupTable[ g_pCB->ObjPool[ActiveIndex].ActionID - MAX_SOCKET_ENUM_IDX].ActionAsyncOpcode == Opcode) && + ( ((Sd == (g_pCB->ObjPool[ActiveIndex].AdditionalData & BSD_SOCKET_ID_MASK) ) && (SL_MAX_SOCKETS > Sd)) || (SL_MAX_SOCKETS == (g_pCB->ObjPool[ActiveIndex].AdditionalData & BSD_SOCKET_ID_MASK)) ) ) + { + /* set handler */ + g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler = _SlActionLookupTable[ g_pCB->ObjPool[ActiveIndex].ActionID - MAX_SOCKET_ENUM_IDX].AsyncEventHandler; + g_pCB->FunctionParams.AsyncExt.ActionIndex = ActiveIndex; + return SL_RET_CODE_OK; + } + ActiveIndex = g_pCB->ObjPool[ActiveIndex].NextIndex; + } + + return SL_RET_CODE_SELF_ERROR; +} diff --git a/drivers/cc3100/src/flowcont.c b/drivers/cc3100/src/flowcont.c new file mode 100644 index 0000000000..889241ea2b --- /dev/null +++ b/drivers/cc3100/src/flowcont.c @@ -0,0 +1,71 @@ +/* + * flowcont.c - CC31xx/CC32xx Host Driver Implementation + * + * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +*/ + + + +/*****************************************************************************/ +/* Include files */ +/*****************************************************************************/ +#include "simplelink.h" +#include "protocol.h" +#include "driver.h" +#include "flowcont.h" + + +/*****************************************************************************/ +/* _SlDrvFlowContInit */ +/*****************************************************************************/ +void _SlDrvFlowContInit(void) +{ + g_pCB->FlowContCB.TxPoolCnt = FLOW_CONT_MIN; + + OSI_RET_OK_CHECK(sl_LockObjCreate(&g_pCB->FlowContCB.TxLockObj, "TxLockObj")); + + OSI_RET_OK_CHECK(sl_SyncObjCreate(&g_pCB->FlowContCB.TxSyncObj, "TxSyncObj")); +} + +/*****************************************************************************/ +/* _SlDrvFlowContDeinit */ +/*****************************************************************************/ +void _SlDrvFlowContDeinit(void) +{ + g_pCB->FlowContCB.TxPoolCnt = 0; + + OSI_RET_OK_CHECK(sl_LockObjDelete(&g_pCB->FlowContCB.TxLockObj)); + + OSI_RET_OK_CHECK(sl_SyncObjDelete(&g_pCB->FlowContCB.TxSyncObj)); +} + diff --git a/drivers/cc3100/src/fs.c b/drivers/cc3100/src/fs.c new file mode 100644 index 0000000000..cc65e219e9 --- /dev/null +++ b/drivers/cc3100/src/fs.c @@ -0,0 +1,415 @@ +/* + * fs.c - CC31xx/CC32xx Host Driver Implementation + * + * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +*/ + + + +/*****************************************************************************/ +/* Include files */ +/*****************************************************************************/ +#include "simplelink.h" +#include "protocol.h" +#include "driver.h" + +/*****************************************************************************/ +/* Macro declarations */ +/*****************************************************************************/ +#define sl_min(a,b) (((a) < (b)) ? (a) : (b)) +#define MAX_NVMEM_CHUNK_SIZE 1460 + +/*****************************************************************************/ +/* Internal functions */ +/*****************************************************************************/ + + +/*****************************************************************************/ +/* _sl_Strlen */ +/*****************************************************************************/ +_u16 _sl_Strlen(const _u8 *buffer) +{ + _u16 len = 0; + if( buffer != NULL ) + { + while(*buffer++) len++; + } + return len; +} + +/*****************************************************************************/ +/* _sl_GetCreateFsMode */ +/*****************************************************************************/ +_u32 _sl_GetCreateFsMode(_u32 maxSizeInBytes,_u32 accessFlags) +{ + _u32 granIdx = 0; + _u32 granNum = 0; + _u32 granTable[_FS_MAX_MODE_SIZE_GRAN] = {256,1024,4096,16384,65536}; + for(granIdx= _FS_MODE_SIZE_GRAN_256B ;granIdx< _FS_MAX_MODE_SIZE_GRAN;granIdx++) + { + if( granTable[granIdx]*255 >= maxSizeInBytes ) + break; + } + granNum = maxSizeInBytes/granTable[granIdx]; + if( maxSizeInBytes % granTable[granIdx] != 0 ) + granNum++; + + return _FS_MODE(_FS_MODE_OPEN_WRITE_CREATE_IF_NOT_EXIST, granIdx, granNum, accessFlags); +} + + +/*****************************************************************************/ +/* API functions */ +/*****************************************************************************/ + +/*****************************************************************************/ +/* sl_FsOpen */ +/*****************************************************************************/ +typedef union +{ + _FsOpenCommand_t Cmd; + _FsOpenResponse_t Rsp; +}_SlFsOpenMsg_u; + +const _SlCmdCtrl_t _SlFsOpenCmdCtrl = +{ + SL_OPCODE_NVMEM_FILEOPEN, + sizeof(_FsOpenCommand_t), + sizeof(_FsOpenResponse_t) +}; + +#if _SL_INCLUDE_FUNC(sl_FsOpen) +_i32 sl_FsOpen(_u8 *pFileName,_u32 AccessModeAndMaxSize, _u32 *pToken,_i32 *pFileHandle) +{ + _SlReturnVal_t RetVal; + _SlFsOpenMsg_u Msg; + _SlCmdExt_t CmdExt; + + CmdExt.TxPayloadLen = (_sl_Strlen(pFileName)+4) & (~3); // add 4: 1 for NULL and the 3 for align + CmdExt.RxPayloadLen = 0; + CmdExt.pTxPayload = pFileName; + CmdExt.pRxPayload = NULL; + + Msg.Cmd.Mode = AccessModeAndMaxSize; + + if(pToken != NULL) + { + Msg.Cmd.Token = *pToken; + } + else + { + Msg.Cmd.Token = 0; + } + + RetVal = _SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsOpenCmdCtrl, &Msg, &CmdExt); + *pFileHandle = Msg.Rsp.FileHandle; + if (pToken != NULL) + { + *pToken = Msg.Rsp.Token; + } + + /* in case of an error, return the erros file handler as an error code */ + if( *pFileHandle < 0 ) + { + return *pFileHandle; + } + return (_i32)RetVal; +} +#endif + +/*****************************************************************************/ +/* sl_FsClose */ +/*****************************************************************************/ +typedef union +{ + _FsCloseCommand_t Cmd; + _BasicResponse_t Rsp; +}_SlFsCloseMsg_u; + +const _SlCmdCtrl_t _SlFsCloseCmdCtrl = +{ + SL_OPCODE_NVMEM_FILECLOSE, + sizeof(_FsCloseCommand_t), + sizeof(_FsCloseResponse_t) +}; + +#if _SL_INCLUDE_FUNC(sl_FsClose) +_i16 sl_FsClose(_i32 FileHdl, _u8* pCeritificateFileName,_u8* pSignature ,_u32 SignatureLen) +{ + _SlFsCloseMsg_u Msg = {.Cmd = {0, 0, 0}, .Rsp = {0, 0}}; + _SlCmdExt_t ExtCtrl; + + Msg.Cmd.FileHandle = FileHdl; + if( pCeritificateFileName != NULL ) + { + Msg.Cmd.CertificFileNameLength = (_sl_Strlen(pCeritificateFileName)+4) & (~3); /* add 4: 1 for NULL and the 3 for align */ + } + Msg.Cmd.SignatureLen = SignatureLen; + + ExtCtrl.TxPayloadLen = ((SignatureLen+3) & (~3)); /* align */ + ExtCtrl.pTxPayload = pSignature; + ExtCtrl.RxPayloadLen = (_u16)Msg.Cmd.CertificFileNameLength; + ExtCtrl.pRxPayload = pCeritificateFileName; /* Add signature */ + + if(ExtCtrl.pRxPayload != NULL && ExtCtrl.RxPayloadLen != 0) + { + g_pCB->RelayFlagsViaRxPayload = TRUE; + } + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsCloseCmdCtrl, &Msg, &ExtCtrl)); + + return (_i16)((_i16)Msg.Rsp.status); +} +#endif + + +/*****************************************************************************/ +/* sl_FsRead */ +/*****************************************************************************/ +typedef union +{ + _FsReadCommand_t Cmd; + _FsReadResponse_t Rsp; +}_SlFsReadMsg_u; + +const _SlCmdCtrl_t _SlFsReadCmdCtrl = +{ + SL_OPCODE_NVMEM_FILEREADCOMMAND, + sizeof(_FsReadCommand_t), + sizeof(_FsReadResponse_t) +}; + + +#if _SL_INCLUDE_FUNC(sl_FsRead) +_i32 sl_FsRead(_i32 FileHdl, _u32 Offset, _u8* pData, _u32 Len) +{ + _SlFsReadMsg_u Msg; + _SlCmdExt_t ExtCtrl; + _u16 ChunkLen; + _SlReturnVal_t RetVal =0; + _i32 RetCount = 0; + + ExtCtrl.TxPayloadLen = 0; + ExtCtrl.pTxPayload = NULL; + + ChunkLen = (_u16)sl_min(MAX_NVMEM_CHUNK_SIZE,Len); + ExtCtrl.RxPayloadLen = ChunkLen; + ExtCtrl.pRxPayload = (_u8 *)(pData); + Msg.Cmd.Offset = Offset; + Msg.Cmd.Len = ChunkLen; + Msg.Cmd.FileHandle = FileHdl; + do + { + RetVal = _SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsReadCmdCtrl, &Msg, &ExtCtrl); + if(SL_OS_RET_CODE_OK == RetVal) + { + if( Msg.Rsp.status < 0) + { + if( RetCount > 0) + { + return RetCount; + } + else + { + return Msg.Rsp.status; + } + } + RetCount += (_i32)Msg.Rsp.status; + Len -= ChunkLen; + Offset += ChunkLen; + Msg.Cmd.Offset = Offset; + ExtCtrl.pRxPayload += ChunkLen; + ChunkLen = (_u16)sl_min(MAX_NVMEM_CHUNK_SIZE,Len); + ExtCtrl.RxPayloadLen = ChunkLen; + Msg.Cmd.Len = ChunkLen; + Msg.Cmd.FileHandle = FileHdl; + } + else + { + return RetVal; + } + }while(ChunkLen > 0); + + return (_i32)RetCount; +} +#endif + +/*****************************************************************************/ +/* sl_FsWrite */ +/*****************************************************************************/ +typedef union +{ + _FsWriteCommand_t Cmd; + _FsWriteResponse_t Rsp; +}_SlFsWriteMsg_u; + +const _SlCmdCtrl_t _SlFsWriteCmdCtrl = +{ + SL_OPCODE_NVMEM_FILEWRITECOMMAND, + sizeof(_FsWriteCommand_t), + sizeof(_FsWriteResponse_t) +}; + + +#if _SL_INCLUDE_FUNC(sl_FsWrite) +_i32 sl_FsWrite(_i32 FileHdl, _u32 Offset, _u8* pData, _u32 Len) +{ + _SlFsWriteMsg_u Msg; + _SlCmdExt_t ExtCtrl; + _u16 ChunkLen; + _SlReturnVal_t RetVal; + _i32 RetCount = 0; + + ExtCtrl.RxPayloadLen = 0; + ExtCtrl.pRxPayload = NULL; + + ChunkLen = (_u16)sl_min(MAX_NVMEM_CHUNK_SIZE,Len); + ExtCtrl.TxPayloadLen = ChunkLen; + ExtCtrl.pTxPayload = (_u8 *)(pData); + Msg.Cmd.Offset = Offset; + Msg.Cmd.Len = ChunkLen; + Msg.Cmd.FileHandle = FileHdl; + + do + { + + RetVal = _SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsWriteCmdCtrl, &Msg, &ExtCtrl); + if(SL_OS_RET_CODE_OK == RetVal) + { + if( Msg.Rsp.status < 0) + { + if( RetCount > 0) + { + return RetCount; + } + else + { + return Msg.Rsp.status; + } + } + + RetCount += (_i32)Msg.Rsp.status; + Len -= ChunkLen; + Offset += ChunkLen; + Msg.Cmd.Offset = Offset; + ExtCtrl.pTxPayload += ChunkLen; + ChunkLen = (_u16)sl_min(MAX_NVMEM_CHUNK_SIZE,Len); + ExtCtrl.TxPayloadLen = ChunkLen; + Msg.Cmd.Len = ChunkLen; + Msg.Cmd.FileHandle = FileHdl; + } + else + { + return RetVal; + } + }while(ChunkLen > 0); + + return (_i32)RetCount; +} +#endif + +/*****************************************************************************/ +/* sl_FsGetInfo */ +/*****************************************************************************/ +typedef union +{ + _FsGetInfoCommand_t Cmd; + _FsGetInfoResponse_t Rsp; +}_SlFsGetInfoMsg_u; + +const _SlCmdCtrl_t _SlFsGetInfoCmdCtrl = +{ + SL_OPCODE_NVMEM_FILEGETINFOCOMMAND, + sizeof(_FsGetInfoCommand_t), + sizeof(_FsGetInfoResponse_t) +}; + +#if _SL_INCLUDE_FUNC(sl_FsGetInfo) +_i16 sl_FsGetInfo(_u8 *pFileName,_u32 Token,SlFsFileInfo_t* pFsFileInfo) +{ + _SlFsGetInfoMsg_u Msg; + _SlCmdExt_t CmdExt; + + CmdExt.TxPayloadLen = (_sl_Strlen(pFileName)+4) & (~3); /* add 4: 1 for NULL and the 3 for align */ + CmdExt.RxPayloadLen = 0; + CmdExt.pTxPayload = pFileName; + CmdExt.pRxPayload = NULL; + Msg.Cmd.Token = Token; + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsGetInfoCmdCtrl, &Msg, &CmdExt)); + + pFsFileInfo->flags = Msg.Rsp.flags; + pFsFileInfo->FileLen = Msg.Rsp.FileLen; + pFsFileInfo->AllocatedLen = Msg.Rsp.AllocatedLen; + pFsFileInfo->Token[0] = Msg.Rsp.Token[0]; + pFsFileInfo->Token[1] = Msg.Rsp.Token[1]; + pFsFileInfo->Token[2] = Msg.Rsp.Token[2]; + pFsFileInfo->Token[3] = Msg.Rsp.Token[3]; + return (_i16)((_i16)Msg.Rsp.Status); +} +#endif + +/*****************************************************************************/ +/* sl_FsDel */ +/*****************************************************************************/ +typedef union +{ + _FsDeleteCommand_t Cmd; + _FsDeleteResponse_t Rsp; +}_SlFsDeleteMsg_u; + +const _SlCmdCtrl_t _SlFsDeleteCmdCtrl = +{ + SL_OPCODE_NVMEM_FILEDELCOMMAND, + sizeof(_FsDeleteCommand_t), + sizeof(_FsDeleteResponse_t) +}; + +#if _SL_INCLUDE_FUNC(sl_FsDel) +_i16 sl_FsDel(_u8 *pFileName,_u32 Token) +{ + _SlFsDeleteMsg_u Msg; + _SlCmdExt_t CmdExt; + + CmdExt.TxPayloadLen = (_sl_Strlen(pFileName)+4) & (~3); /* add 4: 1 for NULL and the 3 for align */ + CmdExt.RxPayloadLen = 0; + CmdExt.pTxPayload = pFileName; + CmdExt.pRxPayload = NULL; + Msg.Cmd.Token = Token; + + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsDeleteCmdCtrl, &Msg, &CmdExt)); + + return (_i16)((_i16)Msg.Rsp.status); +} +#endif diff --git a/drivers/cc3100/src/netapp.c b/drivers/cc3100/src/netapp.c new file mode 100644 index 0000000000..32315e093a --- /dev/null +++ b/drivers/cc3100/src/netapp.c @@ -0,0 +1,1285 @@ +/* + * netapp.c - CC31xx/CC32xx Host Driver Implementation + * + * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +*/ + + + +/*****************************************************************************/ +/* Include files */ +/*****************************************************************************/ +#include "simplelink.h" +#include "protocol.h" +#include "driver.h" + +/*****************************************************************************/ +/* Macro declarations */ +/*****************************************************************************/ +#define NETAPP_MDNS_OPTIONS_ADD_SERVICE_BIT ((_u32)0x1 << 31) + +#ifdef SL_TINY +#define NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH 63 +#else +#define NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH 255 +#endif + + +/*****************************************************************************/ +/* Functions prototypes */ +/*****************************************************************************/ +void _sl_HandleAsync_DnsGetHostByName(void *pVoidBuf); +void _sl_HandleAsync_DnsGetHostByService(void *pVoidBuf); +void _sl_HandleAsync_PingResponse(void *pVoidBuf); +void CopyPingResultsToReport(_PingReportResponse_t *pResults,SlPingReport_t *pReport); +_u16 sl_NetAppSendTokenValue(slHttpServerData_t * Token); +_i16 sl_NetAppMDNSRegisterUnregisterService(const _i8* pServiceName, + _u8 ServiceNameLen, + const _i8* pText, + _u8 TextLen, + _u16 Port, + _u32 TTL, + _u32 Options); + + +/*****************************************************************************/ +/* API functions */ +/*****************************************************************************/ + +/***************************************************************************** + sl_NetAppStart +*****************************************************************************/ +typedef union +{ + _NetAppStartStopCommand_t Cmd; + _NetAppStartStopResponse_t Rsp; +}_SlNetAppStartStopMsg_u; + +const _SlCmdCtrl_t _SlNetAppStartCtrl = +{ + SL_OPCODE_NETAPP_START_COMMAND, + sizeof(_NetAppStartStopCommand_t), + sizeof(_NetAppStartStopResponse_t) +}; + +const _SlCmdCtrl_t _SlNetAppStopCtrl = +{ + SL_OPCODE_NETAPP_STOP_COMMAND, + sizeof(_NetAppStartStopCommand_t), + sizeof(_NetAppStartStopResponse_t) +}; + +#if _SL_INCLUDE_FUNC(sl_NetAppStart) +_i16 sl_NetAppStart(_u32 AppBitMap) +{ + _SlNetAppStartStopMsg_u Msg; + Msg.Cmd.appId = AppBitMap; + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetAppStartCtrl, &Msg, NULL)); + + return Msg.Rsp.status; +} +#endif + +/***************************************************************************** + sl_NetAppStop +*****************************************************************************/ +#if _SL_INCLUDE_FUNC(sl_NetAppStop) +_i16 sl_NetAppStop(_u32 AppBitMap) +{ + _SlNetAppStartStopMsg_u Msg; + Msg.Cmd.appId = AppBitMap; + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetAppStopCtrl, &Msg, NULL)); + + return Msg.Rsp.status; +} +#endif + + +/******************************************************************************/ +/* sl_NetAppGetServiceList */ +/******************************************************************************/ +typedef struct +{ + _u8 IndexOffest; + _u8 MaxServiceCount; + _u8 Flags; + _i8 Padding; +}NetappGetServiceListCMD_t; + +typedef union +{ + NetappGetServiceListCMD_t Cmd; + _BasicResponse_t Rsp; +}_SlNetappGetServiceListMsg_u; + +const _SlCmdCtrl_t _SlGetServiceListeCtrl = +{ + SL_OPCODE_NETAPP_NETAPP_MDNS_LOOKUP_SERVICE, + sizeof(NetappGetServiceListCMD_t), + sizeof(_BasicResponse_t) +}; + + +#if _SL_INCLUDE_FUNC(sl_NetAppGetServiceList) +_i16 sl_NetAppGetServiceList(_u8 IndexOffest, + _u8 MaxServiceCount, + _u8 Flags, + _i8 *pBuffer, + _u32 RxBufferLength + ) +{ + + _i32 retVal= 0; + _SlNetappGetServiceListMsg_u Msg; + _SlCmdExt_t CmdExt; + _u16 ServiceSize = 0; + _u16 BufferSize = 0; + + /* + Calculate RX pBuffer size + WARNING: + if this size is BufferSize than 1480 error should be returned because there + is no place in the RX packet. + */ + switch(Flags) + { + case SL_NET_APP_FULL_SERVICE_WITH_TEXT_IPV4_TYPE: + ServiceSize = sizeof(SlNetAppGetFullServiceWithTextIpv4List_t); + break; + + case SL_NET_APP_FULL_SERVICE_IPV4_TYPE: + ServiceSize = sizeof(SlNetAppGetFullServiceIpv4List_t); + break; + + case SL_NET_APP_SHORT_SERVICE_IPV4_TYPE: + ServiceSize = sizeof(SlNetAppGetShortServiceIpv4List_t); + break; + + default: + ServiceSize = sizeof(_BasicResponse_t); + break; + } + + + + BufferSize = MaxServiceCount * ServiceSize; + + /*Check the size of the requested services is smaller than size of the user buffer. + If not an error is returned in order to avoid overwriting memory. */ + if(RxBufferLength <= BufferSize) + { + return SL_ERROR_NETAPP_RX_BUFFER_LENGTH_ERROR; + } + + CmdExt.TxPayloadLen = 0; + CmdExt.RxPayloadLen = BufferSize; + CmdExt.pTxPayload = NULL; + CmdExt.pRxPayload = (_u8 *)pBuffer; + + Msg.Cmd.IndexOffest = IndexOffest; + Msg.Cmd.MaxServiceCount = MaxServiceCount; + Msg.Cmd.Flags = Flags; + Msg.Cmd.Padding = 0; + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlGetServiceListeCtrl, &Msg, &CmdExt)); + retVal = Msg.Rsp.status; + + return (_i16)retVal; +} + +#endif + +/*****************************************************************************/ +/* sl_mDNSRegisterService */ +/*****************************************************************************/ +/* + * The below struct depicts the constant parameters of the command/API RegisterService. + * + 1. ServiceLen - The length of the service should be smaller than NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH. + 2. TextLen - The length of the text should be smaller than NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH. + 3. port - The port on this target host. + 4. TTL - The TTL of the service + 5. Options - bitwise parameters: + bit 0 - is unique (means if the service needs to be unique) + bit 31 - for internal use if the service should be added or deleted (set means ADD). + bit 1-30 for future. + + NOTE: + + 1. There are another variable parameter is this API which is the service name and the text. + 2. According to now there is no warning and Async event to user on if the service is a unique. +* + */ + + +typedef struct +{ + _u8 ServiceNameLen; + _u8 TextLen; + _u16 Port; + _u32 TTL; + _u32 Options; +}NetappMdnsSetService_t; + +typedef union +{ + NetappMdnsSetService_t Cmd; + _BasicResponse_t Rsp; +}_SlNetappMdnsRegisterServiceMsg_u; + +const _SlCmdCtrl_t _SlRegisterServiceCtrl = +{ + SL_OPCODE_NETAPP_MDNSREGISTERSERVICE, + sizeof(NetappMdnsSetService_t), + sizeof(_BasicResponse_t) +}; + + +/****************************************************************************** + + sl_NetAppMDNSRegisterService + + CALLER user from its host + + + DESCRIPTION: + Add/delete service + The function manipulates the command that register the service and call + to the NWP in order to add/delete the service to/from the mDNS package and to/from the DB. + + This register service is a service offered by the application. + This unregister service is a service offered by the application before. + + The service name should be full service name according to RFC + of the DNS-SD - means the value in name field in SRV answer. + + Example for service name: + 1. PC1._ipp._tcp.local + 2. PC2_server._ftp._tcp.local + + If the option is_unique is set, mDNS probes the service name to make sure + it is unique before starting to announce the service on the network. + Instance is the instance portion of the service name. + + + + + PARAMETERS: + + The command is from constant parameters and variables parameters. + + Constant parameters are: + + ServiceLen - The length of the service. + TextLen - The length of the service should be smaller than 64. + port - The port on this target host. + TTL - The TTL of the service + Options - bitwise parameters: + bit 0 - is unique (means if the service needs to be unique) + bit 31 - for internal use if the service should be added or deleted (set means ADD). + bit 1-30 for future. + + The variables parameters are: + + Service name(full service name) - The service name. + Example for service name: + 1. PC1._ipp._tcp.local + 2. PC2_server._ftp._tcp.local + + Text - The description of the service. + should be as mentioned in the RFC + (according to type of the service IPP,FTP...) + + NOTE - pay attention + + 1. Temporary - there is an allocation on stack of internal buffer. + Its size is NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH. + It means that the sum of the text length and service name length cannot be bigger than + NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH. + If it is - An error is returned. + + 2. According to now from certain constraints the variables parameters are set in the + attribute part (contain constant parameters) + + + + RETURNS: Status - the immediate response of the command status. + 0 means success. + + + +******************************************************************************/ +#if _SL_INCLUDE_FUNC(sl_NetAppMDNSRegisterUnregisterService) + +_i16 sl_NetAppMDNSRegisterUnregisterService( const _i8* pServiceName, + _u8 ServiceNameLen, + const _i8* pText, + _u8 TextLen, + _u16 Port, + _u32 TTL, + _u32 Options) + +{ + _SlNetappMdnsRegisterServiceMsg_u Msg; + _SlCmdExt_t CmdExt ; + _i8 ServiceNameAndTextBuffer[NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH]; + _i8 *TextPtr; + + /* + + NOTE - pay attention + + 1. Temporary - there is an allocation on stack of internal buffer. + Its size is NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH. + It means that the sum of the text length and service name length cannot be bigger than + NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH. + If it is - An error is returned. + + 2. According to now from certain constraints the variables parameters are set in the + attribute part (contain constant parameters) + + + */ + + /*build the attribute part of the command. + It contains the constant parameters of the command*/ + + Msg.Cmd.ServiceNameLen = ServiceNameLen; + Msg.Cmd.Options = Options; + Msg.Cmd.Port = Port; + Msg.Cmd.TextLen = TextLen; + Msg.Cmd.TTL = TTL; + + /*Build the payload part of the command + Copy the service name and text to one buffer. + NOTE - pay attention + The size of the service length + the text length should be smaller than 255, + Until the simplelink drive supports to variable length through SPI command. */ + if(TextLen + ServiceNameLen > (NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH - 1 )) /*-1 is for giving a place to set null termination at the end of the text*/ + { + return -1; + } + + sl_Memset(ServiceNameAndTextBuffer,0,NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH); + + + /*Copy the service name*/ + sl_Memcpy(ServiceNameAndTextBuffer, + pServiceName, + ServiceNameLen); + + if(TextLen > 0 ) + { + + TextPtr = &ServiceNameAndTextBuffer[ServiceNameLen]; + /*Copy the text just after the service name*/ + sl_Memcpy(TextPtr, + pText, + TextLen); + + + } + + CmdExt.TxPayloadLen = (TextLen + ServiceNameLen); + CmdExt.RxPayloadLen = 0; + CmdExt.pTxPayload = (_u8 *)ServiceNameAndTextBuffer; + CmdExt.pRxPayload = NULL; + + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlRegisterServiceCtrl, &Msg, &CmdExt)); + + return (_i16)Msg.Rsp.status; + + +} +#endif + +/**********************************************************************************************/ +#if _SL_INCLUDE_FUNC(sl_NetAppMDNSRegisterService) + +_i16 sl_NetAppMDNSRegisterService( const _i8* pServiceName, + _u8 ServiceNameLen, + const _i8* pText, + _u8 TextLen, + _u16 Port, + _u32 TTL, + _u32 Options) + +{ + + /* + + NOTE - pay attention + + 1. Temporary - there is an allocation on stack of internal buffer. + Its size is NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH. + It means that the sum of the text length and service name length cannot be bigger than + NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH. + If it is - An error is returned. + + 2. According to now from certain constraints the variables parameters are set in the + attribute part (contain constant parameters) + + */ + + /*Set the add service bit in the options parameter. + In order not use different opcodes for the register service and unregister service + bit 31 in option is taken for this purpose. if it is set it means in NWP that the service should be added + if it is cleared it means that the service should be deleted and there is only meaning to pServiceName + and ServiceNameLen values. */ + Options |= NETAPP_MDNS_OPTIONS_ADD_SERVICE_BIT; + + return sl_NetAppMDNSRegisterUnregisterService( pServiceName, + ServiceNameLen, + pText, + TextLen, + Port, + TTL, + Options); + + +} +#endif +/**********************************************************************************************/ + + + +/**********************************************************************************************/ +#if _SL_INCLUDE_FUNC(sl_NetAppMDNSUnRegisterService) + +_i16 sl_NetAppMDNSUnRegisterService( const _i8* pServiceName, + _u8 ServiceNameLen) + + +{ + _u32 Options = 0; + + /* + + NOTE - pay attention + + The size of the service length should be smaller than 255, + Until the simplelink drive supports to variable length through SPI command. + + + */ + + /*Clear the add service bit in the options parameter. + In order not use different opcodes for the register service and unregister service + bit 31 in option is taken for this purpose. if it is set it means in NWP that the service should be added + if it is cleared it means that the service should be deleted and there is only meaning to pServiceName + and ServiceNameLen values.*/ + + Options &= (~NETAPP_MDNS_OPTIONS_ADD_SERVICE_BIT); + + return sl_NetAppMDNSRegisterUnregisterService( pServiceName, + ServiceNameLen, + NULL, + 0, + 0, + 0, + Options); + + +} +#endif +/**********************************************************************************************/ + + + +/*****************************************************************************/ +/* sl_DnsGetHostByService */ +/*****************************************************************************/ +/* + * The below struct depicts the constant parameters of the command/API sl_DnsGetHostByService. + * + 1. ServiceLen - The length of the service should be smaller than 255. + 2. AddrLen - TIPv4 or IPv6 (SL_AF_INET , SL_AF_INET6). +* + */ + +typedef struct +{ + _u8 ServiceLen; + _u8 AddrLen; + _u16 Padding; +}_GetHostByServiceCommand_t; + + + +/* + * The below structure depict the constant parameters that are returned in the Async event answer + * according to command/API sl_DnsGetHostByService for IPv4 and IPv6. + * + 1Status - The status of the response. + 2.Address - Contains the IP address of the service. + 3.Port - Contains the port of the service. + 4.TextLen - Contains the max length of the text that the user wants to get. + it means that if the test of service is bigger that its value than + the text is cut to inout_TextLen value. + Output: Contain the length of the text that is returned. Can be full text or part + of the text (see above). + +* + */ +typedef struct +{ + _u16 Status; + _u16 TextLen; + _u32 Port; + _u32 Address; +}_GetHostByServiceIPv4AsyncResponse_t; + + +typedef struct +{ + _u16 Status; + _u16 TextLen; + _u32 Port; + _u32 Address[4]; +}_GetHostByServiceIPv6AsyncResponse_t; + + +typedef union +{ + _GetHostByServiceIPv4AsyncResponse_t IpV4; + _GetHostByServiceIPv6AsyncResponse_t IpV6; +}_GetHostByServiceAsyncResponseAttribute_u; + +/* + * The below struct contains pointers to the output parameters that the user gives + * + */ +typedef struct +{ + _i16 Status; + _u32 *out_pAddr; + _u32 *out_pPort; + _u16 *inout_TextLen; // in: max len , out: actual len + _i8 *out_pText; +}_GetHostByServiceAsyncResponse_t; + + +typedef union +{ + _GetHostByServiceCommand_t Cmd; + _BasicResponse_t Rsp; +}_SlGetHostByServiceMsg_u; + +const _SlCmdCtrl_t _SlGetHostByServiceCtrl = +{ + SL_OPCODE_NETAPP_MDNSGETHOSTBYSERVICE, + sizeof(_GetHostByServiceCommand_t), + sizeof(_BasicResponse_t) +}; + + + +/******************************************************************************/ + +#if _SL_INCLUDE_FUNC(sl_NetAppDnsGetHostByService) +_i32 sl_NetAppDnsGetHostByService(_i8 *pServiceName, /* string containing all (or only part): name + subtype + service */ + _u8 ServiceLen, + _u8 Family, /* 4-IPv4 , 16-IPv6 */ + _u32 pAddr[], + _u32 *pPort, + _u16 *pTextLen, /* in: max len , out: actual len */ + _i8 *pText + ) +{ + _SlGetHostByServiceMsg_u Msg; + _SlCmdExt_t CmdExt ; + _GetHostByServiceAsyncResponse_t AsyncRsp; + _u8 ObjIdx = MAX_CONCURRENT_ACTIONS; + +/* + Note: + 1. The return's attributes are belonged to first service that is found. + It can be other services with the same service name will response to + the query. The results of these responses are saved in the peer cache of the NWP, and + should be read by another API. + + 2. Text length can be 120 bytes only - not more + It is because of constraints in the NWP on the buffer that is allocated for the Async event. + + 3.The API waits to Async event by blocking. It means that the API is finished only after an Async event + is sent by the NWP. + + 4.No rolling option!!! - only PTR type is sent. + + +*/ + /*build the attribute part of the command. + It contains the constant parameters of the command */ + + Msg.Cmd.ServiceLen = ServiceLen; + Msg.Cmd.AddrLen = Family; + + /*Build the payload part of the command + Copy the service name and text to one buffer.*/ + CmdExt.TxPayloadLen = ServiceLen; + CmdExt.RxPayloadLen = 0; + CmdExt.pTxPayload = (_u8 *)pServiceName; + CmdExt.pRxPayload = NULL; + + /*set pointers to the output parameters (the returned parameters). + This pointers are belonged to local struct that is set to global Async response parameter. + It is done in order not to run more than one sl_DnsGetHostByService at the same time. + The API should be run only if global parameter is pointed to NULL. */ + AsyncRsp.out_pText = pText; + AsyncRsp.inout_TextLen = (_u16* )pTextLen; + AsyncRsp.out_pPort = pPort; + AsyncRsp.out_pAddr = (_u32 *)pAddr; + + + /*Use Obj to issue the command, if not available try later */ + ObjIdx = (_u8)_SlDrvWaitForPoolObj(GETHOSYBYSERVICE_ID,SL_MAX_SOCKETS); + + if (MAX_CONCURRENT_ACTIONS == ObjIdx) + { + return SL_POOL_IS_EMPTY; + } + + OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); + + g_pCB->ObjPool[ObjIdx].pRespArgs = (void *)&AsyncRsp; + + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); + /* set bit to indicate IPv6 address is expected */ + if (SL_AF_INET6 == Family) + { + g_pCB->ObjPool[ObjIdx].AdditionalData |= SL_NETAPP_FAMILY_MASK; + } + /* Send the command */ + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlGetHostByServiceCtrl, &Msg, &CmdExt)); + + + + /* If the immediate reponse is O.K. than wait for aSYNC event response. */ + if(SL_RET_CODE_OK == Msg.Rsp.status) + { + OSI_RET_OK_CHECK(sl_SyncObjWait(&g_pCB->ObjPool[ObjIdx].SyncObj, SL_OS_WAIT_FOREVER)); + + /* If we are - it means that Async event was sent. + The results are copied in the Async handle return functions */ + + Msg.Rsp.status = AsyncRsp.Status; + } + + _SlDrvReleasePoolObj(ObjIdx); + return Msg.Rsp.status; +} +#endif +/******************************************************************************/ + +/****************************************************************************** + _sl_HandleAsync_DnsGetHostByService + + CALLER NWP - Async event on sl_DnsGetHostByService with IPv4 Family + + + DESCRIPTION: + + Async event on sl_DnsGetHostByService command with IPv4 Family. + Return service attributes like IP address, port and text according to service name. + The user sets a service name Full/Part (see example below), and should get the: + 1. IP of the service + 2. The port of service. + 3. The text of service. + + Hence it can make a connection to the specific service and use it. + It is similar to get host by name method. + + It is done by a single shot query with PTR type on the service name. + + + + Note: + 1. The return's attributes are belonged to first service that is found. + It can be other services with the same service name will response to + the query. The results of these responses are saved in the peer cache of the NWP, and + should be read by another API. + + + PARAMETERS: + + pVoidBuf - is point to opcode of the event. + it contains the outputs that are given to the user + + outputs description: + + 1.out_pAddr[] - output: Contain the IP address of the service. + 2.out_pPort - output: Contain the port of the service. + 3.inout_TextLen - Input: Contain the max length of the text that the user wants to get. + it means that if the test of service is bigger that its value than + the text is cut to inout_TextLen value. + Output: Contain the length of the text that is returned. Can be full text or part + of the text (see above). + + 4.out_pText - Contain the text of the service (full or part see above- inout_TextLen description). + + * + + + RETURNS: success or fail. + + + + + +******************************************************************************/ +void _sl_HandleAsync_DnsGetHostByService(void *pVoidBuf) +{ + + _GetHostByServiceAsyncResponse_t* Res; + _u16 TextLen; + _u16 UserTextLen; + + + /*pVoidBuf - is point to opcode of the event.*/ + + /*set pMsgArgs to point to the attribute of the event.*/ + _GetHostByServiceIPv4AsyncResponse_t *pMsgArgs = (_GetHostByServiceIPv4AsyncResponse_t *)_SL_RESP_ARGS_START(pVoidBuf); + + VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs); + + /*IPv6*/ + if(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].AdditionalData & SL_NETAPP_FAMILY_MASK) + { + return; + } + /*IPv4*/ + else + { + /************************************************************************************************* + + 1. Copy the attribute part of the evnt to the attribute part of the response + sl_Memcpy(g_pCB->GetHostByServiceCB.pAsyncRsp, pMsgArgs, sizeof(_GetHostByServiceIPv4AsyncResponse_t)); + + set to TextLen the text length of the service.*/ + TextLen = pMsgArgs->TextLen; + + /*Res pointed to mDNS global object struct */ + Res = (_GetHostByServiceAsyncResponse_t*)g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs; + + + + /*It is 4 bytes so we avoid from memcpy*/ + Res->out_pAddr[0] = pMsgArgs->Address; + Res->out_pPort[0] = pMsgArgs->Port; + Res->Status = pMsgArgs->Status; + + /*set to TextLen the text length of the user (input fromthe user).*/ + UserTextLen = Res->inout_TextLen[0]; + + /*Cut the service text if the user requested for smaller text.*/ + UserTextLen = (TextLen <= UserTextLen) ? TextLen : UserTextLen; + Res->inout_TextLen[0] = UserTextLen ; + + /************************************************************************************************** + + 2. Copy the payload part of the evnt (the text) to the payload part of the response + the lenght of the copy is according to the text length in the attribute part. */ + + + sl_Memcpy(Res->out_pText , + (_i8 *)(& pMsgArgs[1]) , /* & pMsgArgs[1] -> 1st byte after the fixed header = 1st byte of variable text.*/ + UserTextLen ); + + + /**************************************************************************************************/ + + OSI_RET_OK_CHECK(sl_SyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj)); + return; + } +} + + + +/*****************************************************************************/ +/* _sl_HandleAsync_DnsGetHostByAddr */ +/*****************************************************************************/ +void _sl_HandleAsync_DnsGetHostByAddr(void *pVoidBuf) +{ + SL_TRACE0(DBG_MSG, MSG_303, "STUB: _sl_HandleAsync_DnsGetHostByAddr not implemented yet!"); + return; +} + +/*****************************************************************************/ +/* sl_DnsGetHostByName */ +/*****************************************************************************/ +typedef union +{ + _GetHostByNameIPv4AsyncResponse_t IpV4; + _GetHostByNameIPv6AsyncResponse_t IpV6; +}_GetHostByNameAsyncResponse_u; + +typedef union +{ + _GetHostByNameCommand_t Cmd; + _BasicResponse_t Rsp; +}_SlGetHostByNameMsg_u; + +const _SlCmdCtrl_t _SlGetHostByNameCtrl = +{ + SL_OPCODE_NETAPP_DNSGETHOSTBYNAME, + sizeof(_GetHostByNameCommand_t), + sizeof(_BasicResponse_t) +}; +#if _SL_INCLUDE_FUNC(sl_NetAppDnsGetHostByName) +_i16 sl_NetAppDnsGetHostByName(_i8 * hostname, _u16 usNameLen, _u32* out_ip_addr,_u8 family) +{ + _SlGetHostByNameMsg_u Msg; + _SlCmdExt_t ExtCtrl; + _GetHostByNameAsyncResponse_u AsyncRsp; + _u8 ObjIdx = MAX_CONCURRENT_ACTIONS; + + ExtCtrl.TxPayloadLen = usNameLen; + ExtCtrl.RxPayloadLen = 0; + ExtCtrl.pTxPayload = (_u8 *)hostname; + ExtCtrl.pRxPayload = 0; + + Msg.Cmd.Len = usNameLen; + Msg.Cmd.family = family; + + /*Use Obj to issue the command, if not available try later */ + ObjIdx = (_u8)_SlDrvWaitForPoolObj(GETHOSYBYNAME_ID,SL_MAX_SOCKETS); + if (MAX_CONCURRENT_ACTIONS == ObjIdx) + { + return SL_POOL_IS_EMPTY; + } + OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); + + g_pCB->ObjPool[ObjIdx].pRespArgs = (_u8 *)&AsyncRsp; + /*set bit to indicate IPv6 address is expected */ + if (SL_AF_INET6 == family) + { + g_pCB->ObjPool[ObjIdx].AdditionalData |= SL_NETAPP_FAMILY_MASK; + } + + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlGetHostByNameCtrl, &Msg, &ExtCtrl)); + + if(SL_RET_CODE_OK == Msg.Rsp.status) + { + OSI_RET_OK_CHECK(sl_SyncObjWait(&g_pCB->ObjPool[ObjIdx].SyncObj, SL_OS_WAIT_FOREVER)); + Msg.Rsp.status = AsyncRsp.IpV4.status; + + if(SL_OS_RET_CODE_OK == (_i16)Msg.Rsp.status) + { + sl_Memcpy((_i8 *)out_ip_addr, + (_i8 *)&AsyncRsp.IpV4.ip0, + (SL_AF_INET == family) ? SL_IPV4_ADDRESS_SIZE : SL_IPV6_ADDRESS_SIZE); + } + } + _SlDrvReleasePoolObj(ObjIdx); + return Msg.Rsp.status; +} +#endif +/******************************************************************************/ +/* _sl_HandleAsync_DnsGetHostByName */ +/******************************************************************************/ +void _sl_HandleAsync_DnsGetHostByName(void *pVoidBuf) +{ + _GetHostByNameIPv4AsyncResponse_t *pMsgArgs = (_GetHostByNameIPv4AsyncResponse_t *)_SL_RESP_ARGS_START(pVoidBuf); + + OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); + + VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs); + + /*IPv6 */ + if(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].AdditionalData & SL_NETAPP_FAMILY_MASK) + { + sl_Memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_GetHostByNameIPv6AsyncResponse_t)); + } + /*IPv4 */ + else + { + sl_Memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_GetHostByNameIPv4AsyncResponse_t)); + } + OSI_RET_OK_CHECK(sl_SyncObjSignal(&(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj))); + + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); + return; +} + + +void CopyPingResultsToReport(_PingReportResponse_t *pResults,SlPingReport_t *pReport) +{ + pReport->PacketsSent = pResults->numSendsPings; + pReport->PacketsReceived = pResults->numSuccsessPings; + pReport->MinRoundTime = pResults->rttMin; + pReport->MaxRoundTime = pResults->rttMax; + pReport->AvgRoundTime = pResults->rttAvg; + pReport->TestTime = pResults->testTime; +} + + +/*****************************************************************************/ +/* _sl_HandleAsync_PingResponse */ +/*****************************************************************************/ +void _sl_HandleAsync_PingResponse(void *pVoidBuf) +{ + _PingReportResponse_t *pMsgArgs = (_PingReportResponse_t *)_SL_RESP_ARGS_START(pVoidBuf); + SlPingReport_t pingReport; + + if(pPingCallBackFunc) + { + CopyPingResultsToReport(pMsgArgs,&pingReport); + pPingCallBackFunc(&pingReport); + } + else + { + + OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); + VERIFY_SOCKET_CB(NULL != g_pCB->PingCB.PingAsync.pAsyncRsp); + + if (NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs) + { + sl_Memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_PingReportResponse_t)); + OSI_RET_OK_CHECK(sl_SyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj)); + } + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); + } + return; +} + + +/*****************************************************************************/ +/* sl_PingStart */ +/*****************************************************************************/ +typedef union +{ + _PingStartCommand_t Cmd; + _PingReportResponse_t Rsp; +}_SlPingStartMsg_u; + + +typedef enum +{ + CMD_PING_TEST_RUNNING = 0, + CMD_PING_TEST_STOPPED +}_SlPingStatus_e; + + +#if _SL_INCLUDE_FUNC(sl_NetAppPingStart) +_i16 sl_NetAppPingStart(SlPingStartCommand_t* pPingParams,_u8 family,SlPingReport_t *pReport,const P_SL_DEV_PING_CALLBACK pPingCallback) +{ + _SlCmdCtrl_t CmdCtrl = {0, sizeof(_PingStartCommand_t), sizeof(_BasicResponse_t)}; + _SlPingStartMsg_u Msg; + _PingReportResponse_t PingRsp; + _u8 ObjIdx = MAX_CONCURRENT_ACTIONS; + + if( 0 == pPingParams->Ip ) // stop any ongoing ping + { + return _SlDrvBasicCmd(SL_OPCODE_NETAPP_PINGSTOP); + } + + if(SL_AF_INET == family) + { + CmdCtrl.Opcode = SL_OPCODE_NETAPP_PINGSTART; + sl_Memcpy(&Msg.Cmd.ip0, &pPingParams->Ip, SL_IPV4_ADDRESS_SIZE); + } + else + { + CmdCtrl.Opcode = SL_OPCODE_NETAPP_PINGSTART_V6; + sl_Memcpy(&Msg.Cmd.ip0, &pPingParams->Ip, SL_IPV6_ADDRESS_SIZE); + } + + Msg.Cmd.pingIntervalTime = pPingParams->PingIntervalTime; + Msg.Cmd.PingSize = pPingParams->PingSize; + Msg.Cmd.pingRequestTimeout = pPingParams->PingRequestTimeout; + Msg.Cmd.totalNumberOfAttempts = pPingParams->TotalNumberOfAttempts; + Msg.Cmd.flags = pPingParams->Flags; + + if( pPingCallback ) + { + pPingCallBackFunc = pPingCallback; + } + else + { + /*Use Obj to issue the command, if not available try later */ + ObjIdx = (_u8)_SlDrvWaitForPoolObj(PING_ID,SL_MAX_SOCKETS); + if (MAX_CONCURRENT_ACTIONS == ObjIdx) + { + return SL_POOL_IS_EMPTY; + } + OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); + /* async response handler for non callback mode */ + g_pCB->ObjPool[ObjIdx].pRespArgs = (_u8 *)&PingRsp; + pPingCallBackFunc = NULL; + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); + } + + + VERIFY_RET_OK(_SlDrvCmdOp(&CmdCtrl, &Msg, NULL)); + /*send the command*/ + if(CMD_PING_TEST_RUNNING == (_i16)Msg.Rsp.status || CMD_PING_TEST_STOPPED == (_i16)Msg.Rsp.status ) + { + /* block waiting for results if no callback function is used */ + if( NULL == pPingCallback ) + { + OSI_RET_OK_CHECK(sl_SyncObjWait(&g_pCB->ObjPool[ObjIdx].SyncObj, SL_OS_WAIT_FOREVER)); + if( SL_OS_RET_CODE_OK == (_i16)PingRsp.status ) + { + CopyPingResultsToReport(&PingRsp,pReport); + } + _SlDrvReleasePoolObj(ObjIdx); + } + } + else + { /* ping failure, no async response */ + if( NULL == pPingCallback ) + { + _SlDrvReleasePoolObj(ObjIdx); + } + } + + return Msg.Rsp.status; +} +#endif + +/*****************************************************************************/ +/* sl_NetAppSet */ +/*****************************************************************************/ +typedef union +{ + _NetAppSetGet_t Cmd; + _BasicResponse_t Rsp; +}_SlNetAppMsgSet_u; + +const _SlCmdCtrl_t _SlNetAppSetCmdCtrl = +{ + SL_OPCODE_NETAPP_NETAPPSET, + sizeof(_NetAppSetGet_t), + sizeof(_BasicResponse_t) +}; + +#if _SL_INCLUDE_FUNC(sl_NetAppSet) +_i32 sl_NetAppSet(_u8 AppId ,_u8 Option,_u8 OptionLen, _u8 *pOptionValue) +{ + _SlNetAppMsgSet_u Msg; + _SlCmdExt_t CmdExt; + + CmdExt.TxPayloadLen = (OptionLen+3) & (~3); + CmdExt.RxPayloadLen = 0; + CmdExt.pTxPayload = (_u8 *)pOptionValue; + CmdExt.pRxPayload = NULL; + + + Msg.Cmd.AppId = AppId; + Msg.Cmd.ConfigLen = OptionLen; + Msg.Cmd.ConfigOpt = Option; + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetAppSetCmdCtrl, &Msg, &CmdExt)); + + return (_i16)Msg.Rsp.status; +} +#endif + +/*****************************************************************************/ +/* sl_NetAppSendTokenValue */ +/*****************************************************************************/ +typedef union +{ + sl_NetAppHttpServerSendToken_t Cmd; + _BasicResponse_t Rsp; +}_SlNetAppMsgSendTokenValue_u; + +const _SlCmdCtrl_t _SlNetAppSendTokenValueCmdCtrl = +{ + SL_OPCODE_NETAPP_HTTPSENDTOKENVALUE, + sizeof(sl_NetAppHttpServerSendToken_t), + sizeof(_BasicResponse_t) +}; + +_u16 sl_NetAppSendTokenValue(slHttpServerData_t * Token_value) +{ + _SlNetAppMsgSendTokenValue_u Msg; + _SlCmdExt_t CmdExt; + + CmdExt.TxPayloadLen = (Token_value->value_len+3) & (~3); + CmdExt.RxPayloadLen = 0; + CmdExt.pTxPayload = (_u8 *) Token_value->token_value; + CmdExt.pRxPayload = NULL; + + Msg.Cmd.token_value_len = Token_value->value_len; + Msg.Cmd.token_name_len = Token_value->name_len; + sl_Memcpy(&Msg.Cmd.token_name[0], Token_value->token_name, Token_value->name_len); + + + VERIFY_RET_OK(_SlDrvCmdSend((_SlCmdCtrl_t *)&_SlNetAppSendTokenValueCmdCtrl, &Msg, &CmdExt)); + + return Msg.Rsp.status; +} + +/*****************************************************************************/ +/* sl_NetAppGet */ +/*****************************************************************************/ +typedef union +{ + _NetAppSetGet_t Cmd; + _NetAppSetGet_t Rsp; +}_SlNetAppMsgGet_u; + +const _SlCmdCtrl_t _SlNetAppGetCmdCtrl = +{ + SL_OPCODE_NETAPP_NETAPPGET, + sizeof(_NetAppSetGet_t), + sizeof(_NetAppSetGet_t) +}; + +#if _SL_INCLUDE_FUNC(sl_NetAppGet) +_i32 sl_NetAppGet(_u8 AppId, _u8 Option,_u8 *pOptionLen, _u8 *pOptionValue) +{ + _SlNetAppMsgGet_u Msg; + _SlCmdExt_t CmdExt; + + if (*pOptionLen == 0) + { + return SL_EZEROLEN; + } + CmdExt.TxPayloadLen = 0; + CmdExt.RxPayloadLen = *pOptionLen; + CmdExt.pTxPayload = NULL; + CmdExt.pRxPayload = (_u8 *)pOptionValue; + CmdExt.ActualRxPayloadLen = 0; + + Msg.Cmd.AppId = AppId; + Msg.Cmd.ConfigOpt = Option; + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetAppGetCmdCtrl, &Msg, &CmdExt)); + + + if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen) + { + *pOptionLen = (_u8)CmdExt.RxPayloadLen; + return SL_ESMALLBUF; + } + else + { + *pOptionLen = (_u8)CmdExt.ActualRxPayloadLen; + } + + return (_i16)Msg.Rsp.Status; +} +#endif + + +/*****************************************************************************/ +/* _SlDrvNetAppEventHandler */ +/*****************************************************************************/ +void _SlDrvNetAppEventHandler(void *pArgs) +{ + _SlResponseHeader_t *pHdr = (_SlResponseHeader_t *)pArgs; +#ifdef sl_HttpServerCallback + SlHttpServerEvent_t httpServerEvent; + SlHttpServerResponse_t httpServerResponse; +#endif + switch(pHdr->GenHeader.Opcode) + { + case SL_OPCODE_NETAPP_DNSGETHOSTBYNAMEASYNCRESPONSE: + case SL_OPCODE_NETAPP_DNSGETHOSTBYNAMEASYNCRESPONSE_V6: + _sl_HandleAsync_DnsGetHostByName(pArgs); + break; + case SL_OPCODE_NETAPP_MDNSGETHOSTBYSERVICEASYNCRESPONSE: + case SL_OPCODE_NETAPP_MDNSGETHOSTBYSERVICEASYNCRESPONSE_V6: + _sl_HandleAsync_DnsGetHostByService(pArgs); + break; + case SL_OPCODE_NETAPP_PINGREPORTREQUESTRESPONSE: + _sl_HandleAsync_PingResponse(pArgs); + break; + case SL_OPCODE_NETAPP_HTTPGETTOKENVALUE: + { +#ifdef sl_HttpServerCallback + _u8 *pTokenName; + slHttpServerData_t Token_value; + sl_NetAppHttpServerGetToken_t *httpGetToken = (sl_NetAppHttpServerGetToken_t *)_SL_RESP_ARGS_START(pHdr); + pTokenName = (_u8 *)((sl_NetAppHttpServerGetToken_t *)httpGetToken + 1); + + httpServerResponse.Response = SL_NETAPP_HTTPSETTOKENVALUE; + httpServerResponse.ResponseData.token_value.len = MAX_TOKEN_VALUE_LEN; + httpServerResponse.ResponseData.token_value.data = (_u8 *)_SL_RESP_ARGS_START(pHdr) + MAX_TOKEN_NAME_LEN; //Reuse the async buffer for getting the token value response from the user + + httpServerEvent.Event = SL_NETAPP_HTTPGETTOKENVALUE_EVENT; + httpServerEvent.EventData.httpTokenName.len = httpGetToken->token_name_len; + httpServerEvent.EventData.httpTokenName.data = pTokenName; + + Token_value.token_name = pTokenName; + + sl_HttpServerCallback (&httpServerEvent, &httpServerResponse); + + Token_value.value_len = httpServerResponse.ResponseData.token_value.len; + Token_value.name_len = httpServerEvent.EventData.httpTokenName.len; + + Token_value.token_value = httpServerResponse.ResponseData.token_value.data; + + + sl_NetAppSendTokenValue(&Token_value); +#endif + } + break; + + case SL_OPCODE_NETAPP_HTTPPOSTTOKENVALUE: + { +#ifdef sl_HttpServerCallback + _u8 *pPostParams; + + sl_NetAppHttpServerPostToken_t *httpPostTokenArgs = (sl_NetAppHttpServerPostToken_t *)_SL_RESP_ARGS_START(pHdr); + pPostParams = (_u8 *)((sl_NetAppHttpServerPostToken_t *)httpPostTokenArgs + 1); + + httpServerEvent.Event = SL_NETAPP_HTTPPOSTTOKENVALUE_EVENT; + + httpServerEvent.EventData.httpPostData.action.len = httpPostTokenArgs->post_action_len; + httpServerEvent.EventData.httpPostData.action.data = pPostParams; + pPostParams+=httpPostTokenArgs->post_action_len; + + httpServerEvent.EventData.httpPostData.token_name.len = httpPostTokenArgs->token_name_len; + httpServerEvent.EventData.httpPostData.token_name.data = pPostParams; + pPostParams+=httpPostTokenArgs->token_name_len; + + httpServerEvent.EventData.httpPostData.token_value.len = httpPostTokenArgs->token_value_len; + httpServerEvent.EventData.httpPostData.token_value.data = pPostParams; + + httpServerResponse.Response = SL_NETAPP_RESPONSE_NONE; + + + sl_HttpServerCallback (&httpServerEvent, &httpServerResponse); +#endif + } + break; + default: + SL_ERROR_TRACE1(MSG_305, "ASSERT: _SlDrvNetAppEventHandler : invalid opcode = 0x%x", pHdr->GenHeader.Opcode); + VERIFY_PROTOCOL(0); + } +} diff --git a/drivers/cc3100/src/netcfg.c b/drivers/cc3100/src/netcfg.c new file mode 100644 index 0000000000..36d1e1fa97 --- /dev/null +++ b/drivers/cc3100/src/netcfg.c @@ -0,0 +1,142 @@ +/* +* netcfg.c - CC31xx/CC32xx Host Driver Implementation +* +* Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ +* +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the +* distribution. +* +* Neither the name of Texas Instruments Incorporated nor the names of +* its contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + + + +/*****************************************************************************/ +/* Include files */ +/*****************************************************************************/ +#include "simplelink.h" +#include "protocol.h" +#include "driver.h" + +/*****************************************************************************/ +/* sl_NetCfgSet */ +/*****************************************************************************/ +typedef union +{ + _NetCfgSetGet_t Cmd; + _BasicResponse_t Rsp; +}_SlNetCfgMsgSet_u; + +const _SlCmdCtrl_t _SlNetCfgSetCmdCtrl = +{ + SL_OPCODE_DEVICE_NETCFG_SET_COMMAND, + sizeof(_NetCfgSetGet_t), + sizeof(_BasicResponse_t) +}; + +#if _SL_INCLUDE_FUNC(sl_NetCfgSet) +_i32 sl_NetCfgSet(_u8 ConfigId ,_u8 ConfigOpt,_u8 ConfigLen, _u8 *pValues) +{ + _SlNetCfgMsgSet_u Msg; + _SlCmdExt_t CmdExt; + + CmdExt.TxPayloadLen = (ConfigLen+3) & (~3); + CmdExt.RxPayloadLen = 0; + CmdExt.pTxPayload = (_u8 *)pValues; + CmdExt.pRxPayload = NULL; + + + Msg.Cmd.ConfigId = ConfigId; + Msg.Cmd.ConfigLen = ConfigLen; + Msg.Cmd.ConfigOpt = ConfigOpt; + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetCfgSetCmdCtrl, &Msg, &CmdExt)); + + return (_i16)Msg.Rsp.status; +} +#endif + + +/*****************************************************************************/ +/* sl_NetCfgGet */ +/*****************************************************************************/ +typedef union +{ + _NetCfgSetGet_t Cmd; + _NetCfgSetGet_t Rsp; +}_SlNetCfgMsgGet_u; + +const _SlCmdCtrl_t _SlNetCfgGetCmdCtrl = +{ + SL_OPCODE_DEVICE_NETCFG_GET_COMMAND, + sizeof(_NetCfgSetGet_t), + sizeof(_NetCfgSetGet_t) +}; + +#if _SL_INCLUDE_FUNC(sl_NetCfgGet) +_i32 sl_NetCfgGet(_u8 ConfigId, _u8 *pConfigOpt,_u8 *pConfigLen, _u8 *pValues) +{ + _SlNetCfgMsgGet_u Msg; + _SlCmdExt_t CmdExt; + + if (*pConfigLen == 0) + { + return SL_EZEROLEN; + } + CmdExt.TxPayloadLen = 0; + CmdExt.RxPayloadLen = *pConfigLen; + CmdExt.pTxPayload = NULL; + CmdExt.pRxPayload = (_u8 *)pValues; + CmdExt.ActualRxPayloadLen = 0; + Msg.Cmd.ConfigLen = *pConfigLen; + Msg.Cmd.ConfigId = ConfigId; + + if( pConfigOpt ) + { + Msg.Cmd.ConfigOpt = (_u16)*pConfigOpt; + } + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetCfgGetCmdCtrl, &Msg, &CmdExt)); + + if( pConfigOpt ) + { + *pConfigOpt = (_u8)Msg.Rsp.ConfigOpt; + } + if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen) + { + *pConfigLen = (_u8)CmdExt.RxPayloadLen; + return SL_ESMALLBUF; + } + else + { + *pConfigLen = (_u8)CmdExt.ActualRxPayloadLen; + } + + return (_i16)Msg.Rsp.Status; +} +#endif + diff --git a/drivers/cc3100/src/nonos.c b/drivers/cc3100/src/nonos.c new file mode 100644 index 0000000000..9e7d1772e2 --- /dev/null +++ b/drivers/cc3100/src/nonos.c @@ -0,0 +1,153 @@ +/* +* nonos.c - CC31xx/CC32xx Host Driver Implementation +* +* Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ +* +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the +* distribution. +* +* Neither the name of Texas Instruments Incorporated nor the names of +* its contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + + + +/*****************************************************************************/ +/* Include files */ +/*****************************************************************************/ +#include "simplelink.h" +#include "protocol.h" +#include "driver.h" + +#ifndef SL_PLATFORM_MULTI_THREADED + +#include "nonos.h" + +#define NONOS_MAX_SPAWN_ENTRIES 5 + +typedef struct +{ + _SlSpawnEntryFunc_t pEntry; + void* pValue; +}_SlNonOsSpawnEntry_t; + +typedef struct +{ + _SlNonOsSpawnEntry_t SpawnEntries[NONOS_MAX_SPAWN_ENTRIES]; +}_SlNonOsCB_t; + +_SlNonOsCB_t g__SlNonOsCB; + + +_SlNonOsRetVal_t _SlNonOsSemSet(_SlNonOsSemObj_t* pSemObj , _SlNonOsSemObj_t Value) +{ + *pSemObj = Value; + return NONOS_RET_OK; +} + +_SlNonOsRetVal_t _SlNonOsSemGet(_SlNonOsSemObj_t* pSyncObj, _SlNonOsSemObj_t WaitValue, _SlNonOsSemObj_t SetValue, _SlNonOsTime_t Timeout) +{ + while (Timeout>0) + { + if (WaitValue == *pSyncObj) + { + *pSyncObj = SetValue; + break; + } + if (Timeout != NONOS_WAIT_FOREVER) + { + Timeout--; + } + _SlNonOsMainLoopTask(); +#ifdef _SlSyncWaitLoopCallback + if( __NON_OS_SYNC_OBJ_SIGNAL_VALUE == WaitValue ) + { + if (WaitValue == *pSyncObj) + { + *pSyncObj = SetValue; + break; + } + _SlSyncWaitLoopCallback(); + } +#endif + } + + if (0 == Timeout) + { + return NONOS_RET_ERR; + } + else + { + return NONOS_RET_OK; + } +} + + +_SlNonOsRetVal_t _SlNonOsSpawn(_SlSpawnEntryFunc_t pEntry , void* pValue , _u32 flags) +{ + _i16 i; + + for (i=0 ; i<NONOS_MAX_SPAWN_ENTRIES ; i++) + { + _SlNonOsSpawnEntry_t* pE = &g__SlNonOsCB.SpawnEntries[i]; + + if (NULL == pE->pEntry) + { + pE->pValue = pValue; + pE->pEntry = pEntry; + break; + } + } + + return NONOS_RET_OK; +} + + +_SlNonOsRetVal_t _SlNonOsMainLoopTask(void) +{ + _i16 i; + + for (i=0 ; i<NONOS_MAX_SPAWN_ENTRIES ; i++) + { + _SlNonOsSpawnEntry_t* pE = &g__SlNonOsCB.SpawnEntries[i]; + _SlSpawnEntryFunc_t pF = pE->pEntry; + + if (NULL != pF) + { + if((g_pCB)->RxIrqCnt != (g_pCB)->RxDoneCnt) + { + pF(0);/*(pValue);*/ + } + pE->pEntry = NULL; + pE->pValue = NULL; + } + } + + return NONOS_RET_OK; +} + +#endif /*(SL_PLATFORM != SL_PLATFORM_NON_OS)*/ diff --git a/drivers/cc3100/src/socket.c b/drivers/cc3100/src/socket.c new file mode 100644 index 0000000000..34dd4a8b43 --- /dev/null +++ b/drivers/cc3100/src/socket.c @@ -0,0 +1,1123 @@ +/* + * socket.c - CC31xx/CC32xx Host Driver Implementation + * + * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +*/ + + + + +/*****************************************************************************/ +/* Include files */ +/*****************************************************************************/ +#include "simplelink.h" +#include "protocol.h" +#include "driver.h" + + +/*******************************************************************************/ +/* Functions prototypes */ +/*******************************************************************************/ +void _sl_BuildAddress(const SlSockAddr_t *addr, _i16 addrlen, _SocketAddrCommand_u *pCmd); +void _sl_ParseAddress(_SocketAddrResponse_u *pRsp, SlSockAddr_t *addr, SlSocklen_t *addrlen); +void _sl_HandleAsync_Connect(void *pVoidBuf); +void _sl_HandleAsync_Accept(void *pVoidBuf); +void _sl_HandleAsync_Select(void *pVoidBuf); +_u16 _sl_TruncatePayloadByProtocol(const _i16 pSd,const _u16 length); + +/*******************************************************************************/ +/* Functions */ +/*******************************************************************************/ + +/* ******************************************************************************/ +/* _sl_BuildAddress */ +/* ******************************************************************************/ +void _sl_BuildAddress(const SlSockAddr_t *addr, _i16 addrlen, _SocketAddrCommand_u *pCmd) +{ + + /* Note: parsing of family and port in the generic way for all IPV4, IPV6 and EUI48 */ + /* is possible as _i32 as these parameters are in the same offset and size for these */ + /* three families. */ + pCmd->IpV4.FamilyAndFlags = (addr->sa_family << 4) & 0xF0; + pCmd->IpV4.port = ((SlSockAddrIn_t *)addr)->sin_port; + + if(SL_AF_INET == addr->sa_family) + { + pCmd->IpV4.address = ((SlSockAddrIn_t *)addr)->sin_addr.s_addr; + } + else if (SL_AF_INET6_EUI_48 == addr->sa_family ) + { + sl_Memcpy( pCmd->IpV6EUI48.address,((SlSockAddrIn6_t *)addr)->sin6_addr._S6_un._S6_u8, 6); + } +#ifdef SL_SUPPORT_IPV6 + else + { + sl_Memcpy(pCmd->IpV6.address, ((sockaddr_in6 *)addr)->sin6_addr._S6_un._S6_u32, 16 ); + } +#endif +} + +/* ******************************************************************************/ +/* _sl_TruncatePayloadByProtocol */ +/* ******************************************************************************/ +_u16 _sl_TruncatePayloadByProtocol(const _i16 sd,const _u16 length) +{ + _u16 maxLength; + + switch(sd & SL_SOCKET_PAYLOAD_TYPE_MASK) + { + case SL_SOCKET_PAYLOAD_TYPE_UDP_IPV4: + maxLength = 1472; + break; + + case SL_SOCKET_PAYLOAD_TYPE_TCP_IPV4: + maxLength = 1460; + break; + + case SL_SOCKET_PAYLOAD_TYPE_UDP_IPV6: + maxLength = 1452; + break; + + case SL_SOCKET_PAYLOAD_TYPE_TCP_IPV6: + maxLength = 1440; + break; + case SL_SOCKET_PAYLOAD_TYPE_TCP_IPV4_SECURE: + case SL_SOCKET_PAYLOAD_TYPE_UDP_IPV4_SECURE: + maxLength = 1402; + break; + case SL_SOCKET_PAYLOAD_TYPE_UDP_IPV6_SECURE: + case SL_SOCKET_PAYLOAD_TYPE_TCP_IPV6_SECURE: + maxLength = 1396; + break; + case SL_SOCKET_PAYLOAD_TYPE_RAW_TRANCEIVER: + maxLength = 1476; + break; + case SL_SOCKET_PAYLOAD_TYPE_RAW_PACKET: + maxLength = 1514; + break; + case SL_SOCKET_PAYLOAD_TYPE_RAW_IP4: + maxLength = 1480; + break; + default: + maxLength = 1440; + break; + } + + if( length > maxLength ) + { + return maxLength; + } + else + { + return length; + } +} + +/*******************************************************************************/ +/* _sl_ParseAddress */ +/*******************************************************************************/ +void _sl_ParseAddress(_SocketAddrResponse_u *pRsp, SlSockAddr_t *addr, SlSocklen_t *addrlen) +{ + /* Note: parsing of family and port in the generic way for all IPV4, IPV6 and EUI48 */ + /* is possible as long as these parameters are in the same offset and size for these */ + /* three families. */ + addr->sa_family = pRsp->IpV4.family; + ((SlSockAddrIn_t *)addr)->sin_port = pRsp->IpV4.port; + + *addrlen = (SL_AF_INET == addr->sa_family) ? sizeof(SlSockAddrIn_t) : sizeof(SlSockAddrIn6_t); + + if(SL_AF_INET == addr->sa_family) + { + ((SlSockAddrIn_t *)addr)->sin_addr.s_addr = pRsp->IpV4.address; + } + else if (SL_AF_INET6_EUI_48 == addr->sa_family ) + { + sl_Memcpy(((SlSockAddrIn6_t *)addr)->sin6_addr._S6_un._S6_u8, pRsp->IpV6EUI48.address, 6); + } +#ifdef SL_SUPPORT_IPV6 + else + { + sl_Memcpy(((sockaddr_in6 *)addr)->sin6_addr._S6_un._S6_u32, pRsp->IpV6.address, 16); + } +#endif +} + +/*******************************************************************************/ +/* sl_Socket */ +/*******************************************************************************/ +typedef union +{ + _u32 Dummy; + _SocketCommand_t Cmd; + _SocketResponse_t Rsp; +}_SlSockSocketMsg_u; + +const _SlCmdCtrl_t _SlSockSocketCmdCtrl = +{ + SL_OPCODE_SOCKET_SOCKET, + sizeof(_SocketCommand_t), + sizeof(_SocketResponse_t) +}; + +#if _SL_INCLUDE_FUNC(sl_Socket) +_i16 sl_Socket(_i16 Domain, _i16 Type, _i16 Protocol) +{ + _SlSockSocketMsg_u Msg; + + Msg.Cmd.Domain = (_u8)Domain; + Msg.Cmd.Type = (_u8)Type; + Msg.Cmd.Protocol = (_u8)Protocol; + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlSockSocketCmdCtrl, &Msg, NULL)); + + if( Msg.Rsp.statusOrLen < 0 ) + { + return( Msg.Rsp.statusOrLen ); + } + else + { + return (_i16)((_u8)Msg.Rsp.sd); +} +} +#endif + +/*******************************************************************************/ +/* sl_Close */ +/*******************************************************************************/ +typedef union +{ + _CloseCommand_t Cmd; + _SocketResponse_t Rsp; +}_SlSockCloseMsg_u; + +const _SlCmdCtrl_t _SlSockCloseCmdCtrl = +{ + SL_OPCODE_SOCKET_CLOSE, + sizeof(_CloseCommand_t), + sizeof(_SocketResponse_t) +}; + +#if _SL_INCLUDE_FUNC(sl_Close) +_i16 sl_Close(_i16 sd) +{ + _SlSockCloseMsg_u Msg; + + Msg.Cmd.sd = (_u8)sd; + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlSockCloseCmdCtrl, &Msg, NULL)); + + return Msg.Rsp.statusOrLen; +} +#endif + +/*******************************************************************************/ +/* sl_Bind */ +/*******************************************************************************/ +typedef union +{ + _SocketAddrCommand_u Cmd; + _SocketResponse_t Rsp; +}_SlSockBindMsg_u; + +#if _SL_INCLUDE_FUNC(sl_Bind) +_i16 sl_Bind(_i16 sd, const SlSockAddr_t *addr, _i16 addrlen) +{ + _SlSockBindMsg_u Msg; + _SlCmdCtrl_t CmdCtrl = {0, 0, sizeof(_SocketResponse_t)}; + + switch(addr->sa_family) + { + case SL_AF_INET : + CmdCtrl.Opcode = SL_OPCODE_SOCKET_BIND; + CmdCtrl.TxDescLen = sizeof(_SocketAddrIPv4Command_t); + break; + case SL_AF_INET6_EUI_48: + CmdCtrl.Opcode = SL_OPCODE_SOCKET_BIND_V6; + CmdCtrl.TxDescLen = sizeof(_SocketAddrIPv6EUI48Command_t); + break; +#ifdef SL_SUPPORT_IPV6 + case AF_INET6: + CmdCtrl.Opcode = SL_OPCODE_SOCKET_BIND_V6; + CmdCtrl.TxDescLen = sizeof(_SocketAddrIPv6Command_t); + break; +#endif + case SL_AF_RF : + default: + return SL_RET_CODE_INVALID_INPUT; + } + + Msg.Cmd.IpV4.lenOrPadding = 0; + Msg.Cmd.IpV4.sd = (_u8)sd; + + _sl_BuildAddress(addr, addrlen, &Msg.Cmd); + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&CmdCtrl, &Msg, NULL)); + + return Msg.Rsp.statusOrLen; +} +#endif + +/*******************************************************************************/ +/* sl_Sendto */ +/*******************************************************************************/ +typedef union +{ + _SocketAddrCommand_u Cmd; + /* no response for 'sendto' commands*/ +}_SlSendtoMsg_u; + +#if _SL_INCLUDE_FUNC(sl_SendTo) +_i16 sl_SendTo(_i16 sd, const void *pBuf, _i16 Len, _i16 flags, const SlSockAddr_t *to, SlSocklen_t tolen) +{ + _SlSendtoMsg_u Msg; + _SlCmdCtrl_t CmdCtrl = {0, 0, 0}; + _SlCmdExt_t CmdExt; + _u16 ChunkLen; + _i16 RetVal; + + CmdExt.TxPayloadLen = (_u16)Len; + CmdExt.RxPayloadLen = 0; + CmdExt.pTxPayload = (_u8 *)pBuf; + CmdExt.pRxPayload = NULL; + + + switch(to->sa_family) + { + case SL_AF_INET: + CmdCtrl.Opcode = SL_OPCODE_SOCKET_SENDTO; + CmdCtrl.TxDescLen = sizeof(_SocketAddrIPv4Command_t); + break; + case SL_AF_INET6_EUI_48: + CmdCtrl.Opcode = SL_OPCODE_SOCKET_BIND_V6; + CmdCtrl.TxDescLen = sizeof(_SocketAddrIPv6EUI48Command_t); + break; +#ifdef SL_SUPPORT_IPV6 + case AF_INET6: + CmdCtrl.Opcode = SL_OPCODE_SOCKET_SENDTO_V6; + CmdCtrl.TxDescLen = sizeof(_SocketAddrIPv6Command_t); + break; +#endif + case SL_AF_RF: + default: + return SL_RET_CODE_INVALID_INPUT; + } + + ChunkLen = _sl_TruncatePayloadByProtocol(sd,Len); + Msg.Cmd.IpV4.lenOrPadding = ChunkLen; + CmdExt.TxPayloadLen = ChunkLen; + + Msg.Cmd.IpV4.sd = (_u8)sd; + + _sl_BuildAddress(to, tolen, &Msg.Cmd); + + Msg.Cmd.IpV4.FamilyAndFlags |= flags & 0x0F; + + do + { + RetVal = _SlDrvDataWriteOp((_SlSd_t)sd, &CmdCtrl, &Msg, &CmdExt); + + if(SL_OS_RET_CODE_OK == RetVal) + { + CmdExt.pTxPayload += ChunkLen; + ChunkLen = (_u16)((_u8 *)pBuf + Len - CmdExt.pTxPayload); + ChunkLen = _sl_TruncatePayloadByProtocol(sd,ChunkLen); + CmdExt.TxPayloadLen = ChunkLen; + Msg.Cmd.IpV4.lenOrPadding = ChunkLen; + } + else + { + return RetVal; + } + }while(ChunkLen > 0); + + return (_i16)Len; +} +#endif + +/*******************************************************************************/ +/* sl_Recvfrom */ +/*******************************************************************************/ +typedef union +{ + _sendRecvCommand_t Cmd; + _SocketAddrResponse_u Rsp; +}_SlRecvfromMsg_u; + +const _SlCmdCtrl_t _SlRecvfomCmdCtrl = +{ + SL_OPCODE_SOCKET_RECVFROM, + sizeof(_sendRecvCommand_t), + sizeof(_SocketAddrResponse_u) +}; + +#if _SL_INCLUDE_FUNC(sl_RecvFrom) +_i16 sl_RecvFrom(_i16 sd, void *buf, _i16 Len, _i16 flags, SlSockAddr_t *from, SlSocklen_t *fromlen) +{ + _SlRecvfromMsg_u Msg; + _SlCmdExt_t CmdExt; + _i16 RetVal; + + CmdExt.TxPayloadLen = 0; + CmdExt.RxPayloadLen = Len; + CmdExt.pTxPayload = NULL; + CmdExt.pRxPayload = (_u8 *)buf; + + + Msg.Cmd.sd = (_u8)sd; + Msg.Cmd.StatusOrLen = Len; + /* no size truncation in recv path */ + CmdExt.RxPayloadLen = Msg.Cmd.StatusOrLen; + + if(sizeof(SlSockAddrIn_t) == *fromlen) + { + Msg.Cmd.FamilyAndFlags = SL_AF_INET; + } + else if (sizeof(SlSockAddrIn6_t) == *fromlen) + { + Msg.Cmd.FamilyAndFlags = SL_AF_INET6; + } + else + { + return SL_RET_CODE_INVALID_INPUT; + } + + Msg.Cmd.FamilyAndFlags = (Msg.Cmd.FamilyAndFlags << 4) & 0xF0; + Msg.Cmd.FamilyAndFlags |= flags & 0x0F; + + RetVal = _SlDrvDataReadOp((_SlSd_t)sd, (_SlCmdCtrl_t *)&_SlRecvfomCmdCtrl, &Msg, &CmdExt); + if( RetVal != SL_OS_RET_CODE_OK ) + { + return RetVal; + } + + RetVal = Msg.Rsp.IpV4.statusOrLen; + + if(RetVal >= 0) + { + VERIFY_PROTOCOL(sd == Msg.Rsp.IpV4.sd); +#if 0 + _sl_ParseAddress(&Msg.Rsp, from, fromlen); +#else + from->sa_family = Msg.Rsp.IpV4.family; + if(SL_AF_INET == from->sa_family) + { + ((SlSockAddrIn_t *)from)->sin_port = Msg.Rsp.IpV4.port; + ((SlSockAddrIn_t *)from)->sin_addr.s_addr = Msg.Rsp.IpV4.address; + *fromlen = sizeof(SlSockAddrIn_t); + } + else if (SL_AF_INET6_EUI_48 == from->sa_family ) + { + ((SlSockAddrIn6_t *)from)->sin6_port = Msg.Rsp.IpV6EUI48.port; + sl_Memcpy(((SlSockAddrIn6_t *)from)->sin6_addr._S6_un._S6_u8, Msg.Rsp.IpV6EUI48.address, 6); + } +#ifdef SL_SUPPORT_IPV6 + else if(AF_INET6 == from->sa_family) + { + VERIFY_PROTOCOL(*fromlen >= sizeof(sockaddr_in6)); + + ((sockaddr_in6 *)from)->sin6_port = Msg.Rsp.IpV6.port; + sl_Memcpy(((sockaddr_in6 *)from)->sin6_addr._S6_un._S6_u32, Msg.Rsp.IpV6.address, 16); + *fromlen = sizeof(sockaddr_in6); + } +#endif +#endif + } + + return (_i16)RetVal; +} +#endif + +/*******************************************************************************/ +/* sl_Connect */ +/*******************************************************************************/ +typedef union +{ + _SocketAddrCommand_u Cmd; + _SocketResponse_t Rsp; +}_SlSockConnectMsg_u; + +#if _SL_INCLUDE_FUNC(sl_Connect) +_i16 sl_Connect(_i16 sd, const SlSockAddr_t *addr, _i16 addrlen) +{ + _SlSockConnectMsg_u Msg; + _SlReturnVal_t RetVal; + _SlCmdCtrl_t CmdCtrl = {0, 0, sizeof(_SocketResponse_t)}; + _SocketResponse_t AsyncRsp; + _u8 ObjIdx = MAX_CONCURRENT_ACTIONS; + + + switch(addr->sa_family) + { + case SL_AF_INET : + CmdCtrl.Opcode = SL_OPCODE_SOCKET_CONNECT; + CmdCtrl.TxDescLen = sizeof(_SocketAddrIPv4Command_t); + break; + case SL_AF_INET6_EUI_48: + CmdCtrl.Opcode = SL_OPCODE_SOCKET_CONNECT_V6; + CmdCtrl.TxDescLen = sizeof(_SocketAddrIPv6EUI48Command_t); + break; +#ifdef SL_SUPPORT_IPV6 + case AF_INET6: + CmdCtrl.Opcode = SL_OPCODE_SOCKET_CONNECT_V6; + CmdCtrl.TxDescLen = sizeof(_SocketAddrIPv6Command_t); + break; +#endif + case SL_AF_RF : + default: + return SL_RET_CODE_INVALID_INPUT; + } + + Msg.Cmd.IpV4.lenOrPadding = 0; + Msg.Cmd.IpV4.sd = (_u8)sd; + + _sl_BuildAddress(addr, addrlen, &Msg.Cmd); + + /* Use Obj to issue the command, if not available try later */ + ObjIdx = (_u8)_SlDrvWaitForPoolObj(CONNECT_ID, (_u8)(sd & BSD_SOCKET_ID_MASK)); + + if (MAX_CONCURRENT_ACTIONS == ObjIdx) + { + return SL_POOL_IS_EMPTY; + } + OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); + + g_pCB->ObjPool[ObjIdx].pRespArgs = (_u8 *)&AsyncRsp; + + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); + + /* send the command */ + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&CmdCtrl, &Msg, NULL)); + VERIFY_PROTOCOL(Msg.Rsp.sd == sd) + + RetVal = Msg.Rsp.statusOrLen; + + if(SL_RET_CODE_OK == RetVal) + { + /* wait for async and get Data Read parameters */ + OSI_RET_OK_CHECK(sl_SyncObjWait(&g_pCB->ObjPool[ObjIdx].SyncObj, SL_OS_WAIT_FOREVER)); + + VERIFY_PROTOCOL(AsyncRsp.sd == sd); + + RetVal = AsyncRsp.statusOrLen; + } + _SlDrvReleasePoolObj(ObjIdx); + return RetVal; +} +#endif + +/*******************************************************************************/ +/* _sl_HandleAsync_Connect */ +/*******************************************************************************/ +void _sl_HandleAsync_Connect(void *pVoidBuf) +{ + _SocketResponse_t *pMsgArgs = (_SocketResponse_t *)_SL_RESP_ARGS_START(pVoidBuf); + + OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); + + VERIFY_PROTOCOL((pMsgArgs->sd & BSD_SOCKET_ID_MASK) <= SL_MAX_SOCKETS); + VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs); + + ((_SocketResponse_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->sd = pMsgArgs->sd; + ((_SocketResponse_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->statusOrLen = pMsgArgs->statusOrLen; + + OSI_RET_OK_CHECK(sl_SyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj)); + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); + return; +} + +/*******************************************************************************/ +/* sl_Send */ +/*******************************************************************************/ +typedef union +{ + _sendRecvCommand_t Cmd; + /* no response for 'sendto' commands*/ +}_SlSendMsg_u; + +const _SlCmdCtrl_t _SlSendCmdCtrl = +{ + SL_OPCODE_SOCKET_SEND, + sizeof(_sendRecvCommand_t), + 0 +}; + +#if _SL_INCLUDE_FUNC(sl_Send) +_i16 sl_Send(_i16 sd, const void *pBuf, _i16 Len, _i16 flags) +{ + _SlSendMsg_u Msg; + _SlCmdExt_t CmdExt; + _u16 ChunkLen; + _i16 RetVal; + _u32 tempVal; + _u8 runSingleChunk = FALSE; + + CmdExt.TxPayloadLen = Len; + CmdExt.RxPayloadLen = 0; + CmdExt.pTxPayload = (_u8 *)pBuf; + + /* Only for RAW transceiver type socket, relay the flags parameter in the 2 bytes (4 byte aligned) before the actual payload */ + if ((sd & SL_SOCKET_PAYLOAD_TYPE_MASK) == SL_SOCKET_PAYLOAD_TYPE_RAW_TRANCEIVER) + { + tempVal = flags; + CmdExt.pRxPayload = (_u8 *)&tempVal; + CmdExt.RxPayloadLen = 4; + g_pCB->RelayFlagsViaRxPayload = TRUE; + runSingleChunk = TRUE; + } + else + { + CmdExt.pRxPayload = NULL; + } + + ChunkLen = _sl_TruncatePayloadByProtocol(sd,Len); + CmdExt.TxPayloadLen = ChunkLen; + + Msg.Cmd.StatusOrLen = ChunkLen; + Msg.Cmd.sd = (_u8)sd; + Msg.Cmd.FamilyAndFlags |= flags & 0x0F; + + do + { + RetVal = _SlDrvDataWriteOp((_u8)sd, (_SlCmdCtrl_t *)&_SlSendCmdCtrl, &Msg, &CmdExt); + if(SL_OS_RET_CODE_OK == RetVal) + { + CmdExt.pTxPayload += ChunkLen; + ChunkLen = (_u8 *)pBuf + Len - CmdExt.pTxPayload; + ChunkLen = _sl_TruncatePayloadByProtocol(sd,ChunkLen); + CmdExt.TxPayloadLen = ChunkLen; + Msg.Cmd.StatusOrLen = ChunkLen; + } + else + { + return RetVal; + } + }while((ChunkLen > 0) && (runSingleChunk==FALSE)); + + return (_i16)Len; +} +#endif + +/*******************************************************************************/ +/* sl_Listen */ +/*******************************************************************************/ +typedef union +{ + _ListenCommand_t Cmd; + _BasicResponse_t Rsp; +}_SlListenMsg_u; + +const _SlCmdCtrl_t _SlListenCmdCtrl = +{ + SL_OPCODE_SOCKET_LISTEN, + sizeof(_ListenCommand_t), + sizeof(_BasicResponse_t), +}; + +#if _SL_INCLUDE_FUNC(sl_Listen) +_i16 sl_Listen(_i16 sd, _i16 backlog) +{ + _SlListenMsg_u Msg; + + Msg.Cmd.sd = (_u8)sd; + Msg.Cmd.backlog = (_u8)backlog; + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlListenCmdCtrl, &Msg, NULL)); + + return (_i16)Msg.Rsp.status; +} +#endif + +/*******************************************************************************/ +/* sl_Accept */ +/*******************************************************************************/ +typedef union +{ + _AcceptCommand_t Cmd; + _SocketResponse_t Rsp; +}_SlSockAcceptMsg_u; + +const _SlCmdCtrl_t _SlAcceptCmdCtrl = +{ + SL_OPCODE_SOCKET_ACCEPT, + sizeof(_AcceptCommand_t), + sizeof(_BasicResponse_t), +}; + +#if _SL_INCLUDE_FUNC(sl_Accept) +_i16 sl_Accept(_i16 sd, SlSockAddr_t *addr, SlSocklen_t *addrlen) +{ + _SlSockAcceptMsg_u Msg; + _SlReturnVal_t RetVal; + _SocketAddrResponse_u AsyncRsp; + + _u8 ObjIdx = MAX_CONCURRENT_ACTIONS; + + + Msg.Cmd.sd = (_u8)sd; + Msg.Cmd.family = (sizeof(SlSockAddrIn_t) == *addrlen) ? SL_AF_INET : SL_AF_INET6; + + /* Use Obj to issue the command, if not available try later */ + ObjIdx = (_u8)_SlDrvWaitForPoolObj(ACCEPT_ID, (_u8)(sd & BSD_SOCKET_ID_MASK)); + + if (MAX_CONCURRENT_ACTIONS == ObjIdx) + { + return SL_POOL_IS_EMPTY; + } + + OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); + + g_pCB->ObjPool[ObjIdx].pRespArgs = (_u8 *)&AsyncRsp; + + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); + /* send the command */ + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlAcceptCmdCtrl, &Msg, NULL)); + VERIFY_PROTOCOL(Msg.Rsp.sd == sd); + + RetVal = Msg.Rsp.statusOrLen; + + if(SL_OS_RET_CODE_OK == RetVal) + { + /* wait for async and get Data Read parameters */ + OSI_RET_OK_CHECK(sl_SyncObjWait(&g_pCB->ObjPool[ObjIdx].SyncObj, SL_OS_WAIT_FOREVER)); + + VERIFY_PROTOCOL(AsyncRsp.IpV4.sd == sd); + + RetVal = AsyncRsp.IpV4.statusOrLen; + if( (NULL != addr) && (NULL != addrlen) ) + { +#if 0 /* Kept for backup */ + _sl_ParseAddress(&AsyncRsp, addr, addrlen); +#else + addr->sa_family = AsyncRsp.IpV4.family; + + if(SL_AF_INET == addr->sa_family) + { + if( *addrlen == sizeof( SlSockAddrIn_t ) ) + { + ((SlSockAddrIn_t *)addr)->sin_port = AsyncRsp.IpV4.port; + ((SlSockAddrIn_t *)addr)->sin_addr.s_addr = AsyncRsp.IpV4.address; + } + else + { + *addrlen = 0; + } + } + else if (SL_AF_INET6_EUI_48 == addr->sa_family ) + { + if( *addrlen == sizeof( SlSockAddrIn6_t ) ) + { + ((SlSockAddrIn6_t *)addr)->sin6_port = AsyncRsp.IpV6EUI48.port ; + /* will be called from here and from _sl_BuildAddress*/ + sl_Memcpy(((SlSockAddrIn6_t *)addr)->sin6_addr._S6_un._S6_u8, AsyncRsp.IpV6EUI48.address, 6); + } + else + { + *addrlen = 0; + } + } +#ifdef SL_SUPPORT_IPV6 + else + { + if( *addrlen == sizeof( sockaddr_in6 ) ) + { + ((sockaddr_in6 *)addr)->sin6_port = AsyncRsp.IpV6.port ; + sl_Memcpy(((sockaddr_in6 *)addr)->sin6_addr._S6_un._S6_u32, AsyncRsp.IpV6.address, 16); + } + else + { + *addrlen = 0; + } + } +#endif +#endif + } + } + + _SlDrvReleasePoolObj(ObjIdx); + return (_i16)RetVal; +} +#endif + + +/*******************************************************************************/ +/* sl_Htonl */ +/*******************************************************************************/ +_u32 sl_Htonl( _u32 val ) +{ + _u32 i = 1; + _i8 *p = (_i8 *)&i; + if (p[0] == 1) /* little endian */ + { + p[0] = ((_i8* )&val)[3]; + p[1] = ((_i8* )&val)[2]; + p[2] = ((_i8* )&val)[1]; + p[3] = ((_i8* )&val)[0]; + return i; + } + else /* big endian */ + { + return val; + } +} + +/*******************************************************************************/ +/* sl_Htonl */ +/*******************************************************************************/ +_u16 sl_Htons( _u16 val ) +{ + _i16 i = 1; + _i8 *p = (_i8 *)&i; + if (p[0] == 1) /* little endian */ + { + p[0] = ((_i8* )&val)[1]; + p[1] = ((_i8* )&val)[0]; + return i; + } + else /* big endian */ + { + return val; + } +} + +/*******************************************************************************/ +/* _sl_HandleAsync_Accept */ +/*******************************************************************************/ +void _sl_HandleAsync_Accept(void *pVoidBuf) +{ + _SocketAddrResponse_u *pMsgArgs = (_SocketAddrResponse_u *)_SL_RESP_ARGS_START(pVoidBuf); + + OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); + + VERIFY_PROTOCOL(( pMsgArgs->IpV4.sd & BSD_SOCKET_ID_MASK) <= SL_MAX_SOCKETS); + VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs); + + sl_Memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs,sizeof(_SocketAddrResponse_u)); + OSI_RET_OK_CHECK(sl_SyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj)); + + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); + return; +} + +/*******************************************************************************/ +/* sl_Recv */ +/*******************************************************************************/ +typedef union +{ + _sendRecvCommand_t Cmd; + _SocketResponse_t Rsp; +}_SlRecvMsg_u; + +const _SlCmdCtrl_t _SlRecvCmdCtrl = +{ + SL_OPCODE_SOCKET_RECV, + sizeof(_sendRecvCommand_t), + sizeof(_SocketResponse_t) +}; + +#if _SL_INCLUDE_FUNC(sl_Recv) +_i16 sl_Recv(_i16 sd, void *pBuf, _i16 Len, _i16 flags) +{ + _SlRecvMsg_u Msg; + _SlCmdExt_t CmdExt; + _SlReturnVal_t status; + + CmdExt.TxPayloadLen = 0; + CmdExt.RxPayloadLen = Len; + CmdExt.pTxPayload = NULL; + CmdExt.pRxPayload = (_u8 *)pBuf; + + Msg.Cmd.sd = (_u8)sd; + Msg.Cmd.StatusOrLen = Len; + + /* no size truncation in recv path */ + CmdExt.RxPayloadLen = Msg.Cmd.StatusOrLen; + + Msg.Cmd.FamilyAndFlags = flags & 0x0F; + + status = _SlDrvDataReadOp((_SlSd_t)sd, (_SlCmdCtrl_t *)&_SlRecvCmdCtrl, &Msg, &CmdExt); + if( status != SL_OS_RET_CODE_OK ) + { + return status; + } + + /* if the Device side sends less than expected it is not the Driver's role */ + /* the returned value could be smaller than the requested size */ + return (_i16)Msg.Rsp.statusOrLen; +} +#endif + +/*******************************************************************************/ +/* sl_SetSockOpt */ +/*******************************************************************************/ +typedef union +{ + _setSockOptCommand_t Cmd; + _SocketResponse_t Rsp; +}_SlSetSockOptMsg_u; + +const _SlCmdCtrl_t _SlSetSockOptCmdCtrl = +{ + SL_OPCODE_SOCKET_SETSOCKOPT, + sizeof(_setSockOptCommand_t), + sizeof(_SocketResponse_t) +}; + +#if _SL_INCLUDE_FUNC(sl_SetSockOpt) +_i16 sl_SetSockOpt(_i16 sd, _i16 level, _i16 optname, const void *optval, SlSocklen_t optlen) +{ + _SlSetSockOptMsg_u Msg; + _SlCmdExt_t CmdExt; + + CmdExt.TxPayloadLen = optlen; + CmdExt.RxPayloadLen = 0; + CmdExt.pTxPayload = (_u8 *)optval; + CmdExt.pRxPayload = NULL; + + Msg.Cmd.sd = (_u8)sd; + Msg.Cmd.level = (_u8)level; + Msg.Cmd.optionLen = (_u8)optlen; + Msg.Cmd.optionName = (_u8)optname; + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlSetSockOptCmdCtrl, &Msg, &CmdExt)); + + return (_i16)Msg.Rsp.statusOrLen; +} +#endif + +/*******************************************************************************/ +/* sl_GetSockOpt */ +/*******************************************************************************/ +typedef union +{ + _getSockOptCommand_t Cmd; + _getSockOptResponse_t Rsp; +}_SlGetSockOptMsg_u; + +const _SlCmdCtrl_t _SlGetSockOptCmdCtrl = +{ + SL_OPCODE_SOCKET_GETSOCKOPT, + sizeof(_getSockOptCommand_t), + sizeof(_getSockOptResponse_t) +}; + +#if _SL_INCLUDE_FUNC(sl_GetSockOpt) +_i16 sl_GetSockOpt(_i16 sd, _i16 level, _i16 optname, void *optval, SlSocklen_t *optlen) +{ + _SlGetSockOptMsg_u Msg; + _SlCmdExt_t CmdExt; + + if (*optlen == 0) + { + return SL_EZEROLEN; + } + CmdExt.TxPayloadLen = 0; + CmdExt.RxPayloadLen = *optlen; + CmdExt.pTxPayload = NULL; + CmdExt.pRxPayload = optval; + CmdExt.ActualRxPayloadLen = 0; + + Msg.Cmd.sd = (_u8)sd; + Msg.Cmd.level = (_u8)level; + Msg.Cmd.optionLen = (_u8)(*optlen); + Msg.Cmd.optionName = (_u8)optname; + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlGetSockOptCmdCtrl, &Msg, &CmdExt)); + + if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen) + { + *optlen = Msg.Rsp.optionLen; + return SL_ESMALLBUF; + } + else + { + *optlen = (_u8)CmdExt.ActualRxPayloadLen; + } + return (_i16)Msg.Rsp.status; +} +#endif + +/*******************************************************************************/ +/* sl_Select */ +/* ******************************************************************************/ +typedef union +{ + _SelectCommand_t Cmd; + _BasicResponse_t Rsp; +}_SlSelectMsg_u; + +const _SlCmdCtrl_t _SlSelectCmdCtrl = +{ + SL_OPCODE_SOCKET_SELECT, + sizeof(_SelectCommand_t), + sizeof(_BasicResponse_t) +}; + +#if _SL_INCLUDE_FUNC(sl_Select) +_i16 sl_Select(_i16 nfds, SlFdSet_t *readsds, SlFdSet_t *writesds, SlFdSet_t *exceptsds, struct SlTimeval_t *timeout) +{ + _SlSelectMsg_u Msg; + _SelectAsyncResponse_t AsyncRsp; + _u8 ObjIdx = MAX_CONCURRENT_ACTIONS; + + Msg.Cmd.nfds = (_u8)nfds; + Msg.Cmd.readFdsCount = 0; + Msg.Cmd.writeFdsCount = 0; + + Msg.Cmd.readFds = 0; + Msg.Cmd.writeFds = 0; + + if( readsds ) + { + Msg.Cmd.readFds = (_u16)readsds->fd_array[0]; + } + if( writesds ) + { + Msg.Cmd.writeFds = (_u16)writesds->fd_array[0]; + } + if( NULL == timeout ) + { + Msg.Cmd.tv_sec = 0xffff; + Msg.Cmd.tv_usec = 0xffff; + } + else + { + if( 0xffff <= timeout->tv_sec ) + { + Msg.Cmd.tv_sec = 0xffff; + } + else + { + Msg.Cmd.tv_sec = (_u16)timeout->tv_sec; + } + timeout->tv_usec = timeout->tv_usec >> 10; /* convert to milliseconds */ + if( 0xffff <= timeout->tv_usec ) + { + Msg.Cmd.tv_usec = 0xffff; + } + else + { + Msg.Cmd.tv_usec = (_u16)timeout->tv_usec; + } + } + + /* Use Obj to issue the command, if not available try later */ + ObjIdx = (_u8)_SlDrvWaitForPoolObj(SELECT_ID, SL_MAX_SOCKETS); + + if (MAX_CONCURRENT_ACTIONS == ObjIdx) + { + return SL_POOL_IS_EMPTY; + } + OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); + + g_pCB->ObjPool[ObjIdx].pRespArgs = (_u8 *)&AsyncRsp; + + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); + /* send the command */ + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlSelectCmdCtrl, &Msg, NULL)); + + if(SL_OS_RET_CODE_OK == (_i16)Msg.Rsp.status) + { + OSI_RET_OK_CHECK(sl_SyncObjWait(&g_pCB->ObjPool[ObjIdx].SyncObj, SL_OS_WAIT_FOREVER)); + Msg.Rsp.status = AsyncRsp.status; + + if( ((_i16)Msg.Rsp.status) >= 0 ) + { + if( readsds ) + { + readsds->fd_array[0] = AsyncRsp.readFds; + } + if( writesds ) + { + writesds->fd_array[0] = AsyncRsp.writeFds; + } + } + } + + _SlDrvReleasePoolObj(ObjIdx); + return (_i16)Msg.Rsp.status; +} + +/* Select helper functions */ +/*******************************************************************************/ +/* SL_FD_SET */ +/* ******************************************************************************/ +void SL_FD_SET(_i16 fd, SlFdSet_t *fdset) +{ + fdset->fd_array[0] |= (1<< (fd & BSD_SOCKET_ID_MASK)); +} +/*******************************************************************************/ +/* SL_FD_CLR */ +/*******************************************************************************/ +void SL_FD_CLR(_i16 fd, SlFdSet_t *fdset) +{ + fdset->fd_array[0] &= ~(1<< (fd & BSD_SOCKET_ID_MASK)); +} +/*******************************************************************************/ +/* SL_FD_ISSET */ +/*******************************************************************************/ +_i16 SL_FD_ISSET(_i16 fd, SlFdSet_t *fdset) +{ + if( fdset->fd_array[0] & (1<< (fd & BSD_SOCKET_ID_MASK)) ) + { + return 1; + } + return 0; +} +/*******************************************************************************/ +/* SL_FD_ZERO */ +/*******************************************************************************/ +void SL_FD_ZERO(SlFdSet_t *fdset) +{ + fdset->fd_array[0] = 0; +} + +#endif + +/*******************************************************************************/ +/* _sl_HandleAsync_Select */ +/*******************************************************************************/ +void _sl_HandleAsync_Select(void *pVoidBuf) +{ + _SelectAsyncResponse_t *pMsgArgs = (_SelectAsyncResponse_t *)_SL_RESP_ARGS_START(pVoidBuf); + + OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); + + VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs); + + sl_Memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_SelectAsyncResponse_t)); + OSI_RET_OK_CHECK(sl_SyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj)); + + OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); + return; +} + diff --git a/drivers/cc3100/src/spawn.c b/drivers/cc3100/src/spawn.c new file mode 100644 index 0000000000..fdf1930ca4 --- /dev/null +++ b/drivers/cc3100/src/spawn.c @@ -0,0 +1,197 @@ +/* + * spawn.c - CC31xx/CC32xx Host Driver Implementation + * + * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +*/ + + + +/*****************************************************************************/ +/* Include files */ +/*****************************************************************************/ +#include "simplelink.h" + + +#if (defined (SL_PLATFORM_MULTI_THREADED)) && (!defined (SL_PLATFORM_EXTERNAL_SPAWN)) + +#define _SL_MAX_INTERNAL_SPAWN_ENTRIES 10 + +typedef struct _SlInternalSpawnEntry_t +{ + _SlSpawnEntryFunc_t pEntry; + void* pValue; + struct _SlInternalSpawnEntry_t* pNext; +}_SlInternalSpawnEntry_t; + +typedef struct +{ + _SlInternalSpawnEntry_t SpawnEntries[_SL_MAX_INTERNAL_SPAWN_ENTRIES]; + _SlInternalSpawnEntry_t* pFree; + _SlInternalSpawnEntry_t* pWaitForExe; + _SlInternalSpawnEntry_t* pLastInWaitList; + _SlSyncObj_t SyncObj; + _SlLockObj_t LockObj; +}_SlInternalSpawnCB_t; + +_SlInternalSpawnCB_t g_SlInternalSpawnCB; + + +void _SlInternalSpawnTaskEntry() +{ + _i16 i; + _SlInternalSpawnEntry_t* pEntry; + _u8 LastEntry; + + /* create and lock the locking object. lock in order to avoid race condition + on the first creation */ + sl_LockObjCreate(&g_SlInternalSpawnCB.LockObj,"SlSpawnProtect"); + sl_LockObjLock(&g_SlInternalSpawnCB.LockObj,SL_OS_NO_WAIT); + + /* create and clear the sync object */ + sl_SyncObjCreate(&g_SlInternalSpawnCB.SyncObj,"SlSpawnSync"); + sl_SyncObjWait(&g_SlInternalSpawnCB.SyncObj,SL_OS_NO_WAIT); + + g_SlInternalSpawnCB.pFree = &g_SlInternalSpawnCB.SpawnEntries[0]; + g_SlInternalSpawnCB.pWaitForExe = NULL; + g_SlInternalSpawnCB.pLastInWaitList = NULL; + + /* create the link list between the entries */ + for (i=0 ; i<_SL_MAX_INTERNAL_SPAWN_ENTRIES - 1 ; i++) + { + g_SlInternalSpawnCB.SpawnEntries[i].pNext = &g_SlInternalSpawnCB.SpawnEntries[i+1]; + g_SlInternalSpawnCB.SpawnEntries[i].pEntry = NULL; + } + g_SlInternalSpawnCB.SpawnEntries[i].pNext = NULL; + + sl_LockObjUnlock(&g_SlInternalSpawnCB.LockObj); + + + /* here we ready to execute entries */ + + while (TRUE) + { + sl_SyncObjWait(&g_SlInternalSpawnCB.SyncObj,SL_OS_WAIT_FOREVER); + /* go over all entries that already waiting for execution */ + LastEntry = FALSE; + do + { + /* get entry to execute */ + sl_LockObjLock(&g_SlInternalSpawnCB.LockObj,SL_OS_WAIT_FOREVER); + + pEntry = g_SlInternalSpawnCB.pWaitForExe; + if ( NULL == pEntry ) + { + sl_LockObjUnlock(&g_SlInternalSpawnCB.LockObj); + break; + } + g_SlInternalSpawnCB.pWaitForExe = pEntry->pNext; + if (pEntry == g_SlInternalSpawnCB.pLastInWaitList) + { + g_SlInternalSpawnCB.pLastInWaitList = NULL; + LastEntry = TRUE; + } + + sl_LockObjUnlock(&g_SlInternalSpawnCB.LockObj); + + + /* pEntry could be null in case that the sync was already set by some + of the entries during execution of earlier entry */ + if (NULL != pEntry) + { + pEntry->pEntry(pEntry->pValue); + /* free the entry */ + sl_LockObjLock(&g_SlInternalSpawnCB.LockObj,SL_OS_WAIT_FOREVER); + + pEntry->pNext = g_SlInternalSpawnCB.pFree; + g_SlInternalSpawnCB.pFree = pEntry; + + + if (NULL != g_SlInternalSpawnCB.pWaitForExe) + { + /* new entry received meanwhile */ + LastEntry = FALSE; + } + + sl_LockObjUnlock(&g_SlInternalSpawnCB.LockObj); + + } + + }while (!LastEntry); + } +} + + +_i16 _SlInternalSpawn(_SlSpawnEntryFunc_t pEntry , void* pValue , _u32 flags) +{ + _i16 Res = 0; + _SlInternalSpawnEntry_t* pSpawnEntry; + + if (NULL == pEntry) + { + Res = -1; + } + else + { + sl_LockObjLock(&g_SlInternalSpawnCB.LockObj,SL_OS_WAIT_FOREVER); + + pSpawnEntry = g_SlInternalSpawnCB.pFree; + g_SlInternalSpawnCB.pFree = pSpawnEntry->pNext; + + pSpawnEntry->pEntry = pEntry; + pSpawnEntry->pValue = pValue; + pSpawnEntry->pNext = NULL; + + if (NULL == g_SlInternalSpawnCB.pWaitForExe) + { + g_SlInternalSpawnCB.pWaitForExe = pSpawnEntry; + g_SlInternalSpawnCB.pLastInWaitList = pSpawnEntry; + } + else + { + g_SlInternalSpawnCB.pLastInWaitList->pNext = pSpawnEntry; + g_SlInternalSpawnCB.pLastInWaitList = pSpawnEntry; + } + + sl_LockObjUnlock(&g_SlInternalSpawnCB.LockObj); + /* this sync is called after releasing the lock object to avoid unnecessary context switches */ + sl_SyncObjSignal(&g_SlInternalSpawnCB.SyncObj); + } + + return Res; +} + + + + + +#endif diff --git a/drivers/cc3100/src/wlan.c b/drivers/cc3100/src/wlan.c new file mode 100644 index 0000000000..0cc825439f --- /dev/null +++ b/drivers/cc3100/src/wlan.c @@ -0,0 +1,993 @@ +/* +* wlan.c - CC31xx/CC32xx Host Driver Implementation +* +* Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ +* +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the +* distribution. +* +* Neither the name of Texas Instruments Incorporated nor the names of +* its contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + + + +/*****************************************************************************/ +/* Include files */ +/*****************************************************************************/ +#include <string.h> +#include "simplelink.h" +#include "protocol.h" +#include "driver.h" + +/*****************************************************************************/ +/* Macro declarations */ +/*****************************************************************************/ +#define MAX_SSID_LEN (32) +#define MAX_KEY_LEN (63) +#define MAX_USER_LEN (32) +#define MAX_ANON_USER_LEN (32) +#define MAX_SMART_CONFIG_KEY (16) + + +/***************************************************************************** +sl_WlanConnect +*****************************************************************************/ +typedef struct +{ + _WlanConnectEapCommand_t Args; + _i8 Strings[MAX_SSID_LEN + MAX_KEY_LEN + MAX_USER_LEN + MAX_ANON_USER_LEN]; +}_WlanConnectCmd_t; + +typedef union +{ + _WlanConnectCmd_t Cmd; + _BasicResponse_t Rsp; +}_SlWlanConnectMsg_u; + + +#if _SL_INCLUDE_FUNC(sl_WlanConnect) +_i16 sl_WlanConnect(_i8* pName, _i16 NameLen, _u8 *pMacAddr, SlSecParams_t* pSecParams , SlSecParamsExt_t* pSecExtParams) +{ + _SlWlanConnectMsg_u Msg; + _SlCmdCtrl_t CmdCtrl; + + // Clear the above structures + memset (&Msg, 0, sizeof(Msg)); + memset (&CmdCtrl, 0, sizeof(CmdCtrl)); + + CmdCtrl.TxDescLen = 0;/* init */ + CmdCtrl.RxDescLen = sizeof(_BasicResponse_t); + + /* verify SSID length */ + VERIFY_PROTOCOL(NameLen <= MAX_SSID_LEN); + /* update SSID length */ + Msg.Cmd.Args.Common.SsidLen = (_u8)NameLen; + + /* Profile with no security */ + /* Enterprise security profile */ + if (NULL != pSecExtParams) + { + /* Update command opcode */ + CmdCtrl.Opcode = SL_OPCODE_WLAN_WLANCONNECTEAPCOMMAND; + CmdCtrl.TxDescLen += sizeof(_WlanConnectEapCommand_t); + /* copy SSID */ + sl_Memcpy(EAP_SSID_STRING(&Msg), pName, NameLen); + CmdCtrl.TxDescLen += NameLen; + /* Copy password if supplied */ + if ((NULL != pSecParams) && (pSecParams->KeyLen > 0)) + { + /* update security type */ + Msg.Cmd.Args.Common.SecType = pSecParams->Type; + /* verify key length */ + if (pSecParams->KeyLen > MAX_KEY_LEN) + { + return SL_INVALPARAM; + } + /* update key length */ + Msg.Cmd.Args.Common.PasswordLen = pSecParams->KeyLen; + ARG_CHECK_PTR(pSecParams->Key); + /* copy key */ + sl_Memcpy(EAP_PASSWORD_STRING(&Msg), pSecParams->Key, pSecParams->KeyLen); + CmdCtrl.TxDescLen += pSecParams->KeyLen; + } + else + { + Msg.Cmd.Args.Common.PasswordLen = 0; + } + + ARG_CHECK_PTR(pSecExtParams); + /* Update Eap bitmask */ + Msg.Cmd.Args.EapBitmask = pSecExtParams->EapMethod; + /* Update Certificate file ID index - currently not supported */ + Msg.Cmd.Args.CertIndex = pSecExtParams->CertIndex; + /* verify user length */ + if (pSecExtParams->UserLen > MAX_USER_LEN) + { + return SL_INVALPARAM; + } + Msg.Cmd.Args.UserLen = pSecExtParams->UserLen; + /* copy user name (identity) */ + if(pSecExtParams->UserLen > 0) + { + sl_Memcpy(EAP_USER_STRING(&Msg), pSecExtParams->User, pSecExtParams->UserLen); + CmdCtrl.TxDescLen += pSecExtParams->UserLen; + } + /* verify Anonymous user length */ + if (pSecExtParams->AnonUserLen > MAX_ANON_USER_LEN) + { + return SL_INVALPARAM; + } + Msg.Cmd.Args.AnonUserLen = pSecExtParams->AnonUserLen; + /* copy Anonymous user */ + if(pSecExtParams->AnonUserLen > 0) + { + sl_Memcpy(EAP_ANON_USER_STRING(&Msg), pSecExtParams->AnonUser, pSecExtParams->AnonUserLen); + CmdCtrl.TxDescLen += pSecExtParams->AnonUserLen; + } + + } + + /* Regular or open security profile */ + else + { + /* Update command opcode */ + CmdCtrl.Opcode = SL_OPCODE_WLAN_WLANCONNECTCOMMAND; + CmdCtrl.TxDescLen += sizeof(_WlanConnectCommon_t); + /* copy SSID */ + sl_Memcpy(SSID_STRING(&Msg), pName, NameLen); + CmdCtrl.TxDescLen += NameLen; + /* Copy password if supplied */ + if( NULL != pSecParams ) + { + /* update security type */ + Msg.Cmd.Args.Common.SecType = pSecParams->Type; + /* verify key length is valid */ + if (pSecParams->KeyLen > MAX_KEY_LEN) + { + return SL_INVALPARAM; + } + /* update key length */ + Msg.Cmd.Args.Common.PasswordLen = pSecParams->KeyLen; + CmdCtrl.TxDescLen += pSecParams->KeyLen; + /* copy key (could be no key in case of WPS pin) */ + if( NULL != pSecParams->Key ) + { + sl_Memcpy(PASSWORD_STRING(&Msg), pSecParams->Key, pSecParams->KeyLen); + } + } + /* Profile with no security */ + else + { + Msg.Cmd.Args.Common.PasswordLen = 0; + Msg.Cmd.Args.Common.SecType = SL_SEC_TYPE_OPEN; + } + } + /* If BSSID is not null, copy to buffer, otherwise set to 0 */ + if(NULL != pMacAddr) + { + sl_Memcpy(Msg.Cmd.Args.Common.Bssid, pMacAddr, sizeof(Msg.Cmd.Args.Common.Bssid)); + } + else + { + sl_Memset(Msg.Cmd.Args.Common.Bssid, 0, sizeof(Msg.Cmd.Args.Common.Bssid)); + } + + + VERIFY_RET_OK ( _SlDrvCmdOp(&CmdCtrl, &Msg, NULL)); + + return (_i16)Msg.Rsp.status; +} +#endif + +/*******************************************************************************/ +/* sl_Disconnect */ +/* ******************************************************************************/ +#if _SL_INCLUDE_FUNC(sl_WlanDisconnect) +_i16 sl_WlanDisconnect(void) +{ + return _SlDrvBasicCmd(SL_OPCODE_WLAN_WLANDISCONNECTCOMMAND); +} +#endif + +/******************************************************************************/ +/* sl_PolicySet */ +/******************************************************************************/ +typedef union +{ + _WlanPoliciySetGet_t Cmd; + _BasicResponse_t Rsp; +}_SlPolicyMsg_u; + +const _SlCmdCtrl_t _SlPolicySetCmdCtrl = +{ + SL_OPCODE_WLAN_POLICYSETCOMMAND, + sizeof(_WlanPoliciySetGet_t), + sizeof(_BasicResponse_t) +}; + +#if _SL_INCLUDE_FUNC(sl_WlanPolicySet) +_i16 sl_WlanPolicySet(_u8 Type , const _u8 Policy, _u8 *pVal,_u8 ValLen) +{ + _SlPolicyMsg_u Msg; + _SlCmdExt_t CmdExt; + + CmdExt.TxPayloadLen = ValLen; + CmdExt.RxPayloadLen = 0; + CmdExt.pTxPayload = (_u8 *)pVal; + CmdExt.pRxPayload = NULL; + + + Msg.Cmd.PolicyType = Type; + Msg.Cmd.PolicyOption = Policy; + Msg.Cmd.PolicyOptionLen = ValLen; + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlPolicySetCmdCtrl, &Msg, &CmdExt)); + + return (_i16)Msg.Rsp.status; +} +#endif + + +/******************************************************************************/ +/* sl_PolicyGet */ +/******************************************************************************/ +typedef union +{ + _WlanPoliciySetGet_t Cmd; + _WlanPoliciySetGet_t Rsp; +}_SlPolicyGetMsg_u; + +const _SlCmdCtrl_t _SlPolicyGetCmdCtrl = +{ + SL_OPCODE_WLAN_POLICYGETCOMMAND, + sizeof(_WlanPoliciySetGet_t), + sizeof(_WlanPoliciySetGet_t) +}; + +#if _SL_INCLUDE_FUNC(sl_WlanPolicyGet) +_i16 sl_WlanPolicyGet(_u8 Type , _u8 Policy,_u8 *pVal,_u8 *pValLen) +{ + _SlPolicyGetMsg_u Msg; + _SlCmdExt_t CmdExt; + + if (*pValLen == 0) + { + return SL_EZEROLEN; + } + CmdExt.TxPayloadLen = 0; + CmdExt.RxPayloadLen = *pValLen; + CmdExt.pTxPayload = NULL; + CmdExt.pRxPayload = pVal; + CmdExt.ActualRxPayloadLen = 0; + + + Msg.Cmd.PolicyType = Type; + Msg.Cmd.PolicyOption = Policy; + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlPolicyGetCmdCtrl, &Msg, &CmdExt)); + + + if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen) + { + *pValLen = Msg.Rsp.PolicyOptionLen; + return SL_ESMALLBUF; + } + else + { + /* no pointer valus, fill the results into _i8 */ + *pValLen = (_u8)CmdExt.ActualRxPayloadLen; + if( 0 == CmdExt.ActualRxPayloadLen ) + { + *pValLen = 1; + pVal[0] = Msg.Rsp.PolicyOption; + } + } + return (_i16)SL_OS_RET_CODE_OK; +} +#endif + + +/*******************************************************************************/ +/* sl_ProfileAdd */ +/*******************************************************************************/ +typedef struct +{ + _WlanAddGetEapProfile_t Args; + _i8 Strings[MAX_SSID_LEN + MAX_KEY_LEN + MAX_USER_LEN + MAX_ANON_USER_LEN]; +}_SlProfileParams_t; + +typedef union +{ + _SlProfileParams_t Cmd; + _BasicResponse_t Rsp; +}_SlProfileAddMsg_u; + + + +#if _SL_INCLUDE_FUNC(sl_WlanProfileAdd) +_i16 sl_WlanProfileAdd(_i8* pName, _i16 NameLen, _u8 *pMacAddr, SlSecParams_t* pSecParams , SlSecParamsExt_t* pSecExtParams, _u32 Priority, _u32 Options) +{ + _SlProfileAddMsg_u Msg; + _SlCmdCtrl_t CmdCtrl = {0}; + CmdCtrl.TxDescLen = 0;/* init */ + CmdCtrl.RxDescLen = sizeof(_BasicResponse_t); + + /* update priority */ + Msg.Cmd.Args.Common.Priority = (_u8)Priority; + /* verify SSID length */ + VERIFY_PROTOCOL(NameLen <= MAX_SSID_LEN); + /* update SSID length */ + Msg.Cmd.Args.Common.SsidLen = (_u8)NameLen; + + + /* Enterprise security profile */ + if (NULL != pSecExtParams) + { + /* Update command opcode */ + CmdCtrl.Opcode = SL_OPCODE_WLAN_EAP_PROFILEADDCOMMAND; + CmdCtrl.TxDescLen += sizeof(_WlanAddGetEapProfile_t); + + /* copy SSID */ + sl_Memcpy(EAP_PROFILE_SSID_STRING(&Msg), pName, NameLen); + CmdCtrl.TxDescLen += NameLen; + + /* Copy password if supplied */ + if ((NULL != pSecParams) && (pSecParams->KeyLen > 0)) + { + /* update security type */ + Msg.Cmd.Args.Common.SecType = pSecParams->Type; + + if( SL_SEC_TYPE_WEP == Msg.Cmd.Args.Common.SecType ) + { + Msg.Cmd.Args.Common.WepKeyId = 0; + } + + /* verify key length */ + if (pSecParams->KeyLen > MAX_KEY_LEN) + { + return SL_INVALPARAM; + } + VERIFY_PROTOCOL(pSecParams->KeyLen <= MAX_KEY_LEN); + /* update key length */ + Msg.Cmd.Args.Common.PasswordLen = pSecParams->KeyLen; + CmdCtrl.TxDescLen += pSecParams->KeyLen; + ARG_CHECK_PTR(pSecParams->Key); + /* copy key */ + sl_Memcpy(EAP_PROFILE_PASSWORD_STRING(&Msg), pSecParams->Key, pSecParams->KeyLen); + } + else + { + Msg.Cmd.Args.Common.PasswordLen = 0; + } + + ARG_CHECK_PTR(pSecExtParams); + /* Update Eap bitmask */ + Msg.Cmd.Args.EapBitmask = pSecExtParams->EapMethod; + /* Update Certificate file ID index - currently not supported */ + Msg.Cmd.Args.CertIndex = pSecExtParams->CertIndex; + /* verify user length */ + if (pSecExtParams->UserLen > MAX_USER_LEN) + { + return SL_INVALPARAM; + } + Msg.Cmd.Args.UserLen = pSecExtParams->UserLen; + /* copy user name (identity) */ + if(pSecExtParams->UserLen > 0) + { + sl_Memcpy(EAP_PROFILE_USER_STRING(&Msg), pSecExtParams->User, pSecExtParams->UserLen); + CmdCtrl.TxDescLen += pSecExtParams->UserLen; + } + + /* verify Anonymous user length (for tunneled) */ + if (pSecExtParams->AnonUserLen > MAX_ANON_USER_LEN) + { + return SL_INVALPARAM; + } + Msg.Cmd.Args.AnonUserLen = pSecExtParams->AnonUserLen; + + /* copy Anonymous user */ + if(pSecExtParams->AnonUserLen > 0) + { + sl_Memcpy(EAP_PROFILE_ANON_USER_STRING(&Msg), pSecExtParams->AnonUser, pSecExtParams->AnonUserLen); + CmdCtrl.TxDescLen += pSecExtParams->AnonUserLen; + } + + } + /* Regular or open security profile */ + else + { + /* Update command opcode */ + CmdCtrl.Opcode = SL_OPCODE_WLAN_PROFILEADDCOMMAND; + /* update commnad length */ + CmdCtrl.TxDescLen += sizeof(_WlanAddGetProfile_t); + + if (NULL != pName) + { + /* copy SSID */ + sl_Memcpy(PROFILE_SSID_STRING(&Msg), pName, NameLen); + CmdCtrl.TxDescLen += NameLen; + } + + /* Copy password if supplied */ + if( NULL != pSecParams ) + { + /* update security type */ + Msg.Cmd.Args.Common.SecType = pSecParams->Type; + + if( SL_SEC_TYPE_WEP == Msg.Cmd.Args.Common.SecType ) + { + Msg.Cmd.Args.Common.WepKeyId = 0; + } + + /* verify key length */ + if (pSecParams->KeyLen > MAX_KEY_LEN) + { + return SL_INVALPARAM; + } + /* update key length */ + Msg.Cmd.Args.Common.PasswordLen = pSecParams->KeyLen; + CmdCtrl.TxDescLen += pSecParams->KeyLen; + /* copy key (could be no key in case of WPS pin) */ + if( NULL != pSecParams->Key ) + { + sl_Memcpy(PROFILE_PASSWORD_STRING(&Msg), pSecParams->Key, pSecParams->KeyLen); + } + } + else + { + Msg.Cmd.Args.Common.SecType = SL_SEC_TYPE_OPEN; + Msg.Cmd.Args.Common.PasswordLen = 0; + } + + } + + + /* If BSSID is not null, copy to buffer, otherwise set to 0 */ + if(NULL != pMacAddr) + { + sl_Memcpy(Msg.Cmd.Args.Common.Bssid, pMacAddr, sizeof(Msg.Cmd.Args.Common.Bssid)); + } + else + { + sl_Memset(Msg.Cmd.Args.Common.Bssid, 0, sizeof(Msg.Cmd.Args.Common.Bssid)); + } + + VERIFY_RET_OK(_SlDrvCmdOp(&CmdCtrl, &Msg, NULL)); + + return (_i16)Msg.Rsp.status; +} +#endif +/*******************************************************************************/ +/* sl_ProfileGet */ +/*******************************************************************************/ +typedef union +{ + _WlanProfileDelGetCommand_t Cmd; + _SlProfileParams_t Rsp; +}_SlProfileGetMsg_u; + +const _SlCmdCtrl_t _SlProfileGetCmdCtrl = +{ + SL_OPCODE_WLAN_PROFILEGETCOMMAND, + sizeof(_WlanProfileDelGetCommand_t), + sizeof(_SlProfileParams_t) +}; + +#if _SL_INCLUDE_FUNC(sl_WlanProfileGet) +_i16 sl_WlanProfileGet(_i16 Index,_i8* pName, _i16 *pNameLen, _u8 *pMacAddr, SlSecParams_t* pSecParams, SlGetSecParamsExt_t* pEntParams, _u32 *pPriority) +{ + _SlProfileGetMsg_u Msg; + Msg.Cmd.index = (_u8)Index; + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlProfileGetCmdCtrl, &Msg, NULL)); + + pSecParams->Type = Msg.Rsp.Args.Common.SecType; + /* since password is not transferred in getprofile, password length should always be zero */ + pSecParams->KeyLen = Msg.Rsp.Args.Common.PasswordLen; + if (NULL != pEntParams) + { + pEntParams->UserLen = Msg.Rsp.Args.UserLen; + /* copy user name */ + if (pEntParams->UserLen > 0) + { + sl_Memcpy(pEntParams->User, EAP_PROFILE_USER_STRING(&Msg), pEntParams->UserLen); + } + pEntParams->AnonUserLen = Msg.Rsp.Args.AnonUserLen; + /* copy anonymous user name */ + if (pEntParams->AnonUserLen > 0) + { + sl_Memcpy(pEntParams->AnonUser, EAP_PROFILE_ANON_USER_STRING(&Msg), pEntParams->AnonUserLen); + } + } + + *pNameLen = Msg.Rsp.Args.Common.SsidLen; + *pPriority = Msg.Rsp.Args.Common.Priority; + + if (NULL != Msg.Rsp.Args.Common.Bssid) + { + sl_Memcpy(pMacAddr, Msg.Rsp.Args.Common.Bssid, sizeof(Msg.Rsp.Args.Common.Bssid)); + } + + sl_Memcpy(pName, EAP_PROFILE_SSID_STRING(&Msg), *pNameLen); + + return (_i16)Msg.Rsp.Args.Common.SecType; + +} +#endif +/*******************************************************************************/ +/* sl_ProfileDel */ +/*******************************************************************************/ +typedef union +{ + _WlanProfileDelGetCommand_t Cmd; + _BasicResponse_t Rsp; +}_SlProfileDelMsg_u; + +const _SlCmdCtrl_t _SlProfileDelCmdCtrl = +{ + SL_OPCODE_WLAN_PROFILEDELCOMMAND, + sizeof(_WlanProfileDelGetCommand_t), + sizeof(_BasicResponse_t) +}; + +#if _SL_INCLUDE_FUNC(sl_WlanProfileDel) +_i16 sl_WlanProfileDel(_i16 Index) +{ + _SlProfileDelMsg_u Msg; + + Msg.Cmd.index = (_u8)Index; + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlProfileDelCmdCtrl, &Msg, NULL)); + + return (_i16)Msg.Rsp.status; +} +#endif + + +/******************************************************************************/ +/* sl_WlanGetNetworkList */ +/******************************************************************************/ +typedef union +{ + _WlanGetNetworkListCommand_t Cmd; + _WlanGetNetworkListResponse_t Rsp; +}_SlWlanGetNetworkListMsg_u; + +const _SlCmdCtrl_t _SlWlanGetNetworkListCtrl = +{ + SL_OPCODE_WLAN_SCANRESULTSGETCOMMAND, + sizeof(_WlanGetNetworkListCommand_t), + sizeof(_WlanGetNetworkListResponse_t) +}; + + +#if _SL_INCLUDE_FUNC(sl_WlanGetNetworkList) +_i16 sl_WlanGetNetworkList(_u8 Index, _u8 Count, Sl_WlanNetworkEntry_t *pEntries) +{ + _i16 retVal = 0; + _SlWlanGetNetworkListMsg_u Msg; + _SlCmdExt_t CmdExt; + + if (Count == 0) + { + return SL_EZEROLEN; + } + CmdExt.TxPayloadLen = 0; + CmdExt.RxPayloadLen = sizeof(Sl_WlanNetworkEntry_t)*(Count); + CmdExt.pTxPayload = NULL; + CmdExt.pRxPayload = (_u8 *)pEntries; + + Msg.Cmd.index = Index; + Msg.Cmd.count = Count; + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlWlanGetNetworkListCtrl, &Msg, &CmdExt)); + retVal = Msg.Rsp.status; + + return (_i16)retVal; +} +#endif + + + + + +/******************************************************************************/ +/* RX filters message command response structures */ +/******************************************************************************/ + +/* Set command */ +typedef union +{ + _WlanRxFilterAddCommand_t Cmd; + _WlanRxFilterAddCommandReponse_t Rsp; +}_SlrxFilterAddMsg_u; + +const _SlCmdCtrl_t _SlRxFilterAddtCmdCtrl = +{ + SL_OPCODE_WLAN_WLANRXFILTERADDCOMMAND, + sizeof(_WlanRxFilterAddCommand_t), + sizeof(_WlanRxFilterAddCommandReponse_t) +}; + + +/* Set command */ +typedef union _SlRxFilterSetMsg_u +{ + _WlanRxFilterSetCommand_t Cmd; + _WlanRxFilterSetCommandReponse_t Rsp; +}_SlRxFilterSetMsg_u; + + +const _SlCmdCtrl_t _SlRxFilterSetCmdCtrl = +{ + SL_OPCODE_WLAN_WLANRXFILTERSETCOMMAND, + sizeof(_WlanRxFilterSetCommand_t), + sizeof(_WlanRxFilterSetCommandReponse_t) +}; + +/* Get command */ +typedef union _SlRxFilterGetMsg_u +{ + _WlanRxFilterGetCommand_t Cmd; + _WlanRxFilterGetCommandReponse_t Rsp; +}_SlRxFilterGetMsg_u; + + +const _SlCmdCtrl_t _SlRxFilterGetCmdCtrl = +{ + SL_OPCODE_WLAN_WLANRXFILTERGETCOMMAND, + sizeof(_WlanRxFilterGetCommand_t), + sizeof(_WlanRxFilterGetCommandReponse_t) +}; + + +/*******************************************************************************/ +/* RX filters */ +/*******************************************************************************/ + +#if _SL_INCLUDE_FUNC(sl_WlanRxFilterAdd) +SlrxFilterID_t sl_WlanRxFilterAdd( SlrxFilterRuleType_t RuleType, + SlrxFilterFlags_t FilterFlags, + const SlrxFilterRule_t* const Rule, + const SlrxFilterTrigger_t* const Trigger, + const SlrxFilterAction_t* const Action, + SlrxFilterID_t* pFilterId) +{ + + + _SlrxFilterAddMsg_u Msg; + Msg.Cmd.RuleType = RuleType; + /* filterId is zero */ + Msg.Cmd.FilterId = 0; + Msg.Cmd.FilterFlags = FilterFlags; + sl_Memcpy( &(Msg.Cmd.Rule), Rule, sizeof(SlrxFilterRule_t) ); + sl_Memcpy( &(Msg.Cmd.Trigger), Trigger, sizeof(SlrxFilterTrigger_t) ); + sl_Memcpy( &(Msg.Cmd.Action), Action, sizeof(SlrxFilterAction_t) ); + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlRxFilterAddtCmdCtrl, &Msg, NULL) ); + *pFilterId = Msg.Rsp.FilterId; + return (_i16)Msg.Rsp.Status; + +} +#endif + + + +/*******************************************************************************/ +/* RX filters */ +/*******************************************************************************/ +#if _SL_INCLUDE_FUNC(sl_WlanRxFilterSet) +_i16 sl_WlanRxFilterSet(const SLrxFilterOperation_t RxFilterOperation, + const _u8* const pInputBuffer, + _u16 InputbufferLength) +{ + _SlRxFilterSetMsg_u Msg; + _SlCmdExt_t CmdExt; + + CmdExt.TxPayloadLen = InputbufferLength; + CmdExt.pTxPayload = (_u8 *)pInputBuffer; + CmdExt.RxPayloadLen = 0; + CmdExt.pRxPayload = (_u8 *)NULL; + + Msg.Cmd.RxFilterOperation = RxFilterOperation; + Msg.Cmd.InputBufferLength = InputbufferLength; + + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlRxFilterSetCmdCtrl, &Msg, &CmdExt) ); + + + return (_i16)Msg.Rsp.Status; +} +#endif + +/******************************************************************************/ +/* RX filters */ +/******************************************************************************/ +#if _SL_INCLUDE_FUNC(sl_WlanRxFilterGet) +_i16 sl_WlanRxFilterGet(const SLrxFilterOperation_t RxFilterOperation, + _u8* pOutputBuffer, + _u16 OutputbufferLength) +{ + _SlRxFilterGetMsg_u Msg; + _SlCmdExt_t CmdExt; + + if (OutputbufferLength == 0) + { + return SL_EZEROLEN; + } + CmdExt.TxPayloadLen = 0; + CmdExt.pTxPayload = NULL; + CmdExt.RxPayloadLen = OutputbufferLength; + CmdExt.pRxPayload = (_u8 *)pOutputBuffer; + CmdExt.ActualRxPayloadLen = 0; + + Msg.Cmd.RxFilterOperation = RxFilterOperation; + Msg.Cmd.OutputBufferLength = OutputbufferLength; + + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlRxFilterGetCmdCtrl, &Msg, &CmdExt) ); + + if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen) + { + return SL_ESMALLBUF; + } + + return (_i16)Msg.Rsp.Status; +} +#endif + +/*******************************************************************************/ +/* sl_WlanRxStatStart */ +/*******************************************************************************/ +#if _SL_INCLUDE_FUNC(sl_WlanRxStatStart) +_i16 sl_WlanRxStatStart(void) +{ + return _SlDrvBasicCmd(SL_OPCODE_WLAN_STARTRXSTATCOMMAND); +} +#endif + +#if _SL_INCLUDE_FUNC(sl_WlanRxStatStop) +_i16 sl_WlanRxStatStop(void) +{ + return _SlDrvBasicCmd(SL_OPCODE_WLAN_STOPRXSTATCOMMAND); +} +#endif + +#if _SL_INCLUDE_FUNC(sl_WlanRxStatGet) +_i16 sl_WlanRxStatGet(SlGetRxStatResponse_t *pRxStat,_u32 Flags) +{ + _SlCmdCtrl_t CmdCtrl = {SL_OPCODE_WLAN_GETRXSTATCOMMAND, 0, sizeof(SlGetRxStatResponse_t)}; + sl_Memset(pRxStat,0,sizeof(SlGetRxStatResponse_t)); + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&CmdCtrl, pRxStat, NULL)); + + return 0; +} +#endif + + + +/******************************************************************************/ +/* sl_WlanSmartConfigStop */ +/******************************************************************************/ +#if _SL_INCLUDE_FUNC(sl_WlanSmartConfigStop) +_i16 sl_WlanSmartConfigStop(void) +{ + return _SlDrvBasicCmd(SL_OPCODE_WLAN_SMART_CONFIG_STOP_COMMAND); +} +#endif + + +/******************************************************************************/ +/* sl_WlanSmartConfigStart */ +/******************************************************************************/ + + +typedef struct +{ + _WlanSmartConfigStartCommand_t Args; + _i8 Strings[3 * MAX_SMART_CONFIG_KEY]; /* public key + groupId1 key + groupId2 key */ +}_SlSmartConfigStart_t; + +typedef union +{ + _SlSmartConfigStart_t Cmd; + _BasicResponse_t Rsp; +}_SlSmartConfigStartMsg_u; + +const _SlCmdCtrl_t _SlSmartConfigStartCmdCtrl = +{ + SL_OPCODE_WLAN_SMART_CONFIG_START_COMMAND, + sizeof(_SlSmartConfigStart_t), + sizeof(_BasicResponse_t) +}; + +#if _SL_INCLUDE_FUNC(sl_WlanSmartConfigStart) +_i16 sl_WlanSmartConfigStart( const _u32 groupIdBitmask, + const _u8 cipher, + const _u8 publicKeyLen, + const _u8 group1KeyLen, + const _u8 group2KeyLen, + const _u8* pPublicKey, + const _u8* pGroup1Key, + const _u8* pGroup2Key) +{ + _SlSmartConfigStartMsg_u Msg; + + Msg.Cmd.Args.groupIdBitmask = (_u8)groupIdBitmask; + Msg.Cmd.Args.cipher = (_u8)cipher; + Msg.Cmd.Args.publicKeyLen = (_u8)publicKeyLen; + Msg.Cmd.Args.group1KeyLen = (_u8)group1KeyLen; + Msg.Cmd.Args.group2KeyLen = (_u8)group2KeyLen; + + /* copy keys (if exist) after command (one after another) */ + sl_Memcpy(SMART_CONFIG_START_PUBLIC_KEY_STRING(&Msg), pPublicKey, publicKeyLen); + sl_Memcpy(SMART_CONFIG_START_GROUP1_KEY_STRING(&Msg), pGroup1Key, group1KeyLen); + sl_Memcpy(SMART_CONFIG_START_GROUP2_KEY_STRING(&Msg), pGroup2Key, group2KeyLen); + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlSmartConfigStartCmdCtrl , &Msg, NULL)); + + return (_i16)Msg.Rsp.status; + + +} +#endif + + +/*******************************************************************************/ +/* sl_WlanSetMode */ +/*******************************************************************************/ +typedef union +{ + _WlanSetMode_t Cmd; + _BasicResponse_t Rsp; +}_SlwlanSetModeMsg_u; + +const _SlCmdCtrl_t _SlWlanSetModeCmdCtrl = +{ + SL_OPCODE_WLAN_SET_MODE, + sizeof(_WlanSetMode_t), + sizeof(_BasicResponse_t) +}; + +/* possible values are: +WLAN_SET_STA_MODE = 1 +WLAN_SET_AP_MODE = 2 +WLAN_SET_P2P_MODE = 3 */ + +#if _SL_INCLUDE_FUNC(sl_WlanSetMode) +_i16 sl_WlanSetMode(const _u8 mode) +{ + _SlwlanSetModeMsg_u Msg; + + Msg.Cmd.mode = mode; + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlWlanSetModeCmdCtrl , &Msg, NULL)); + + return (_i16)Msg.Rsp.status; + +} +#endif + + + + +/*******************************************************************************/ +/* sl_WlanSet */ +/* ******************************************************************************/ +typedef union +{ + _WlanCfgSetGet_t Cmd; + _BasicResponse_t Rsp; +}_SlWlanCfgSetMsg_u; + +const _SlCmdCtrl_t _SlWlanCfgSetCmdCtrl = +{ + SL_OPCODE_WLAN_CFG_SET, + sizeof(_WlanCfgSetGet_t), + sizeof(_BasicResponse_t) +}; + + +#if _SL_INCLUDE_FUNC(sl_WlanSet) +_i16 sl_WlanSet(_u16 ConfigId ,_u16 ConfigOpt,_u16 ConfigLen, _u8 *pValues) +{ + _SlWlanCfgSetMsg_u Msg; + _SlCmdExt_t CmdExt; + + CmdExt.TxPayloadLen = (ConfigLen+3) & (~3); + CmdExt.RxPayloadLen = 0; + CmdExt.pTxPayload = (_u8 *)pValues; + CmdExt.pRxPayload = NULL; + + + Msg.Cmd.ConfigId = ConfigId; + Msg.Cmd.ConfigLen = ConfigLen; + Msg.Cmd.ConfigOpt = ConfigOpt; + + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlWlanCfgSetCmdCtrl, &Msg, &CmdExt)); + + return (_i16)Msg.Rsp.status; +} +#endif + + +/******************************************************************************/ +/* sl_WlanGet */ +/******************************************************************************/ +typedef union +{ + _WlanCfgSetGet_t Cmd; + _WlanCfgSetGet_t Rsp; +}_SlWlanCfgMsgGet_u; + +const _SlCmdCtrl_t _SlWlanCfgGetCmdCtrl = +{ + SL_OPCODE_WLAN_CFG_GET, + sizeof(_WlanCfgSetGet_t), + sizeof(_WlanCfgSetGet_t) +}; + +#if _SL_INCLUDE_FUNC(sl_WlanGet) +_i16 sl_WlanGet(_u16 ConfigId, _u16 *pConfigOpt,_u16 *pConfigLen, _u8 *pValues) +{ + _SlWlanCfgMsgGet_u Msg; + _SlCmdExt_t CmdExt; + + if (*pConfigLen == 0) + { + return SL_EZEROLEN; + } + CmdExt.TxPayloadLen = 0; + CmdExt.RxPayloadLen = *pConfigLen; + CmdExt.pTxPayload = NULL; + CmdExt.pRxPayload = (_u8 *)pValues; + CmdExt.ActualRxPayloadLen = 0; + + Msg.Cmd.ConfigId = ConfigId; + if( pConfigOpt ) + { + Msg.Cmd.ConfigOpt = (_u16)*pConfigOpt; + } + VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlWlanCfgGetCmdCtrl, &Msg, &CmdExt)); + + if( pConfigOpt ) + { + *pConfigOpt = (_u8)Msg.Rsp.ConfigOpt; + } + if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen) + { + *pConfigLen = (_u8)CmdExt.RxPayloadLen; + return SL_ESMALLBUF; + } + else + { + *pConfigLen = (_u8)CmdExt.ActualRxPayloadLen; + } + + + return (_i16)Msg.Rsp.Status; +} +#endif |