From dae73f62500891c64192f4355823ffb868a4d55f Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Tue, 5 Apr 2016 22:30:00 +0200 Subject: [PATCH] Update WINC1500 driver to 19.4.4 --- .../include/common/include/nm_common.h | 12 +- .../include/common/include/nm_debug.h | 48 +- .../include/driver/include/m2m_ate_mode.h | 34 +- .../include/driver/include/m2m_crypto.h | 245 ++++ src/winc1500/include/driver/include/m2m_ota.h | 18 +- .../include/driver/include/m2m_periph.h | 64 +- .../include/driver/include/m2m_types.h | 326 ++++-- .../include/driver/include/m2m_wifi.h | 663 +++++------ src/winc1500/include/driver/include/nmasic.h | 7 + src/winc1500/include/driver/include/nmdrv.h | 25 +- .../socket/include/m2m_socket_host_if.h | 39 +- src/winc1500/include/socket/include/socket.h | 731 +++++++----- src/winc1500/src/m2m_ate_mode.c | 23 +- src/winc1500/src/m2m_crypto.c | 1010 +++++++++++++++++ src/winc1500/src/m2m_hif.c | 76 +- src/winc1500/src/m2m_ota.c | 38 +- src/winc1500/src/m2m_periph.c | 4 + src/winc1500/src/m2m_wifi.c | 303 +++-- src/winc1500/src/nmasic.c | 136 ++- src/winc1500/src/nmdrv.c | 175 ++- src/winc1500/src/nmspi.c | 24 - src/winc1500/src/socket.c | 105 +- 22 files changed, 3044 insertions(+), 1062 deletions(-) create mode 100644 src/winc1500/include/driver/include/m2m_crypto.h create mode 100644 src/winc1500/src/m2m_crypto.c diff --git a/src/winc1500/include/common/include/nm_common.h b/src/winc1500/include/common/include/nm_common.h index 1a30d363f..a3724aa65 100644 --- a/src/winc1500/include/common/include/nm_common.h +++ b/src/winc1500/include/common/include/nm_common.h @@ -2,7 +2,7 @@ * * \file * - * \brief This module contains common APIs declarations. + * \brief WINC Driver Common API Declarations. * * Copyright (c) 2015 Atmel Corporation. All rights reserved. * @@ -139,16 +139,6 @@ Invalid argument #define BYTE_3(word) ((uint8)(((word) >> 0 ) & 0x000000FFUL)) #endif - -typedef enum{ - M2M_REQ_GRP_MAIN = 0, M2M_REQ_GRP_WIFI, M2M_REQ_GRP_IP, M2M_REQ_GRP_HIF, M2M_REQ_GRP_OTA -}tenuM2mReqGrp; - - -typedef enum{ - M2M_REQ_CONFIG_PKT, - M2M_REQ_DATA_PKT = NBIT7 -}tenuM2mReqPkt; /**@}*/ #ifdef __cplusplus extern "C" { diff --git a/src/winc1500/include/common/include/nm_debug.h b/src/winc1500/include/common/include/nm_debug.h index 0a1138d90..bf5e0ce8d 100644 --- a/src/winc1500/include/common/include/nm_debug.h +++ b/src/winc1500/include/common/include/nm_debug.h @@ -57,21 +57,21 @@ #define M2M_LOG_REQ 3 #define M2M_LOG_DBG 4 -#if (defined __APP_APS3_CORTUS__) +#if (defined __APS3_CORTUS__) #define M2M_LOG_LEVEL M2M_LOG_ERROR #else #define M2M_LOG_LEVEL M2M_LOG_REQ #endif -/**/ -#if !((defined __MSP430FR5739)||(defined __MCF964548__)) #define M2M_ERR(...) #define M2M_INFO(...) #define M2M_REQ(...) #define M2M_DBG(...) +#define M2M_PRINT(...) #if (CONF_WINC_DEBUG == 1) +#undef M2M_PRINT #define M2M_PRINT(...) do{CONF_WINC_PRINTF(__VA_ARGS__);CONF_WINC_PRINTF("\r");}while(0) #if (M2M_LOG_LEVEL >= M2M_LOG_ERROR) #undef M2M_ERR @@ -85,41 +85,11 @@ #if (M2M_LOG_LEVEL >= M2M_LOG_DBG) #undef M2M_DBG #define M2M_DBG(...) do{CONF_WINC_PRINTF("(APP)(DBG)[%s][%d]",__FUNCTION__,__LINE__); CONF_WINC_PRINTF(__VA_ARGS__);CONF_WINC_PRINTF("\r");}while(0) -#endif -#endif -#endif -#endif -#else -#define M2M_ERR(...) -#define M2M_DBG(...) -#define M2M_REQ(...) -#define M2M_INFO(...) -#define M2M_PRINT(...) -#endif -#else -#if (!defined __MCF964548__)||(!defined __SAMD21J18A__) -static void M2M_ERR(const char *_format, ...) //__attribute__ ((__format__ (M2M_ERR, 1, 2))) -{ -} -static void M2M_DBG(const char *_format, ...) //__attribute__ ((__format__ (M2M_DBG, 1, 2))) -{ -} -static void M2M_REQ(const char *_format, ...) //__attribute__ ((__format__ (M2M_DBG, 1, 2))) -{ -} -static void M2M_INFO(const char *_format, ...) // __attribute__ ((__format__ (M2M_INFO, 1, 2))) -{ - -} -static void M2M_PRINT(const char *_format, ...) // __attribute__ ((__format__ (M2M_INFO, 1, 2))) -{ - -} -static void CONF_WINC_PRINTF(const char *_format, ...) -{ -} -#endif -#endif +#endif /*M2M_LOG_DBG*/ +#endif /*M2M_LOG_REQ*/ +#endif /*M2M_LOG_INFO*/ +#endif /*M2M_LOG_ERROR*/ +#endif /*CONF_WINC_DEBUG */ /**@}*/ -#endif /* _NM_DEBUG_H_ */ \ No newline at end of file +#endif /* _NM_DEBUG_H_ */ diff --git a/src/winc1500/include/driver/include/m2m_ate_mode.h b/src/winc1500/include/driver/include/m2m_ate_mode.h index f7b44fa69..855127b13 100644 --- a/src/winc1500/include/driver/include/m2m_ate_mode.h +++ b/src/winc1500/include/driver/include/m2m_ate_mode.h @@ -2,7 +2,7 @@ * * \file * - * \brief NMC1500 Peripherals Application Interface. + * \brief WINC ATE Test Driver Interface. * * Copyright (c) 2015 Atmel Corporation. All rights reserved. * @@ -209,6 +209,15 @@ typedef enum { M2M_ATE_TX_MODE_CW = 0x01, }tenuM2mAteTxMode; +/*! + *@enum tenuM2mAteRxPwrMode + *@brief Used to define type of RX mode either high power or low power + */ +typedef enum { + M2M_ATE_RX_PWR_HIGH = 0x00, + M2M_ATE_RX_PWR_LOW = 0x01, +}tenuM2mAteRxPwrMode; + /*! *@enum tenuM2mAteChannels *@brief Available channels for TX and RX @@ -246,6 +255,16 @@ typedef struct { */ } tstrM2mAteRxStatus; +/*! + *@struct tstrM2mAteRxStatus + *@brief Used to save statistics of RX case + */ +typedef struct { + uint8 u8RxPwrMode; + /*!< RX power mode review tenuM2mAteRxPwrMode + */ +} tstrM2mAteInit; + /*! *@struct tstrM2mAteTx *@brief Used as data source in case of enabling TX test case @@ -345,6 +364,19 @@ FUNCTION PROTOTYPES */ sint8 m2m_ate_init(void); + +/*! +@fn \ + sint8 m2m_ate_init(tstrM2mAteInit *pstrInit); + +@brief + This function used to download ATE firmware from flash and start it + +@return + The function SHALL return 0 for success and a negative value otherwise. +*/ +sint8 m2m_ate_init_param(tstrM2mAteInit *pstrInit); + /*! @fn \ sint8 m2m_ate_deinit(void); diff --git a/src/winc1500/include/driver/include/m2m_crypto.h b/src/winc1500/include/driver/include/m2m_crypto.h new file mode 100644 index 000000000..5e7da0e0e --- /dev/null +++ b/src/winc1500/include/driver/include/m2m_crypto.h @@ -0,0 +1,245 @@ +/** + * + * \file + * + * \brief WINC Crypto Application Interface. + * + * Copyright (c) 2015 Atmel Corporation. All rights reserved. + * + * \asf_license_start + * + * \page License + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. 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. + * + * 3. The name of Atmel may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * + * \asf_license_stop + * + */ + +#ifndef __M2M_CRYPTO_H__ +#define __M2M_CRYPTO_H__ + + +/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* +INCLUDES +*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ + + +#include "common/include/nm_common.h" +#include "driver/include/m2m_types.h" +#include "driver/include/m2m_hif.h" + +/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* +MACROS +*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ +#define M2M_MAX_RSA_LEN (256) +#define M2M_SHA256_DIGEST_LEN 32 +#define M2M_SHA256_MAX_DATA (M2M_BUFFER_MAX_SIZE - M2M_SHA256_CONTEXT_BUFF_LEN - M2M_HIF_HDR_OFFSET) +/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* +DATA TYPES +*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ + +/*! +@struct \ + tstrM2mSha256Ctxt + +@brief + SHA256 context data +*/ +typedef struct sha256ctxt{ + uint32 au32Sha256CtxtBuff[M2M_SHA256_CONTEXT_BUFF_LEN/sizeof(uint32)]; +} tstrM2mSha256Ctxt; + + + +/*! +@enum \ + tenuRsaSignStatus + +@brief + RSA Signature status: pass or fail. +*/ +typedef enum{ + M2M_RSA_SIGN_OK, + M2M_RSA_SIGN_FAIL +} tenuRsaSignStatus; + +/*! +@typedef \ + tpfAppCryproCb + +@brief +@param [in] u8MsgType + +@param [in] pvMsg + A pointer to a buffer containing the notification parameters (if any). It should be + Casted to the correct data type corresponding to the notification type. + + +*/ +typedef void (*tpfAppCryproCb) (uint8 u8MsgType,void * pvResp, void * pvMsg); + +/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* +FUNCTION PROTOTYPES +*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ + + +#ifdef __cplusplus + extern "C" { +#endif +/*! +@fn \ + sint8 m2m_crypto_init(); + +@brief crypto initialization + +@param[in] pfAppCryproCb + +*/ +sint8 m2m_crypto_init(tpfAppCryproCb pfAppCryproCb); +/*! +@fn \ + sint8 m2m_sha256_hash_init(tstrM2mSha256Ctxt *psha256Ctxt); + +@brief SHA256 hash initialization + +@param[in] psha256Ctxt + Pointer to a sha256 context allocated by the caller. +*/ +sint8 m2m_crypto_sha256_hash_init(tstrM2mSha256Ctxt *psha256Ctxt); + + +/*! +@fn \ + sint8 m2m_sha256_hash_update(tstrM2mSha256Ctxt *psha256Ctxt, uint8 *pu8Data, uint16 u16DataLength); + +@brief SHA256 hash update + +@param [in] psha256Ctxt + Pointer to the sha256 context. + +@param [in] pu8Data + Buffer holding the data submitted to the hash. + +@param [in] u16DataLength + Size of the data bufefr in bytes. +*/ +sint8 m2m_crypto_sha256_hash_update(tstrM2mSha256Ctxt *psha256Ctxt, uint8 *pu8Data, uint16 u16DataLength); + + +/*! +@fn \ + sint8 m2m_sha256_hash_finish(tstrM2mSha256Ctxt *psha256Ctxt, uint8 *pu8Sha256Digest); + +@brief SHA256 hash finalization + +@param[in] psha256Ctxt + Pointer to a sha256 context allocated by the caller. + +@param [in] pu8Sha256Digest + Buffer allocated by the caller which will hold the resultant SHA256 Digest. It must be allocated no less than M2M_SHA256_DIGEST_LEN. +*/ +sint8 m2m_crypto_sha256_hash_finish(tstrM2mSha256Ctxt *psha256Ctxt, uint8 *pu8Sha256Digest); + + + + +/*! +@fn \ + sint8 m2m_rsa_sign_verify(uint8 *pu8N, uint16 u16NSize, uint8 *pu8E, uint16 u16ESize, uint8 *pu8SignedMsgHash, \ + uint16 u16HashLength, uint8 *pu8RsaSignature); + +@brief RSA Signature Verification + + The function shall request the RSA Signature verification from the WINC Firmware for the given message. The signed message shall be + compressed to the corresponding hash algorithm before calling this function. + The hash type is identified by the given hash length. For example, if the hash length is 32 bytes, then it is SHA256. + +@param[in] pu8N + RSA Key modulus n. + +@param[in] u16NSize + Size of the RSA modulus n in bytes. + +@param[in] pu8E + RSA public exponent. + +@param[in] u16ESize + Size of the RSA public exponent in bytes. + +@param[in] pu8SignedMsgHash + The hash digest of the signed message. + +@param[in] u16HashLength + The length of the hash digest. + +@param[out] pu8RsaSignature + Signature value to be verified. +*/ +sint8 m2m_crypto_rsa_sign_verify(uint8 *pu8N, uint16 u16NSize, uint8 *pu8E, uint16 u16ESize, uint8 *pu8SignedMsgHash, + uint16 u16HashLength, uint8 *pu8RsaSignature); + + +/*! +@fn \ + sint8 m2m_rsa_sign_gen(uint8 *pu8N, uint16 u16NSize, uint8 *pu8d, uint16 u16dSize, uint8 *pu8SignedMsgHash, \ + uint16 u16HashLength, uint8 *pu8RsaSignature); + +@brief RSA Signature Generation + + The function shall request the RSA Signature generation from the WINC Firmware for the given message. The signed message shall be + compressed to the corresponding hash algorithm before calling this function. + The hash type is identified by the given hash length. For example, if the hash length is 32 bytes, then it is SHA256. + +@param[in] pu8N + RSA Key modulus n. + +@param[in] u16NSize + Size of the RSA modulus n in bytes. + +@param[in] pu8d + RSA private exponent. + +@param[in] u16dSize + Size of the RSA private exponent in bytes. + +@param[in] pu8SignedMsgHash + The hash digest of the signed message. + +@param[in] u16HashLength + The length of the hash digest. + +@param[out] pu8RsaSignature + Pointer to a user buffer allocated by teh caller shall hold the generated signature. +*/ +sint8 m2m_crypto_rsa_sign_gen(uint8 *pu8N, uint16 u16NSize, uint8 *pu8d, uint16 u16dSize, uint8 *pu8SignedMsgHash, + uint16 u16HashLength, uint8 *pu8RsaSignature); +#ifdef __cplusplus +} +#endif + + +#endif /* __M2M_CRYPTO_H__ */ diff --git a/src/winc1500/include/driver/include/m2m_ota.h b/src/winc1500/include/driver/include/m2m_ota.h index ba6e1a43f..c450fd6d8 100644 --- a/src/winc1500/include/driver/include/m2m_ota.h +++ b/src/winc1500/include/driver/include/m2m_ota.h @@ -2,7 +2,7 @@ * * \file * - * \brief NMC1500 IoT OTA Interface. + * \brief WINC OTA Upgrade API Interface. * * Copyright (c) 2015 Atmel Corporation. All rights reserved. * @@ -48,8 +48,9 @@ INCLUDES #include "common/include/nm_common.h" #include "driver/include/m2m_types.h" -/**@defgroup OTATYPEDEF WLANTypedef - * @ingroup WlanEnums +#include "driver/include/nmdrv.h" +/**@addtogroup WlanEnums Enumerations and Typedefs + * @ingroup m2m_wifi */ /* @{ */ @@ -321,6 +322,17 @@ NMI_API sint8 m2m_ota_rollback(void); The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise. */ NMI_API sint8 m2m_ota_switch_firmware(void); +/*! +@fn \ + NMI_API sint8 m2m_ota_get_firmware_version(void); + +@brief + Get the OTA Firmware version. + +@return + The function SHALL return 0 for success and a negative value otherwise. +*/ +NMI_API sint8 m2m_ota_get_firmware_version(tstrM2mRev *pstrRev); /**@}*/ NMI_API sint8 m2m_ota_test(void); diff --git a/src/winc1500/include/driver/include/m2m_periph.h b/src/winc1500/include/driver/include/m2m_periph.h index 5a8eb2dbf..19f81f487 100644 --- a/src/winc1500/include/driver/include/m2m_periph.h +++ b/src/winc1500/include/driver/include/m2m_periph.h @@ -2,7 +2,7 @@ * * \file * - * \brief NMC1500 Peripherals Application Interface. + * \brief WINC Peripherals Application Interface. * * Copyright (c) 2015 Atmel Corporation. All rights reserved. * @@ -79,6 +79,10 @@ typedef struct { A list of GPIO numbers configurable through the m2m_periph module. */ typedef enum { + M2M_PERIPH_GPIO3, /*!< GPIO15 pad */ + M2M_PERIPH_GPIO4, /*!< GPIO16 pad */ + M2M_PERIPH_GPIO5, /*!< GPIO18 pad */ + M2M_PERIPH_GPIO6, /*!< GPIO18 pad */ M2M_PERIPH_GPIO15, /*!< GPIO15 pad */ M2M_PERIPH_GPIO16, /*!< GPIO16 pad */ M2M_PERIPH_GPIO18, /*!< GPIO18 pad */ @@ -165,35 +169,35 @@ typedef enum { */ typedef enum { - M2M_PERIPH_PULLUP_HOST_WAKEUP = (1ul << 0), - M2M_PERIPH_PULLUP_RTC_CLK = (1ul << 1), - M2M_PERIPH_PULLUP_IRQN = (1ul << 2), - M2M_PERIPH_PULLUP_GPIO_3 = (1ul << 3), - M2M_PERIPH_PULLUP_GPIO_4 = (1ul << 4), - M2M_PERIPH_PULLUP_GPIO_5 = (1ul << 5), - M2M_PERIPH_PULLUP_SD_DAT3 = (1ul << 6), - M2M_PERIPH_PULLUP_SD_DAT2_SPI_RXD = (1ul << 7), - M2M_PERIPH_PULLUP_SD_DAT1_SPI_SSN = (1ul << 8), - M2M_PERIPH_PULLUP_SD_CMD_SPI_SCK = (1ul << 9), - M2M_PERIPH_PULLUP_SD_DAT0_SPI_TXD = (1ul << 10), - M2M_PERIPH_PULLUP_GPIO_6 = (1ul << 11), - M2M_PERIPH_PULLUP_SD_CLK = (1ul << 12), - M2M_PERIPH_PULLUP_I2C_SCL = (1ul << 13), - M2M_PERIPH_PULLUP_I2C_SDA = (1ul << 14), - M2M_PERIPH_PULLUP_GPIO_11 = (1ul << 15), - M2M_PERIPH_PULLUP_GPIO_12 = (1ul << 16), - M2M_PERIPH_PULLUP_GPIO_13 = (1ul << 17), - M2M_PERIPH_PULLUP_GPIO_14 = (1ul << 18), - M2M_PERIPH_PULLUP_GPIO_15 = (1ul << 19), - M2M_PERIPH_PULLUP_GPIO_16 = (1ul << 20), - M2M_PERIPH_PULLUP_GPIO_17 = (1ul << 21), - M2M_PERIPH_PULLUP_GPIO_18 = (1ul << 22), - M2M_PERIPH_PULLUP_GPIO_19 = (1ul << 23), - M2M_PERIPH_PULLUP_GPIO_20 = (1ul << 24), - M2M_PERIPH_PULLUP_GPIO_21 = (1ul << 25), - M2M_PERIPH_PULLUP_GPIO_22 = (1ul << 26), - M2M_PERIPH_PULLUP_GPIO_23 = (1ul << 27), - M2M_PERIPH_PULLUP_GPIO_24 = (1ul << 28), + M2M_PERIPH_PULLUP_DIS_HOST_WAKEUP = (1ul << 0), + M2M_PERIPH_PULLUP_DIS_RTC_CLK = (1ul << 1), + M2M_PERIPH_PULLUP_DIS_IRQN = (1ul << 2), + M2M_PERIPH_PULLUP_DIS_GPIO_3 = (1ul << 3), + M2M_PERIPH_PULLUP_DIS_GPIO_4 = (1ul << 4), + M2M_PERIPH_PULLUP_DIS_GPIO_5 = (1ul << 5), + M2M_PERIPH_PULLUP_DIS_SD_DAT3 = (1ul << 6), + M2M_PERIPH_PULLUP_DIS_SD_DAT2_SPI_RXD = (1ul << 7), + M2M_PERIPH_PULLUP_DIS_SD_DAT1_SPI_SSN = (1ul << 9), + M2M_PERIPH_PULLUP_DIS_SD_CMD_SPI_SCK = (1ul << 10), + M2M_PERIPH_PULLUP_DIS_SD_DAT0_SPI_TXD = (1ul << 11), + M2M_PERIPH_PULLUP_DIS_GPIO_6 = (1ul << 12), + M2M_PERIPH_PULLUP_DIS_SD_CLK = (1ul << 13), + M2M_PERIPH_PULLUP_DIS_I2C_SCL = (1ul << 14), + M2M_PERIPH_PULLUP_DIS_I2C_SDA = (1ul << 15), + M2M_PERIPH_PULLUP_DIS_GPIO_11 = (1ul << 16), + M2M_PERIPH_PULLUP_DIS_GPIO_12 = (1ul << 17), + M2M_PERIPH_PULLUP_DIS_GPIO_13 = (1ul << 18), + M2M_PERIPH_PULLUP_DIS_GPIO_14 = (1ul << 19), + M2M_PERIPH_PULLUP_DIS_GPIO_15 = (1ul << 20), + M2M_PERIPH_PULLUP_DIS_GPIO_16 = (1ul << 21), + M2M_PERIPH_PULLUP_DIS_GPIO_17 = (1ul << 22), + M2M_PERIPH_PULLUP_DIS_GPIO_18 = (1ul << 23), + M2M_PERIPH_PULLUP_DIS_GPIO_19 = (1ul << 24), + M2M_PERIPH_PULLUP_DIS_GPIO_20 = (1ul << 25), + M2M_PERIPH_PULLUP_DIS_GPIO_21 = (1ul << 26), + M2M_PERIPH_PULLUP_DIS_GPIO_22 = (1ul << 27), + M2M_PERIPH_PULLUP_DIS_GPIO_23 = (1ul << 28), + M2M_PERIPH_PULLUP_DIS_GPIO_24 = (1ul << 29), } tenuPullupMask; /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* diff --git a/src/winc1500/include/driver/include/m2m_types.h b/src/winc1500/include/driver/include/m2m_types.h index 3fbaa2b71..ba06e014b 100644 --- a/src/winc1500/include/driver/include/m2m_types.h +++ b/src/winc1500/include/driver/include/m2m_types.h @@ -2,7 +2,7 @@ * * \file * - * \brief NMC1500 IoT Application Interface Internal Types. + * \brief WINC Application Interface Internal Types. * * Copyright (c) 2015 Atmel Corporation. All rights reserved. * @@ -95,6 +95,16 @@ MACROS ( ((uint32)M2M_MAKE_VERSION((fw_major), (fw_minor), (fw_patch))) << M2M_FW_VERSION_SHIFT) | \ ( ((uint32)M2M_MAKE_VERSION((drv_major), (drv_minor), (drv_patch))) << M2M_DRV_VERSION_SHIFT)) +#define REL_19_4_1_VER M2M_MAKE_VERSION_INFO(19,4,1,19,3,0) +#define REL_19_4_0_VER M2M_MAKE_VERSION_INFO(19,4,0,19,3,0) +#define REL_19_3_1_VER M2M_MAKE_VERSION_INFO(19,3,1,19,3,0) +#define REL_19_3_0_VER M2M_MAKE_VERSION_INFO(19,3,0,19,3,0) +#define REL_19_2_2_VER M2M_MAKE_VERSION_INFO(19,2,2,19,2,0) +#define REL_19_2_1_VER M2M_MAKE_VERSION_INFO(19,2,1,19,2,0) +#define REL_19_2_0_VER M2M_MAKE_VERSION_INFO(19,2,0,19,2,0) +#define REL_19_1_0_VER M2M_MAKE_VERSION_INFO(19,1,0,18,2,0) +#define REL_19_0_0_VER M2M_MAKE_VERSION_INFO(19,0,0,18,1,1) + /*======*======*======*======* FIRMWARE VERSION NO INFO *======*======*======*======*/ @@ -104,11 +114,11 @@ MACROS */ -#define M2M_FIRMWARE_VERSION_MINOR_NO (3) +#define M2M_FIRMWARE_VERSION_MINOR_NO (4) /*!< Firmware Minor release version number. */ -#define M2M_FIRMWARE_VERSION_PATCH_NO (0) +#define M2M_FIRMWARE_VERSION_PATCH_NO (4) /*!< Firmware patch release version number. */ @@ -191,7 +201,10 @@ MACROS #define M2M_CUST_IE_LEN_MAX 252 /*!< The maximum size of IE (Information Element). */ - +/********************* + * + * WIFI GROUP requests + */ #define M2M_CONFIG_CMD_BASE 1 /*!< The base value of all the host configuration commands opcodes. @@ -205,13 +218,28 @@ MACROS #define M2M_P2P_CMD_BASE 90 /*!< The base value of all the P2P mode host commands opcodes. */ -#define M2M_OTA_CMD_BASE 100 -/*!< The base value of all the OTA mode host commands opcodes. -*/ -#define M2M_SERVER_CMD_BASE 120 +#define M2M_SERVER_CMD_BASE 100 /*!< The base value of all the power save mode host commands codes. */ +/********************** + * OTA GROUP requests + */ +#define M2M_OTA_CMD_BASE 100 +/*!< The base value of all the OTA mode host commands opcodes. + * The OTA Have special group so can extended from 1-M2M_MAX_GRP_NUM_REQ +*/ +/*********************** + * + * CRYPTO group requests + */ +#define M2M_CRYPTO_CMD_BASE 1 +/*!< The base value of all the crypto mode host commands opcodes. + * The crypto Have special group so can extended from 1-M2M_MAX_GRP_NUM_REQ +*/ +#define M2M_MAX_GRP_NUM_REQ (127) +/*!< max number of request in one group equal to 127 as the last bit reserved for config or data pkt +*/ #define WEP_40_KEY_STRING_SIZE ((uint8)10) /*!< Indicate the wep key size in bytes for 40 bit string passphrase. @@ -223,72 +251,47 @@ MACROS #define WEP_KEY_MAX_INDEX ((uint8)4) /*!< Indicate the max key index value for WEP authentication */ +#define M2M_SHA256_CONTEXT_BUFF_LEN (128) +/*!< sha256 context size +*/ #define M2M_SCAN_DEFAULT_NUM_SLOTS (2) /*!< The default. number of scan slots performed by the WINC board. */ -#define M2M_SCAN_DEFAULT_SLOT_TIME (20) +#define M2M_SCAN_DEFAULT_SLOT_TIME (30) /*!< The default. duration in miliseconds of a scan slots performed by the WINC board. */ #define M2M_SCAN_DEFAULT_NUM_PROBE (2) /*!< The default. number of scan slots performed by the WINC board. */ -#define M2M_SCAN_FAIL ((uint8)1) -/*!< Indicate that the WINC board has failed to perform the scan operation. -*/ -#define M2M_JOIN_FAIL ((uint8)2) -/*!< Indicate that the WINC board has failed to join the BSS . -*/ -#define M2M_AUTH_FAIL ((uint8)3) -/*!< Indicate that the WINC board has failed to authenticate with the AP. -*/ -#define M2M_ASSOC_FAIL ((uint8)4) -/*!< Indicate that the WINC board has failed to associate with the AP. -*/ - -#define M2M_SCAN_ERR_WIFI ((sint8)-2) -/*!< currently not used. -*/ -#define M2M_SCAN_ERR_IP ((sint8)-3) -/*!< currently not used. -*/ -#define M2M_SCAN_ERR_AP ((sint8)-4) -/*!< currently not used. -*/ -#define M2M_SCAN_ERR_P2P ((sint8)-5) -/*!< currently not used. -*/ -#define M2M_SCAN_ERR_WPS ((sint8)-6) -/*!< currently not used. -*/ -#define M2M_DEFAULT_CONN_EMPTY_LIST ((sint8)-20) -/*!< - A failure response that indicates an empty network list as - a result to the function call m2m_default_connect. -*/ - - -#define M2M_DEFAULT_CONN_SCAN_MISMATCH ((sint8)-21) -/*!< +/*======*======*======*======* + CONNECTION ERROR DEFINITIONS + *======*======*======*======*/ +typedef enum { + M2M_DEFAULT_CONN_INPROGRESS = ((sint8)-23), + /*!< + A failure that indicates that a default connection or forced connection is in progress + */ + M2M_DEFAULT_CONN_FAIL, + /*!< + A failure response that indicates that the winc failed to connect to the cached network + */ + M2M_DEFAULT_CONN_SCAN_MISMATCH, + /*!< A failure response that indicates that no one of the cached networks was found in the scan results, as a result to the function call m2m_default_connect. -*/ -#define M2M_DEFAULT_CONN_FAIL ((sint8)-22) + */ + M2M_DEFAULT_CONN_EMPTY_LIST + /*!< + A failure response that indicates an empty network list as + a result to the function call m2m_default_connect. + */ + +}tenuM2mDefaultConnErrcode; + -/*!< - A failure response that indicates that the winc failed to connect to the cached network -*/ -/*======*======*======*======* - MONTIORING MODE DEFINITIONS - *======*======*======*======*/ -#define M2M_WIFI_FRAME_TYPE_ANY 0xFF -/*!< Set monitor mode to receive any of the frames types -*/ -#define M2M_WIFI_FRAME_SUB_TYPE_ANY 0xFF -/*!< Set monitor mode to receive frames with any sub type -*/ /*======*======*======*======* OTA DEFINITIONS @@ -306,6 +309,12 @@ MACROS /*!< Magic value set at the beginning of the OTA image header */ + +#define OTA_FORMAT_VER_0 (0) /*Till 19.2.2 format*/ +#define OTA_FORMAT_VER_1 (1) /*starting from 19.3.0 CRC is used and sequence number is used*/ +/*!< + Control structure format version +*/ #define OTA_SHA256_DIGEST_SIZE (32) /*!< Sha256 digest size in the OTA image, @@ -350,9 +359,35 @@ MACROS /**@}*/ /** -* @addtogroup WlanEnums +* @addtogroup WlanEnums Enumerations and Typedefs +* @ingroup m2m_wifi */ /**@{*/ + +/*! +@enum \ + tenuM2mConnChangedErrcode + +@brief + +*/ +typedef enum { + M2M_ERR_SCAN_FAIL = ((uint8)1), + /*!< Indicate that the WINC board has failed to perform the scan operation. + */ + M2M_ERR_JOIN_FAIL, + /*!< Indicate that the WINC board has failed to join the BSS . + */ + M2M_ERR_AUTH_FAIL, + /*!< Indicate that the WINC board has failed to authenticate with the AP. + */ + M2M_ERR_ASSOC_FAIL, + /*!< Indicate that the WINC board has failed to associate with the AP. + */ + M2M_ERR_CONN_INPROGRESS, + /*!< Indicate that the WINC board has another connection request in progress. + */ +}tenuM2mConnChangedErrcode; /*! @enum \ tenuM2mWepKeyIndex @@ -380,11 +415,11 @@ typedef enum { PWR_AUTO = ((uint8) 1), /*!< FW will decide the best power mode to use internally. */ PWR_LOW1, - /*low power mode #1. RX current 60mA, sensitivity Ok.*/ + /*low power mode #1*/ PWR_LOW2, - /*low power mode #2, RX current 55mA, sensitivity is less by 3dBm*/ + /*low power mode #2*/ PWR_HIGH, - /* high power mode: RX current 100mA.*/ + /* high power mode*/ }tenuM2mPwrMode; /*! @@ -467,6 +502,33 @@ typedef struct { */ }tstrM2mBatteryVoltage; +/*! +@enum \ + tenuM2mReqGroup + +@brief +*/ +typedef enum{ + M2M_REQ_GROUP_MAIN = 0, + M2M_REQ_GROUP_WIFI, + M2M_REQ_GROUP_IP, + M2M_REQ_GROUP_HIF, + M2M_REQ_GROUP_OTA, + M2M_REQ_GROUP_SSL, + M2M_REQ_GROUP_CRYPTO, + M2M_REQ_GROUP_SIGMA, +}tenuM2mReqGroup; + +/*! +@enum \ + tenuM2mReqpkt + +@brief +*/ +typedef enum{ + M2M_REQ_CONFIG_PKT, + M2M_REQ_DATA_PKT = 0x80 /*BIT7*/ +}tenuM2mReqpkt; /*! @enum \ tenuM2mConfigCmd @@ -583,6 +645,12 @@ typedef enum { M2M_WIFI_REQ_SET_MAC_MCAST, /*!< Set the WINC multicast filters. */ + M2M_WIFI_REQ_GET_PRNG, + /*!< Request PRNG. + */ + M2M_WIFI_RESP_GET_PRNG, + /*!< Response for PRNG. + */ M2M_WIFI_MAX_CONFIG_ALL, }tenuM2mConfigCmd; @@ -700,6 +768,24 @@ typedef enum { }tenuM2mP2pCmd; + +/*! +@enum \ + tenuM2mServerCmd + +@brief + This enum contains all the WINC commands while in PS mode. + These command are currently not supported. +*/ +typedef enum { + M2M_WIFI_REQ_CLIENT_CTRL = M2M_SERVER_CMD_BASE, + M2M_WIFI_RESP_CLIENT_INFO, + M2M_WIFI_REQ_SERVER_INIT, + M2M_WIFI_MAX_SERVER_ALL +}tenuM2mServerCmd; + + + /*! @enum \ tenuM2mOtaCmd @@ -720,24 +806,26 @@ typedef enum { M2M_OTA_MAX_ALL, }tenuM2mOtaCmd; - /*! @enum \ - tenuM2mServerCmd + tenuM2mCryptoCmd @brief - This enum contains all the WINC commands while in PS mode. - These command are currently not supported. + */ typedef enum { - M2M_WIFI_REQ_CLIENT_CTRL = M2M_SERVER_CMD_BASE, - M2M_WIFI_RESP_CLIENT_INFO, - M2M_WIFI_REQ_SERVER_INIT, - M2M_WIFI_MAX_SERVER_ALL -}tenuM2mServerCmd; - - - + M2M_CRYPTO_REQ_SHA256_INIT = M2M_CRYPTO_CMD_BASE, + M2M_CRYPTO_RESP_SHA256_INIT, + M2M_CRYPTO_REQ_SHA256_UPDATE, + M2M_CRYPTO_RESP_SHA256_UPDATE, + M2M_CRYPTO_REQ_SHA256_FINSIH, + M2M_CRYPTO_RESP_SHA256_FINSIH, + M2M_CRYPTO_REQ_RSA_SIGN_GEN, + M2M_CRYPTO_RESP_RSA_SIGN_GEN, + M2M_CRYPTO_REQ_RSA_SIGN_VERIFY, + M2M_CRYPTO_RESP_RSA_SIGN_VERIFY, + M2M_CRYPTO_MAX_ALL, +}tenuM2mCryptoCmd; /*! @enum \ @@ -753,6 +841,28 @@ typedef enum { M2M_IP_REQ_DISABLE_DHCP } tenuM2mIpCmd; +/*! +@enum \ + tenuM2mSigmaCmd + +@brief + +*/ +typedef enum { + /* Request IDs corresponding to the IP GROUP. */ + M2M_SIGMA_ENABLE = ((uint8) 3), + M2M_SIGMA_TA_START, + M2M_SIGMA_TA_STATS, + M2M_SIGMA_TA_RECEIVE_STOP, + M2M_SIGMA_ICMP_ARP, + M2M_SIGMA_ICMP_RX, + M2M_SIGMA_ICMP_TX, + M2M_SIGMA_UDP_TX, + M2M_SIGMA_UDP_TX_DEFER, + M2M_SIGMA_SECURITY_POLICY, + M2M_SIGMA_SET_SYSTIME +} tenuM2mSigmaCmd; + /*! @enum \ @@ -918,9 +1028,16 @@ typedef enum { M2M_WIFI_MODE_NORMAL = ((uint8) 1), /*!< Normal Mode means to run customer firmware version. */ - M2M_WIFI_MODE_CONFIG, - /*!< Config Mode means to run production test firmware version which is known as ATE (Burst) firmware. + M2M_WIFI_MODE_ATE_HIGH, + /*!< Config Mode in HIGH POWER means to run production test firmware version which is known as ATE (Burst) firmware. */ + M2M_WIFI_MODE_ATE_LOW, + /*!< Config Mode in LOW POWER means to run production test firmware version which is known as ATE (Burst) firmware. + */ + M2M_WIFI_MODE_ETHERNET, + /*!< etherent Mode + */ + M2M_WIFI_MODE_MAX, }tenuM2mWifiMode; /*! @@ -1081,9 +1198,6 @@ typedef struct { @sa tenuM2mSecType - -@todo - Use different error codes to differentiate error types. */ typedef struct{ uint8 u8AuthType; @@ -1189,6 +1303,21 @@ typedef struct { }tstrM2MScan; +/*! +@struct \ + tstrCyptoResp + +@brief + crypto response +*/ +typedef struct { + sint8 s8Resp; + /***/ + uint8 __PAD24__[3]; + /* + */ +}tstrCyptoResp; + /*! @struct \ @@ -1269,14 +1398,14 @@ typedef struct { Wi-Fi Connection State @sa - M2M_WIFI_DISCONNECTED, M2M_WIFI_CONNECTED, M2M_WIFI_REQ_CON_STATE_CHANGED + M2M_WIFI_DISCONNECTED, M2M_WIFI_CONNECTED, M2M_WIFI_REQ_CON_STATE_CHANGED,tenuM2mConnChangedErrcode */ typedef struct { uint8 u8CurrState; /*!< Current Wi-Fi connection state */ uint8 u8ErrCode; - /*!< Error type + /*!< Error type review tenuM2mConnChangedErrcode */ uint8 __PAD16__[2]; /*!< Padding bytes for forcing 4-byte alignment @@ -1736,6 +1865,7 @@ typedef struct{ */ }tstrOtaInitHdr; + /*! @struct \ tstrOtaControlSec @@ -1752,6 +1882,8 @@ typedef struct { */ uint32 u32OtaFormatVersion; /*!< + NA NA NA Flash version cs struct version + 00 00 00 00 00 Control structure format version, the value will be incremented in case of structure changed or updated */ uint32 u32OtaSequenceNumber; @@ -1834,6 +1966,12 @@ typedef enum { /*!< An OTA operation is already enabled. */ OTA_STATUS_UPDATE_INPROGRESS = 6, /*!< An OTA operation update is in progress */ + OTA_STATUS_IMAGE_VERIF_FAILED = 7, + /*!< OTA Verfication failed */ + OTA_STATUS_CONNECTION_ERROR = 8, + /*!< OTA connection error */ + OTA_STATUS_SERVER_ERROR = 9, + /*!< OTA server Error (file not found or else ...) */ } tenuOtaUpdateStatus; /*! @enum \ @@ -1956,6 +2094,28 @@ typedef struct{ */ }tstrM2MMulticastMac; +/*! +@struct \ + tstrPrng + +@brief + M2M Request PRNG + */ + typedef struct { + /*!< + return buffer address + */ + uint8 *pu8RngBuff; + /*!< + PRNG size requested + */ + uint16 u16PrngSize; + /*!< + PRNG pads + */ + uint8 __PAD16__[2]; +}tstrPrng; + /**@}*/ diff --git a/src/winc1500/include/driver/include/m2m_wifi.h b/src/winc1500/include/driver/include/m2m_wifi.h index ed3951287..cc0277644 100644 --- a/src/winc1500/include/driver/include/m2m_wifi.h +++ b/src/winc1500/include/driver/include/m2m_wifi.h @@ -2,7 +2,7 @@ * * \file * - * \brief NMC1500 IoT Application Interface. + * \brief WINC WLAN Application Interface. * * Copyright (c) 2015 Atmel Corporation. All rights reserved. * @@ -42,6 +42,10 @@ #ifndef __M2M_WIFI_H__ #define __M2M_WIFI_H__ +/** \defgroup m2m_wifi WLAN + * + */ + /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* INCLUDES *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ @@ -56,7 +60,7 @@ INCLUDES /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* MACROS *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ -/**@defgroup WlanEnums Enumeration/Typedef +/**@defgroup WlanEnums Enumerations and Typedefs * @ingroup m2m_wifi * @{*/ /*! @@ -64,11 +68,11 @@ MACROS tenuWifiFrameType @brief - Enumeration for Wi-Fi MAC frame type codes (2-bit) + Enumeration for Wi-Fi MAC frame type codes (2-bit) The following types are used to identify the type of frame sent or received. Each frame type constitutes a number of frame subtypes as defined in @ref tenuSubTypes to specify the exact type of frame. Values are defined as per the IEEE 802.11 standard. - + @remarks The following frame types are useful for advanced user usage when @ref CONF_MGMT is defined and the user application requires to monitor the frame transmission and reception. @@ -85,7 +89,11 @@ typedef enum { DATA_BASICTYPE = 0x08, /*!< Wi-Fi Data frame. */ - RESERVED = 0x0C + RESERVED = 0x0C, + + M2M_WIFI_FRAME_TYPE_ANY = 0xFF +/*!< Set monitor mode to receive any of the frames types +*/ }tenuWifiFrameType; @@ -105,7 +113,6 @@ typedef enum { tenuWifiFrameType */ typedef enum { - /*!< Sub-Types related to Management Sub-Types */ ASSOC_REQ = 0x00, ASSOC_RSP = 0x10, @@ -119,8 +126,7 @@ typedef enum { AUTH = 0xB0, DEAUTH = 0xC0, ACTION = 0xD0, - -/**@{*/ +/**@{*/ /* Sub-Types related to Control */ PS_POLL = 0xA4, RTS = 0xB4, @@ -130,7 +136,7 @@ typedef enum { CFEND_ACK = 0xF4, BLOCKACK_REQ = 0x84, BLOCKACK = 0x94, -/**@{*/ +/**@{*/ /* Sub-Types related to Data */ DATA = 0x08, DATA_ACK = 0x18, @@ -146,7 +152,10 @@ typedef enum { QOS_DATA_POLL_ACK = 0xB8, QOS_NULL_FRAME = 0xC8, QOS_CFPOLL = 0xE8, - QOS_CFPOLL_ACK = 0xF8 + QOS_CFPOLL_ACK = 0xF8, + M2M_WIFI_FRAME_SUB_TYPE_ANY = 0xFF + /*!< Set monitor mode to receive any of the frames types + */ }tenuSubTypes; @@ -160,85 +169,85 @@ typedef enum { Values are defined as per the IEEE 802.11 standard. @details Available IDs are:- - + ISSID : Service Set Identifier (SSID) - + ISUPRATES : Supported Rates - + IFHPARMS : FH parameter set - + IDSPARMS : DS parameter set - + ICFPARMS : CF parameter set - + ITIM : Traffic Information Map IIBPARMS : IBSS parameter set - + ICOUNTRY : Country element. - + IEDCAPARAMS : EDCA parameter set - + ITSPEC : Traffic Specification ITCLAS : Traffic Classification - + ISCHED : Schedule. - + ICTEXT : Challenge Text - + IPOWERCONSTRAINT : Power Constraint. - + IPOWERCAPABILITY : Power Capability - - ITPCREQUEST : TPC Request - - ITPCREPORT : TPC Report - - ISUPCHANNEL : Supported channel list - - ICHSWANNOUNC : Channel Switch Announcement - - IMEASUREMENTREQUEST : Measurement request - - IMEASUREMENTREPORT : Measurement report - - IQUIET : Quiet element Info - - IIBSSDFS : IBSS DFS - - IERPINFO : ERP Information - - ITSDELAY : TS Delay - - ITCLASPROCESS : TCLAS Processing - - IHTCAP : HT Capabilities - - IQOSCAP : QoS Capability - - IRSNELEMENT : RSN Information Element - - IEXSUPRATES : Extended Supported Rates - + + ITPCREQUEST : TPC Request + + ITPCREPORT : TPC Report + + ISUPCHANNEL : Supported channel list + + ICHSWANNOUNC : Channel Switch Announcement + + IMEASUREMENTREQUEST : Measurement request + + IMEASUREMENTREPORT : Measurement report + + IQUIET : Quiet element Info + + IIBSSDFS : IBSS DFS + + IERPINFO : ERP Information + + ITSDELAY : TS Delay + + ITCLASPROCESS : TCLAS Processing + + IHTCAP : HT Capabilities + + IQOSCAP : QoS Capability + + IRSNELEMENT : RSN Information Element + + IEXSUPRATES : Extended Supported Rates + IEXCHSWANNOUNC : Extended Ch Switch Announcement - - IHTOPERATION : HT Information - - ISECCHOFF : Secondary Channel Offset - - I2040COEX : Coexistence IE - + + IHTOPERATION : HT Information + + ISECCHOFF : Secondary Channel Offset + + I2040COEX : Coexistence IE + I2040INTOLCHREPORT : Intolerant channel report - - IOBSSSCAN : OBSS Scan parameters - - IEXTCAP : Extended capability - - IWMM : WMM parameters - + + IOBSSSCAN : OBSS Scan parameters + + IEXTCAP : Extended capability + + IWMM : WMM parameters + IWPAELEMENT : WPA Information Element - + */ typedef enum { ISSID = 0, @@ -293,7 +302,7 @@ typedef enum { /*!< TPC Report */ ISUPCHANNEL = 36, - /*!< Supported channel list + /* Supported channel list */ ICHSWANNOUNC = 37, /*!< Channel Switch Announcement @@ -366,22 +375,22 @@ typedef enum { tenuWifiCapability @brief - Enumeration for capability Information field bit. - The value of the capability information field from the 802.11 management frames received by the wireless LAN interface. + Enumeration for capability Information field bit. + The value of the capability information field from the 802.11 management frames received by the wireless LAN interface. Defining the capabilities of the Wi-Fi system. Values are defined as per the IEEE 802.11 standard. @details Capabilities:- - ESS/IBSS : Defines whether a frame is coming from an AP or not. - POLLABLE : CF Poll-able - POLLREQ : Request to be polled - PRIVACY : WEP encryption supported - SHORTPREAMBLE : Short Preamble is supported - SHORTSLOT : Short Slot is supported - PBCC :PBCC - CHANNELAGILITY :Channel Agility - SPECTRUM_MGMT :Spectrum Management - DSSS_OFDM : DSSS-OFDM + ESS/IBSS : Defines whether a frame is coming from an AP or not. + POLLABLE : CF Poll-able + POLLREQ : Request to be polled + PRIVACY : WEP encryption supported + SHORTPREAMBLE : Short Preamble is supported + SHORTSLOT : Short Slot is supported + PBCC :PBCC + CHANNELAGILITY :Channel Agility + SPECTRUM_MGMT :Spectrum Management + DSSS_OFDM : DSSS-OFDM */ typedef enum{ ESS = 0x01, @@ -426,10 +435,10 @@ typedef enum{ @typedef \ tpfAppWifiCb -@brief - Wi-Fi's main callback function handler, for handling the M2M_WIFI events received on the Wi-Fi interface. +@brief + Wi-Fi's main callback function handler, for handling the M2M_WIFI events received on the Wi-Fi interface. Such notifications are received in response to Wi-Fi/P2P operations such as @ref m2m_wifi_request_scan, - @ref m2m_wifi_connect. + @ref m2m_wifi_connect. Wi-Fi/P2P operations are implemented in an asynchronous mode, and all incoming information/status are to be handled through this callback function when the corresponding notification is received. Applications are expected to assign this wi-fi callback function by calling @ref m2m_wifi_init @@ -439,20 +448,20 @@ typedef enum{ /ref M2M_WIFI_RESP_CONN_INFO /ref M2M_WIFI_REQ_DHCP_CONF /ref M2M_WIFI_REQ_WPS - /ref M2M_WIFI_RESP_IP_CONFLICT + /ref M2M_WIFI_RESP_IP_CONFLICT /ref M2M_WIFI_RESP_SCAN_DONE /ref M2M_WIFI_RESP_SCAN_RESULT /ref M2M_WIFI_RESP_CURRENT_RSSI /ref M2M_WIFI_RESP_CLIENT_INFO /ref M2M_WIFI_RESP_PROVISION_INFO /ref M2M_WIFI_RESP_DEFAULT_CONNECT - + In case Bypass mode is defined : @ref M2M_WIFI_RESP_ETHERNET_RX_PACKET - + In case Monitoring mode is used: @ref M2M_WIFI_RESP_WIFI_RX_PACKET - + @param [in] pvMsg A pointer to a buffer containing the notification parameters (if any). It should be Casted to the correct data type corresponding to the notification type. @@ -469,9 +478,9 @@ typedef void (*tpfAppWifiCb) (uint8 u8MsgType, void * pvMsg); @typedef \ tpfAppEthCb -@brief +@brief Ethernet (Bypass mode) notification callback function receiving Bypass mode events as defined in - the Wi-Fi responses enumeration @ref tenuM2mStaCmd. + the Wi-Fi responses enumeration @ref tenuM2mStaCmd. @param [in] u8MsgType Type of notification. Possible types are: @@ -482,13 +491,13 @@ typedef void (*tpfAppWifiCb) (uint8 u8MsgType, void * pvMsg); casted to the correct data type corresponding to the notification type. For example, it could be a pointer to the buffer holding the received frame in case of @ref M2M_WIFI_RESP_ETHERNET_RX_PACKET event. - + @param [in] pvControlBuf A pointer to control buffer describing the accompanied message. To be casted to @ref tstrM2mIpCtrlBuf in case of @ref M2M_WIFI_RESP_ETHERNET_RX_PACKET event. @warning - Make sure that the bypass mode is defined before using @ref tpfAppEthCb. + Make sure that the bypass mode is defined before using @ref tpfAppEthCb. @see m2m_wifi_init @@ -500,7 +509,7 @@ typedef void (*tpfAppEthCb) (uint8 u8MsgType, void * pvMsg,void * pvCtrlBuf); @typedef \ tpfAppMonCb -@brief +@brief Wi-Fi monitoring mode callback function. This function delivers all received wi-Fi packets through the Wi-Fi interface. Applications requiring to operate in the monitoring should call the asynchronous function m2m_wifi_enable_monitoring_mode and expect to receive the Wi-Fi packets through this callback function, when the event ....is received. @@ -515,34 +524,34 @@ typedef void (*tpfAppEthCb) (uint8 u8MsgType, void * pvMsg,void * pvCtrlBuf); @param [in] u16PayloadSize The size of the payload in bytes. - + @see - m2m_wifi_enable_monitoring_mode - + m2m_wifi_enable_monitoring_mode + @warning u16PayloadSize should not exceed the buffer size given through m2m_wifi_enable_monitoring_mode. - + */ typedef void (*tpfAppMonCb) (tstrM2MWifiRxPacketInfo *pstrWifiRxPacket, uint8 * pu8Payload, uint16 u16PayloadSize); /** @struct \ tstrEthInitParam - -@brief - Structure to hold Ethernet interface parameters. - Structure is to be defined and have its attributes set,based on the application's functionality before + +@brief + Structure to hold Ethernet interface parameters. + Structure is to be defined and have its attributes set,based on the application's functionality before a call is made to the initialize the wi-fi operations by calling the @ref m2m_wifi_init function. Part of the wi-fi configuration structure @ref tstrWifiInitParam. Applications shouldn't need to define this structure, if the bypass mode is not defined. - + @see tpfAppEthCb tpfAppWifiCb m2m_wifi_init @warning - Make sure that bypass mode is defined before using @ref tstrEthInitParam. + Make sure that bypass mode is defined before using @ref tstrEthInitParam. */ typedef struct { @@ -562,24 +571,30 @@ typedef struct { /*!< Size of Receive Buffer for Ethernet Packet */ + uint8 u8EthernetEnable; + /*!< + Enable Ethernet mode flag + */ + uint8 __PAD8__; + } tstrEthInitParam; /*! @struct \ tstrM2mIpCtrlBuf - -@brief + +@brief Structure holding the incoming buffer's data size information, indicating the data size of the buffer and the remaining buffer's data size . - The data of the buffer which holds the packet sent to the host when in the bypass mode, is placed in the @ref tstrEthInitParam structure in the - @ref au8ethRcvBuf attribute. This following information is retrieved in the host when an event @ref M2M_WIFI_RESP_ETHERNET_RX_PACKET is received in - the Wi-Fi callback function @ref tpfAppWifiCb. + The data of the buffer which holds the packet sent to the host when in the bypass mode, is placed in the @ref tstrEthInitParam structure in the + @ref au8ethRcvBuf attribute. This following information is retrieved in the host when an event @ref M2M_WIFI_RESP_ETHERNET_RX_PACKET is received in + the Wi-Fi callback function @ref tpfAppWifiCb. The application is expected to use this structure's information to determine if there is still incoming data to be received from the firmware. - + @see tpfAppEthCb tstrEthInitParam - + @warning Make sure that bypass mode is defined before using @ref tstrM2mIpCtrlBuf @@ -600,14 +615,14 @@ typedef struct{ @struct \ tstrWifiInitParam -@brief +@brief Structure, holding the Wi-fi configuration attributes such as the wi-fi callback , monitoring mode callback and Ethernet parameter initialization structure. Such configuration parameters are required to be set before calling the wi-fi initialization function @ref m2m_wifi_init. @ref pfAppWifiCb attribute must be set to handle the wi-fi callback operations. @ref pfAppMonCb attribute, is optional based on whether the application requires the monitoring mode configuration, and can there not be set before the initialization. @ref strEthInitParam structure, is another optional configuration based on whether the bypass mode is set. - + */ typedef struct { tpfAppWifiCb pfAppWifiCb; @@ -645,24 +660,24 @@ FUNCTION PROTOTYPES @fn \ NMI_API void m2m_wifi_download_mode(void); -@return +@return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise. */ NMI_API sint8 m2m_wifi_download_mode(void); /**@}*/ /** @defgroup WifiInitFn m2m_wifi_init * @ingroup WLANAPI - * Synchronous initialization function for the WINC driver. This function initializes the driver by, registering the call back function for M2M_WIFI layer(also the call back function for bypass mode/monitoring mode if defined), - * initializing the host interface layer and the bus interfaces. - * Wi-Fi callback registering is essential to allow the handling of the events received, in response to the asynchronous Wi-Fi operations. + * Synchronous initialization function for the WINC driver. This function initializes the driver by, registering the call back function for M2M_WIFI layer(also the call back function for bypass mode/monitoring mode if defined), + * initializing the host interface layer and the bus interfaces. + * Wi-Fi callback registering is essential to allow the handling of the events received, in response to the asynchronous Wi-Fi operations. -Following are the possible Wi-Fi events that are expected to be received through the call back function(provided by the application) to the M2M_WIFI layer are : +Following are the possible Wi-Fi events that are expected to be received through the call back function(provided by the application) to the M2M_WIFI layer are : @ref M2M_WIFI_RESP_CON_STATE_CHANGED \n @ref M2M_WIFI_RESP_CONN_INFO \n @ref M2M_WIFI_REQ_DHCP_CONF \n @ref M2M_WIFI_REQ_WPS \n - @ref M2M_WIFI_RESP_IP_CONFLICT \n + @ref M2M_WIFI_RESP_IP_CONFLICT \n @ref M2M_WIFI_RESP_SCAN_DONE \n @ref M2M_WIFI_RESP_SCAN_RESULT \n @ref M2M_WIFI_RESP_CURRENT_RSSI \n @@ -672,10 +687,10 @@ Following are the possible Wi-Fi events that are expected to be received through Example: \n In case Bypass mode is defined : \n @ref M2M_WIFI_RESP_ETHERNET_RX_PACKET - + In case Monitoring mode is used: \n @ref M2M_WIFI_RESP_WIFI_RX_PACKET - + Any application using the WINC driver must call this function at the start of its main function. */ /**@{*/ @@ -686,35 +701,35 @@ Following are the possible Wi-Fi events that are expected to be received through @param [in] pWifiInitParam This is a pointer to the @ref tstrWifiInitParam structure which holds the pointer to the application WIFI layer call back function, monitoring mode call back and @ref tstrEthInitParam structure containing bypass mode parameters. - -@pre + +@pre Prior to this function call, application users must provide a call back function responsible for receiving all the wi-fi events that are received on the M2M_WIFI layer. - + @warning - Failure to successfully complete function indicates that the driver couldn't be initialized and a fatal error will prevent the application from proceeding. - + Failure to successfully complete function indicates that the driver couldn't be initialized and a fatal error will prevent the application from proceeding. + @see m2m_wifi_deinit tenuM2mStaCmd -@return +@return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise. */ NMI_API sint8 m2m_wifi_init(tstrWifiInitParam * pWifiInitParam); /**@}*/ /** @defgroup WifiDeinitFn m2m_wifi_deinit * @ingroup WLANAPI - * Synchronous de-initialization function to the WINC1500 driver. De-initializes the host interface and frees any resources used by the M2M_WIFI layer. - * This function must be called in the application closing phase,to ensure that all resources have been correctly released. No arguments are expected to be passed in. + * Synchronous de-initialization function to the WINC1500 driver. De-initializes the host interface and frees any resources used by the M2M_WIFI layer. + * This function must be called in the application closing phase,to ensure that all resources have been correctly released. No arguments are expected to be passed in. */ /**@{*/ /*! @fn \ NMI_API sint8 m2m_wifi_deinit(void * arg); - + @param [in] arg Generic argument. Not used in current implementation. -@return +@return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise. */ NMI_API sint8 m2m_wifi_deinit(void * arg); @@ -733,23 +748,23 @@ NMI_API sint8 m2m_wifi_deinit(void * arg); @pre Prior to receiving wi-fi interrupts, the WINC driver should have been successfully initialized by calling the @ref m2m_wifi_init function. - + @warning Failure to successfully complete this function indicates bus errors and hence a fatal error that will prevent the application from proceeding. -@return +@return The function returns @ref M2M_SUCCESS for successful interrupt handling and a negative value otherwise. */ NMI_API sint8 m2m_wifi_handle_events(void * arg); /**@}*/ /** @defgroup WifiDefaultConnectFn m2m_wifi_default_connect * @ingroup WLANAPI - * Asynchronous Wi-Fi connection function. An application calling this function will cause the firmware to correspondingly connect to the last successfully connected AP from the cached connections. + * Asynchronous Wi-Fi connection function. An application calling this function will cause the firmware to correspondingly connect to the last successfully connected AP from the cached connections. * A failure to connect will result in a response of @ref M2M_WIFI_RESP_DEFAULT_CONNECT indicating the connection error as defined in the structure @ref tstrM2MDefaultConnResp. - * Possible errors are: + * Possible errors are: * The connection list is empty @ref M2M_DEFAULT_CONN_EMPTY_LIST or a mismatch for the saved AP name @ref M2M_DEFAULT_CONN_SCAN_MISMATCH. - * only difference between this function and @ref m2m_wifi_connect, is the connection parameters. - * Connection using this function is expected to connect to cached connection parameters. + * only difference between this function and @ref m2m_wifi_connect, is the connection parameters. + * Connection using this function is expected to connect to cached connection parameters. */ /**@{*/ @@ -757,18 +772,18 @@ NMI_API sint8 m2m_wifi_handle_events(void * arg); @fn \ NMI_API sint8 m2m_wifi_default_connect(void); -@pre +@pre Prior to connecting, the WINC driver should have been successfully initialized by calling the @ref m2m_wifi_init function. - + @warning This function must be called in station mode only. - It's important to note that successful completion of a call to m2m_wifi_default_connect() does not guarantee success of the WIFI connection, + It's important to note that successful completion of a call to m2m_wifi_default_connect() does not guarantee success of the WIFI connection, and a negative return value indicates only locally-detected errors. - + @see m2m_wifi_connect - -@return + +@return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise. */ @@ -780,8 +795,8 @@ NMI_API sint8 m2m_wifi_default_connect(void); * the authentication information parameters and the channel number to which the connection will be established. * The connection status is known when a response of @ref M2M_WIFI_RESP_CON_STATE_CHANGED is received based on the states defined in @ref tenuM2mConnState, * successful connection is defined by @ref M2M_WIFI_CONNECTED -* - * The only difference between this function and @ref m2m_wifi_default_connect, is the connection parameters. +* + * The only difference between this function and @ref m2m_wifi_default_connect, is the connection parameters. * Connection using this function is expected to be made to a specific AP and to a specified channel. */ /**@{*/ @@ -791,12 +806,12 @@ NMI_API sint8 m2m_wifi_default_connect(void); @param [in] pcSsid A buffer holding the SSID corresponding to the requested AP. - + @param [in] u8SsidLen Length of the given SSID (not including the NULL termination). - A length less than ZERO or greater than the maximum defined SSID @ref M2M_MAX_SSID_LEN will result in a negative error + A length less than ZERO or greater than the maximum defined SSID @ref M2M_MAX_SSID_LEN will result in a negative error @ref M2M_ERR_FAIL. - + @param [in] u8SecType Wi-Fi security type security for the network. It can be one of the following types: -@ref M2M_WIFI_SEC_OPEN @@ -979,7 +994,7 @@ NMI_API sint8 m2m_wifi_disconnect(void); tstrM2MProvisionInfo *pstrProvInfo = (tstrM2MProvisionInfo*)pvMsg; if(pstrProvInfo->u8Status == M2M_SUCCESS) { - m2m_wifi_connect((char*)pstrProvInfo->au8SSID, (uint8)strlen(pstrProvInfo->au8SSID), pstrProvInfo->u8SecType, + m2m_wifi_connect((char*)pstrProvInfo->au8SSID, (uint8)strlen(pstrProvInfo->au8SSID), pstrProvInfo->u8SecType, pstrProvInfo->au8Password, M2M_WIFI_CH_ALL); printf("PROV SSID : %s\n",pstrProvInfo->au8SSID); @@ -1000,18 +1015,18 @@ NMI_API sint8 m2m_wifi_disconnect(void); int main() { tstrWifiInitParam param; - + param.pfAppWifiCb = wifi_event_cb; if(!m2m_wifi_init(¶m)) { tstrM2MAPConfig apConfig; uint8 bEnableRedirect = 1; - + strcpy(apConfig.au8SSID, "WINC_SSID"); apConfig.u8ListenChannel = 1; apConfig.u8SecType = M2M_WIFI_SEC_OPEN; apConfig.u8SsidHide = 0; - + // IP Address apConfig.au8DHCPServerIP[0] = 192; apConfig.au8DHCPServerIP[1] = 168; @@ -1019,14 +1034,14 @@ NMI_API sint8 m2m_wifi_disconnect(void); apConfig.au8DHCPServerIP[0] = 1; m2m_wifi_start_provision_mode(&apConfig, "atmelwincconf.com", bEnableRedirect); - + while(1) { m2m_wifi_handle_events(NULL); } } } - + @endcode */ NMI_API sint8 m2m_wifi_start_provision_mode(tstrM2MAPConfig *pstrAPConfig, char *pcHttpServerDomainName, uint8 bEnableHttpRedirect); @@ -1044,7 +1059,7 @@ NMI_API sint8 m2m_wifi_start_provision_mode(tstrM2MAPConfig *pstrAPConfig, char An active provisioning session must be active before it is terminated through this function. @see m2m_wifi_start_provision_mode - + @return The function returns ZERO for success and a negative value otherwise. */ @@ -1063,14 +1078,14 @@ NMI_API sint8 m2m_wifi_stop_provision_mode(void); @brief Retrieve the current Connection information. The result is passed to the Wi-Fi notification callback with [M2M_WIFI_RESP_CONN_INFO](@ref M2M_WIFI_RESP_CONN_INFO). -@pre +@pre - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at startup. Registering the callback is done through passing it to the initialization @ref m2m_wifi_init function. - The event @ref M2M_WIFI_RESP_CONN_INFO must be handled in the callback to receive the requested connection info. - + Connection Information retrieved: - + -Connection Security -Connection RSSI -Remote MAC address @@ -1082,7 +1097,6 @@ NMI_API sint8 m2m_wifi_stop_provision_mode(void); @sa M2M_WIFI_RESP_CONN_INFO, tstrM2MConnInfo - @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise. \section Example @@ -1100,12 +1114,12 @@ NMI_API sint8 m2m_wifi_stop_provision_mode(void); case M2M_WIFI_RESP_CONN_INFO: { tstrM2MConnInfo *pstrConnInfo = (tstrM2MConnInfo*)pvMsg; - + printf("CONNECTED AP INFO\n"); printf("SSID : %s\n",pstrConnInfo->acSSID); printf("SEC TYPE : %d\n",pstrConnInfo->u8SecType); - printf("Signal Strength : %d\n", pstrConnInfo->s8RSSI); - printf("Local IP Address : %d.%d.%d.%d\n", + printf("Signal Strength : %d\n", pstrConnInfo->s8RSSI); + printf("Local IP Address : %d.%d.%d.%d\n", pstrConnInfo->au8IPAddr[0] , pstrConnInfo->au8IPAddr[1], pstrConnInfo->au8IPAddr[2], pstrConnInfo->au8IPAddr[3]); } break; @@ -1124,27 +1138,27 @@ NMI_API sint8 m2m_wifi_stop_provision_mode(void); int main() { tstrWifiInitParam param; - + param.pfAppWifiCb = wifi_event_cb; if(!m2m_wifi_init(¶m)) { // connect to the default AP m2m_wifi_default_connect(); - + while(1) { m2m_wifi_handle_events(NULL); } } } - + @endcode */ NMI_API sint8 m2m_wifi_get_connection_info(void); /**@}*/ /** @defgroup WifiSetMacAddFn m2m_wifi_set_mac_address * @ingroup WLANAPI - * Synchronous MAC address assigning to the NMC1500. It is used for non-production SW. Assign MAC address to the WINC device. + * Synchronous MAC address assigning to the NMC1500. It is used for non-production SW. Assign MAC address to the WINC device. */ /**@{*/ /*! @@ -1156,7 +1170,7 @@ NMI_API sint8 m2m_wifi_get_connection_info(void); @param [in] au8MacAddress MAC Address to be provisioned to the WINC. -@return +@return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise. */ NMI_API sint8 m2m_wifi_set_mac_address(uint8 au8MacAddress[6]); @@ -1176,19 +1190,19 @@ NMI_API sint8 m2m_wifi_set_mac_address(uint8 au8MacAddress[6]); WPS Trigger method. Could be: - [WPS_PIN_TRIGGER](@ref WPS_PIN_TRIGGER) Push button method - [WPS_PBC_TRIGGER](@ref WPS_PBC_TRIGGER) Pin method - + @param [in] pcPinNumber PIN number for WPS PIN method. It is not used if the trigger type is WPS_PBC_TRIGGER. It must follow the rules stated by the WPS Standard. @warning This function is not allowed in AP or P2P modes. - -@pre + +@pre - A Wi-Fi notification callback of type (@ref tpfAppWifiCb MUST be implemented and registered at startup. Registering the callback is done through passing it to the [m2m_wifi_init](@ref m2m_wifi_init). - The event [M2M_WIFI_REQ_WPS](@ref M2M_WIFI_REQ_WPS) must be handled in the callback to receive the WPS status. - - The WINC device MUST be in IDLE or STA mode. If AP or P2P mode is active, the WPS will not be performed. + - The WINC device MUST be in IDLE or STA mode. If AP or P2P mode is active, the WPS will not be performed. - The [m2m_wifi_handle_events](@ref m2m_wifi_handle_events) MUST be called to receive the responses in the callback. @see tpfAppWifiCb @@ -1219,7 +1233,7 @@ NMI_API sint8 m2m_wifi_set_mac_address(uint8 au8MacAddress[6]); printf("WPS PSK : %s\n",pstrWPS->au8PSK); printf("WPS SSID Auth Type : %s\n",pstrWPS->u8AuthType == M2M_WIFI_SEC_OPEN ? "OPEN" : "WPA/WPA2"); printf("WPS Channel : %d\n",pstrWPS->u8Ch + 1); - + // establish Wi-Fi connection m2m_wifi_connect((char*)pstrWPS->au8SSID, (uint8)m2m_strlen(pstrWPS->au8SSID), pstrWPS->u8AuthType, pstrWPS->au8PSK, pstrWPS->u8Ch); @@ -1230,7 +1244,7 @@ NMI_API sint8 m2m_wifi_set_mac_address(uint8 au8MacAddress[6]); } } break; - + default: break; } @@ -1239,20 +1253,20 @@ NMI_API sint8 m2m_wifi_set_mac_address(uint8 au8MacAddress[6]); int main() { tstrWifiInitParam param; - + param.pfAppWifiCb = wifi_event_cb; if(!m2m_wifi_init(¶m)) { // Trigger WPS in Push button mode. m2m_wifi_wps(WPS_PBC_TRIGGER, NULL); - + while(1) { m2m_wifi_handle_events(NULL); } } } - + @endcode */ NMI_API sint8 m2m_wifi_wps(uint8 u8TriggerType,const char *pcPinNumber); @@ -1278,7 +1292,7 @@ NMI_API sint8 m2m_wifi_wps_disable(void); The WINC supports P2P in device listening mode ONLY (intent is ZERO). The WINC P2P implementation does not support P2P GO (Group Owner) mode. Active P2P devices (e.g. phones) could find the WINC in the search list. When a device is connected to WINC, a Wi-Fi notification event - @ref M2M_WIFI_RESP_CON_STATE_CHANGED is triggered. After a short while, the DHCP IP Address is obtained + @ref M2M_WIFI_RESP_CON_STATE_CHANGED is triggered. After a short while, the DHCP IP Address is obtained and an event @ref M2M_WIFI_REQ_DHCP_CONF is triggered. Refer to the code examples for a more illustrative example. */ /**@{*/ @@ -1292,7 +1306,7 @@ NMI_API sint8 m2m_wifi_wps_disable(void); @pre - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at initialization. Registering the callback is done through passing it to the @ref m2m_wifi_init. - - The events @ref M2M_WIFI_RESP_CON_STATE_CHANGED and @ref M2M_WIFI_REQ_DHCP_CONF + - The events @ref M2M_WIFI_RESP_CON_STATE_CHANGED and @ref M2M_WIFI_REQ_DHCP_CONF must be handled in the callback. - The @ref m2m_wifi_handle_events MUST be called to receive the responses in the callback. @@ -1313,7 +1327,7 @@ NMI_API sint8 m2m_wifi_wps_disable(void); @code #include "m2m_wifi.h" #include "m2m_types.h" - + void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg) { switch(u8WiFiEvent) @@ -1322,11 +1336,11 @@ NMI_API sint8 m2m_wifi_wps_disable(void); { tstrM2mWifiStateChanged *pstrWifiState = (tstrM2mWifiStateChanged*)pvMsg; M2M_INFO("Wifi State :: %s :: ErrCode %d\n", pstrWifiState->u8CurrState? "CONNECTED":"DISCONNECTED",pstrWifiState->u8ErrCode); - + // Do something } break; - + case M2M_WIFI_REQ_DHCP_CONF: { uint8 *pu8IPAddress = (uint8*)pvMsg; @@ -1334,16 +1348,16 @@ NMI_API sint8 m2m_wifi_wps_disable(void); printf("P2P IP Address \"%u.%u.%u.%u\"\n",pu8IPAddress[0],pu8IPAddress[1],pu8IPAddress[2],pu8IPAddress[3]); } break; - + default: break; } } - + int main() { tstrWifiInitParam param; - + param.pfAppWifiCb = wifi_event_cb; if(!m2m_wifi_init(¶m)) { @@ -1356,7 +1370,7 @@ NMI_API sint8 m2m_wifi_wps_disable(void); } } } - + @endcode */ @@ -1364,13 +1378,13 @@ NMI_API sint8 m2m_wifi_p2p(uint8 u8Channel); /**@}*/ /** @defgroup WifiP2PDisconnectFn m2m_wifi_p2p_disconnect * @ingroup WLANAPI - * Disable the NMC1500 device Wi-Fi direct mode (P2P). + * Disable the NMC1500 device Wi-Fi direct mode (P2P). */ /**@{*/ /*! @fn \ NMI_API sint8 m2m_wifi_p2p_disconnect(void); -@pre +@pre The p2p mode must have be enabled and active before a disconnect can be called. @see m2m_wifi_p2p @@ -1381,7 +1395,7 @@ NMI_API sint8 m2m_wifi_p2p_disconnect(void); /**@}*/ /** @defgroup WifiEnableApFn m2m_wifi_enable_ap * @ingroup WLANAPI - * Asynchronous wi-fi hot-spot enabling function. + * Asynchronous wi-fi hot-spot enabling function. * The WINC supports AP mode operation with the following limitations: - Only 1 STA could be associated at a time. - Open and WEP are the only supported security types @@ -1396,7 +1410,7 @@ NMI_API sint8 m2m_wifi_p2p_disconnect(void); @warning This function is not allowed in P2P or STA modes. - + @pre - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at initialization. Registering the callback is done through passing it to the [m2m_wifi_init](@ref m2m_wifi_init). @@ -1419,7 +1433,7 @@ NMI_API sint8 m2m_wifi_p2p_disconnect(void); @code #include "m2m_wifi.h" #include "m2m_types.h" - + void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg) { switch(u8WiFiEvent) @@ -1431,35 +1445,35 @@ NMI_API sint8 m2m_wifi_p2p_disconnect(void); printf("Associated STA has IP Address \"%u.%u.%u.%u\"\n",pu8IPAddress[0],pu8IPAddress[1],pu8IPAddress[2],pu8IPAddress[3]); } break; - + default: break; } } - + int main() { tstrWifiInitParam param; - + param.pfAppWifiCb = wifi_event_cb; if(!m2m_wifi_init(¶m)) { tstrM2MAPConfig apConfig; - + strcpy(apConfig.au8SSID, "WINC_SSID"); apConfig.u8ListenChannel = 1; apConfig.u8SecType = M2M_WIFI_SEC_OPEN; apConfig.u8SsidHide = 0; - + // IP Address apConfig.au8DHCPServerIP[0] = 192; apConfig.au8DHCPServerIP[1] = 168; apConfig.au8DHCPServerIP[2] = 1; apConfig.au8DHCPServerIP[0] = 1; - + // Trigger AP m2m_wifi_enable_ap(&apConfig); - + while(1) { m2m_wifi_handle_events(NULL); @@ -1490,7 +1504,7 @@ NMI_API sint8 m2m_wifi_disable_ap(void); /**@}*/ /** @defgroup SetStaticIPFn m2m_wifi_set_static_ip * @ingroup WLANAPI - * Synchronous static IP Address configuration function. + * Synchronous static IP Address configuration function. */ /**@{*/ /*! @@ -1503,10 +1517,10 @@ NMI_API sint8 m2m_wifi_disable_ap(void); @warning This function should not be used. DHCP configuration is requested automatically after successful Wi-Fi connection is established. - + @see tstrM2MIPConfig - + @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise. */ @@ -1515,13 +1529,13 @@ NMI_API sint8 m2m_wifi_set_static_ip(tstrM2MIPConfig * pstrStaticIPConf); /** @defgroup RequestDHCPClientFn m2m_wifi_request_dhcp_client * @ingroup WLANAPI * Starts the DHCP client operation(DHCP requested by the firmware automatically in STA/AP/P2P mode). - * + * */ /**@{*/ /*! @fn \ NMI_API sint8 m2m_wifi_request_dhcp_client(void); - + @warning This function should not be used. DHCP configuration is requested automatically after successful Wi-Fi connection is established. @@ -1556,11 +1570,11 @@ NMI_API sint8 m2m_wifi_request_dhcp_server(uint8* addr); /*! @fn \ NMI_API sint8 m2m_wifi_enable_dhcp(uint8 u8DhcpEn ); - + @brief Enable/Disable the DHCP client after connection. -@param [in] u8DhcpEn +@param [in] u8DhcpEn Possible values: 1: Enable DHCP client after connection. 0: Disable DHCP client after connection. @@ -1568,10 +1582,10 @@ NMI_API sint8 m2m_wifi_request_dhcp_server(uint8* addr); - DHCP client is enabled by default -This Function should be called before using m2m_wifi_set_static_ip() - + @sa m2m_wifi_set_static_ip() - + @return The function SHALL return 0 for success and a negative value otherwise. */ @@ -1632,12 +1646,12 @@ NMI_API sint8 m2m_wifi_set_scan_region(uint16 ScanRegion); NMI_API sint8 m2m_wifi_request_scan(uint8 ch); @param [in] ch - RF Channel ID for SCAN operation. It should be set according to tenuM2mScanCh. + RF Channel ID for SCAN operation. It should be set according to tenuM2mScanCh. With a value of M2M_WIFI_CH_ALL(255)), means to scan all channels. @warning This function is not allowed in P2P or AP modes. It works only for STA mode (connected or disconnected). - + @pre - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at initialization. Registering the callback is done through passing it to the @ref m2m_wifi_init. @@ -1664,17 +1678,17 @@ NMI_API sint8 m2m_wifi_set_scan_region(uint16 ScanRegion); #include "m2m_wifi.h" #include "m2m_types.h" - + void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg) { static uint8 u8ScanResultIdx = 0; - + switch(u8WiFiEvent) { case M2M_WIFI_RESP_SCAN_DONE: { tstrM2mScanDone *pstrInfo = (tstrM2mScanDone*)pvMsg; - + printf("Num of AP found %d\n",pstrInfo->u8NumofCh); if(pstrInfo->s8ScanState == M2M_SUCCESS) { @@ -1696,12 +1710,12 @@ NMI_API sint8 m2m_wifi_set_scan_region(uint16 ScanRegion); } } break; - + case M2M_WIFI_RESP_SCAN_RESULT: { tstrM2mWifiscanResult *pstrScanResult =(tstrM2mWifiscanResult*)pvMsg; uint8 u8NumFoundAPs = m2m_wifi_get_num_ap_found(); - + printf(">>%02d RI %d SEC %s CH %02d BSSID %02X:%02X:%02X:%02X:%02X:%02X SSID %s\n", pstrScanResult->u8index,pstrScanResult->s8rssi, pstrScanResult->u8AuthType, @@ -1709,7 +1723,7 @@ NMI_API sint8 m2m_wifi_set_scan_region(uint16 ScanRegion); pstrScanResult->au8BSSID[0], pstrScanResult->au8BSSID[1], pstrScanResult->au8BSSID[2], pstrScanResult->au8BSSID[3], pstrScanResult->au8BSSID[4], pstrScanResult->au8BSSID[5], pstrScanResult->au8SSID); - + if(u8ScanResultIdx < u8NumFoundAPs) { // Read the next scan result @@ -1722,24 +1736,24 @@ NMI_API sint8 m2m_wifi_set_scan_region(uint16 ScanRegion); break; } } - + int main() { tstrWifiInitParam param; - + param.pfAppWifiCb = wifi_event_cb; if(!m2m_wifi_init(¶m)) { // Scan all channels m2m_wifi_request_scan(M2M_WIFI_CH_ALL); - + while(1) { m2m_wifi_handle_events(NULL); } } } - + @endcode */ NMI_API sint8 m2m_wifi_request_scan(uint8 ch); @@ -1747,24 +1761,24 @@ NMI_API sint8 m2m_wifi_request_scan(uint8 ch); /** @defgroup WifiGetNumAPFoundFn m2m_wifi_get_num_ap_found * @ingroup WLANAPI * Synchronous function to retrieve the number of AP's found in the last scan request, The function read the number of AP's from global variable which updated in the Wi-Fi callback function through the M2M_WIFI_RESP_SCAN_DONE event. -* Function used only in STA mode only. +* Function used only in STA mode only. */ /**@{*/ /*! @fn NMI_API uint8 m2m_wifi_get_num_ap_found(void); -@see m2m_wifi_request_scan +@see m2m_wifi_request_scan M2M_WIFI_RESP_SCAN_DONE - M2M_WIFI_RESP_SCAN_RESULT -@pre m2m_wifi_request_scan need to be called first + M2M_WIFI_RESP_SCAN_RESULT +@pre m2m_wifi_request_scan need to be called first - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at initialization. Registering the callback is done through passing it to the @ref m2m_wifi_init. - - The event @ref M2M_WIFI_RESP_SCAN_DONE must be handled in the callback to receive the requested connection information. + - The event @ref M2M_WIFI_RESP_SCAN_DONE must be handled in the callback to receive the requested connection information. @warning This function must be called only in the wi-fi callback function when the events @ref M2M_WIFI_RESP_SCAN_DONE or @ref M2M_WIFI_RESP_SCAN_RESULT are received. Calling this function in any other place will result in undefined/outdated numbers. @return Return the number of AP's found in the last Scan Request. - + \section Example The code snippet demonstrates an example of how the scan request is called from the application's main function and the handling of the events received in response. @@ -1772,17 +1786,17 @@ NMI_API sint8 m2m_wifi_request_scan(uint8 ch); #include "m2m_wifi.h" #include "m2m_types.h" - + void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg) { static uint8 u8ScanResultIdx = 0; - + switch(u8WiFiEvent) { case M2M_WIFI_RESP_SCAN_DONE: { tstrM2mScanDone *pstrInfo = (tstrM2mScanDone*)pvMsg; - + printf("Num of AP found %d\n",pstrInfo->u8NumofCh); if(pstrInfo->s8ScanState == M2M_SUCCESS) { @@ -1804,12 +1818,12 @@ NMI_API sint8 m2m_wifi_request_scan(uint8 ch); } } break; - + case M2M_WIFI_RESP_SCAN_RESULT: { tstrM2mWifiscanResult *pstrScanResult =(tstrM2mWifiscanResult*)pvMsg; uint8 u8NumFoundAPs = m2m_wifi_get_num_ap_found(); - + printf(">>%02d RI %d SEC %s CH %02d BSSID %02X:%02X:%02X:%02X:%02X:%02X SSID %s\n", pstrScanResult->u8index,pstrScanResult->s8rssi, pstrScanResult->u8AuthType, @@ -1817,7 +1831,7 @@ NMI_API sint8 m2m_wifi_request_scan(uint8 ch); pstrScanResult->au8BSSID[0], pstrScanResult->au8BSSID[1], pstrScanResult->au8BSSID[2], pstrScanResult->au8BSSID[3], pstrScanResult->au8BSSID[4], pstrScanResult->au8BSSID[5], pstrScanResult->au8SSID); - + if(u8ScanResultIdx < u8NumFoundAPs) { // Read the next scan result @@ -1830,25 +1844,25 @@ NMI_API sint8 m2m_wifi_request_scan(uint8 ch); break; } } - + int main() { tstrWifiInitParam param; - + param.pfAppWifiCb = wifi_event_cb; if(!m2m_wifi_init(¶m)) { // Scan all channels m2m_wifi_request_scan(M2M_WIFI_CH_ALL); - + while(1) { m2m_wifi_handle_events(NULL); } } } - -@endcode + +@endcode */ NMI_API uint8 m2m_wifi_get_num_ap_found(void); /**@}*/ @@ -1857,28 +1871,28 @@ NMI_API uint8 m2m_wifi_get_num_ap_found(void); * Synchronous call to read the AP information from the SCAN Result list with the given index. * This function is expected to be called when the response events M2M_WIFI_RESP_SCAN_RESULT or * M2M_WIFI_RESP_SCAN_DONE are received in the wi-fi callback function. -* The response information received can be obtained through the casting to the @ref tstrM2mWifiscanResult structure +* The response information received can be obtained through the casting to the @ref tstrM2mWifiscanResult structure */ /**@{*/ /*! @fn NMI_API sint8 m2m_wifi_req_scan_result(uint8 index); -@param [in] index +@param [in] index Index for the requested result, the index range start from 0 till number of AP's found @see tstrM2mWifiscanResult m2m_wifi_get_num_ap_found - m2m_wifi_request_scan - -@pre @ref m2m_wifi_request_scan needs to be called first, then m2m_wifi_get_num_ap_found - to get the number of AP's found + m2m_wifi_request_scan + +@pre @ref m2m_wifi_request_scan needs to be called first, then m2m_wifi_get_num_ap_found + to get the number of AP's found - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at startup. Registering the callback is done through passing it to the @ref m2m_wifi_init function. - The event @ref M2M_WIFI_RESP_SCAN_RESULT must be handled in the callback to receive the requested connection information. @warning Function used in STA mode only. the scan results are updated only if the scan request is called. - Calling this function only without a scan request will lead to firmware errors. + Calling this function only without a scan request will lead to firmware errors. Refrain from introducing a large delay between the scan request and the scan result request, to prevent an errors occurring. - + @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise. \section Example The code snippet demonstrates an example of how the scan request is called from the application's main function and the handling of @@ -1886,17 +1900,17 @@ NMI_API uint8 m2m_wifi_get_num_ap_found(void); @code #include "m2m_wifi.h" #include "m2m_types.h" - + void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg) { static uint8 u8ScanResultIdx = 0; - + switch(u8WiFiEvent) { case M2M_WIFI_RESP_SCAN_DONE: { tstrM2mScanDone *pstrInfo = (tstrM2mScanDone*)pvMsg; - + printf("Num of AP found %d\n",pstrInfo->u8NumofCh); if(pstrInfo->s8ScanState == M2M_SUCCESS) { @@ -1918,12 +1932,12 @@ NMI_API uint8 m2m_wifi_get_num_ap_found(void); } } break; - + case M2M_WIFI_RESP_SCAN_RESULT: { tstrM2mWifiscanResult *pstrScanResult =(tstrM2mWifiscanResult*)pvMsg; uint8 u8NumFoundAPs = m2m_wifi_get_num_ap_found(); - + printf(">>%02d RI %d SEC %s CH %02d BSSID %02X:%02X:%02X:%02X:%02X:%02X SSID %s\n", pstrScanResult->u8index,pstrScanResult->s8rssi, pstrScanResult->u8AuthType, @@ -1931,7 +1945,7 @@ NMI_API uint8 m2m_wifi_get_num_ap_found(void); pstrScanResult->au8BSSID[0], pstrScanResult->au8BSSID[1], pstrScanResult->au8BSSID[2], pstrScanResult->au8BSSID[3], pstrScanResult->au8BSSID[4], pstrScanResult->au8BSSID[5], pstrScanResult->au8SSID); - + if(u8ScanResultIdx < u8NumFoundAPs) { // Read the next scan result @@ -1944,25 +1958,25 @@ NMI_API uint8 m2m_wifi_get_num_ap_found(void); break; } } - + int main() { tstrWifiInitParam param; - + param.pfAppWifiCb = wifi_event_cb; if(!m2m_wifi_init(¶m)) { // Scan all channels m2m_wifi_request_scan(M2M_WIFI_CH_ALL); - + while(1) { m2m_wifi_handle_events(NULL); } } } - -@endcode + +@endcode */ NMI_API sint8 m2m_wifi_req_scan_result(uint8 index); /**@}*/ @@ -1976,19 +1990,19 @@ NMI_API sint8 m2m_wifi_req_scan_result(uint8 index); @fn NMI_API sint8 m2m_wifi_req_curr_rssi(void); @pre - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered before initialization. Registering the callback is done through passing it to the [m2m_wifi_init](@ref m2m_wifi_init) through the @ref tstrWifiInitParam initialization structure. - - The event @ref M2M_WIFI_RESP_CURRENT_RSSI must be handled in the callback to receive the requested connection information. -@return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise. + - The event @ref M2M_WIFI_RESP_CURRENT_RSSI must be handled in the callback to receive the requested connection information. +@return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise. \section Example - The code snippet demonstrates how the RSSI request is called in the application's main function and the handling of event received in the callback. + The code snippet demonstrates how the RSSI request is called in the application's main function and the handling of event received in the callback. @code #include "m2m_wifi.h" #include "m2m_types.h" - + void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg) { static uint8 u8ScanResultIdx = 0; - + switch(u8WiFiEvent) { case M2M_WIFI_RESP_CURRENT_RSSI: @@ -2001,17 +2015,17 @@ NMI_API sint8 m2m_wifi_req_scan_result(uint8 index); break; } } - + int main() { tstrWifiInitParam param; - + param.pfAppWifiCb = wifi_event_cb; if(!m2m_wifi_init(¶m)) { // Scan all channels m2m_wifi_req_curr_rssi(); - + while(1) { m2m_wifi_handle_events(NULL); @@ -2019,7 +2033,7 @@ NMI_API sint8 m2m_wifi_req_scan_result(uint8 index); } } -@endcode +@endcode */ NMI_API sint8 m2m_wifi_req_curr_rssi(void); @@ -2036,10 +2050,10 @@ NMI_API sint8 m2m_wifi_req_curr_rssi(void); @param [out] pu8MacAddr Output MAC address buffer of 6 bytes size. Valid only if *pu8Valid=1. @param [out] pu8IsValid - A output boolean value to indicate the validity of pu8MacAddr in OTP. + A output boolean value to indicate the validity of pu8MacAddr in OTP. Output zero if the OTP memory is not programmed, non-zero otherwise. @pre m2m_wifi_init required to call any WIFI/socket function -@see m2m_wifi_get_mac_address +@see m2m_wifi_get_mac_address @return The function returns @ref M2M_SUCCESS for success and a negative value otherwise. @@ -2052,11 +2066,11 @@ NMI_API sint8 m2m_wifi_get_otp_mac_address(uint8 *pu8MacAddr, uint8 * pu8IsValid */ /**@{*/ /*! -@fn NMI_API sint8 m2m_wifi_get_mac_address(uint8 *pu8MacAddr) +@fn NMI_API sint8 m2m_wifi_get_mac_address(uint8 *pu8MacAddr) @param [out] pu8MacAddr - Output MAC address buffer of 6 bytes size. + Output MAC address buffer of 6 bytes size. @pre m2m_wifi_init required to call any WIFI/socket function -@see m2m_wifi_get_otp_mac_address +@see m2m_wifi_get_otp_mac_address @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise. */ @@ -2064,7 +2078,7 @@ NMI_API sint8 m2m_wifi_get_mac_address(uint8 *pu8MacAddr); /**@}*/ /** @defgroup SetSleepModeFn m2m_wifi_set_sleep_mode * @ingroup WLANAPI - * Synchronous power-save mode setting function for the NMC1500. + * Synchronous power-save mode setting function for the NMC1500. */ /**@{*/ /*! @@ -2072,10 +2086,10 @@ NMI_API sint8 m2m_wifi_get_mac_address(uint8 *pu8MacAddr); @param [in] PsTyp Desired power saving mode. Supported types are defined in @ref tenuPowerSaveModes. @param [in] BcastEn - Broadcast reception enable flag. + Broadcast reception enable flag. If it is 1, the WINC1500 must be awake each DTIM beacon for receiving broadcast traffic. - If it is 0, the WINC1500 will not wakeup at the DTIM beacon, but its wakeup depends only - on the the configured Listen Interval. + If it is 0, the WINC1500 will not wakeup at the DTIM beacon, but its wakeup depends only + on the the configured Listen Interval. @warning The function called once after initialization. @@ -2089,7 +2103,7 @@ NMI_API sint8 m2m_wifi_set_sleep_mode(uint8 PsTyp, uint8 BcastEn); /**@}*/ /** @defgroup WifiRequestSleepFn m2m_wifi_request_sleep * @ingroup WLANAPI - * Synchronous power save request function, which requests from the NMC1500 device to sleep in the mode previously set + * Synchronous power save request function, which requests from the NMC1500 device to sleep in the mode previously set * for a specific time. * This function should be used in the M2M_PS_MANUAL Power save mode (only). */ @@ -2097,9 +2111,9 @@ NMI_API sint8 m2m_wifi_set_sleep_mode(uint8 PsTyp, uint8 BcastEn); /*! @fn NMI_API sint8 m2m_wifi_request_sleep(uint32 u32SlpReqTime); @param [in] u32SlpReqTime - Request Sleep in ms + Request Sleep in ms @warning The function should be called in M2M_PS_MANUAL power save only. -@see tenuPowerSaveModes +@see tenuPowerSaveModes m2m_wifi_set_sleep_mode @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise. */ @@ -2112,7 +2126,7 @@ NMI_API sint8 m2m_wifi_request_sleep(uint32 u32SlpReqTime); /**@{*/ /*! @fn NMI_API uint8 m2m_wifi_get_sleep_mode(void); -@see tenuPowerSaveModes +@see tenuPowerSaveModes m2m_wifi_set_sleep_mode @return The current operating power saving mode. @@ -2127,7 +2141,7 @@ NMI_API uint8 m2m_wifi_get_sleep_mode(void); /**@{*/ /*! @fn NMI_API sint8 m2m_wifi_req_client_ctrl(uint8 cmd); -@brief +@brief @param [in] cmd Control command sent from PS Server to PS Client (command values defined by the application) @pre m2m_wifi_req_server_init should be called first @@ -2141,7 +2155,7 @@ NMI_API sint8 m2m_wifi_req_client_ctrl(uint8 cmd); /** @defgroup WifiReqServerInit m2m_wifi_req_server_init * @ingroup WLANAPI * Synchronous function to initialize the PS Server. - * The WINC1500 supports non secure communication with another WINC1500, + * The WINC1500 supports non secure communication with another WINC1500, * (SERVER/CLIENT) through one byte command (probe request and probe response) without any connection setup. * The server mode can't be used with any other modes (STA/P2P/AP) */ @@ -2162,12 +2176,12 @@ NMI_API sint8 m2m_wifi_req_server_init(uint8 ch); */ /**@{*/ /*! -@fn NMI_API sint8 m2m_wifi_set_device_name(uint8 *pu8DeviceName, uint8 u8DeviceNameLength); +@fn NMI_API sint8 m2m_wifi_set_device_name(uint8 *pu8DeviceName, uint8 u8DeviceNameLength); @param [in] pu8DeviceName Buffer holding the device name. @param [in] u8DeviceNameLength Length of the device name. Should not exceed the maximum device name's length M2M_DEVICE_NAME_MAX. -@warning The function called once after initialization. +@warning The function called once after initialization. @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise. */ NMI_API sint8 m2m_wifi_set_device_name(uint8 *pu8DeviceName, uint8 u8DeviceNameLength); @@ -2175,7 +2189,7 @@ NMI_API sint8 m2m_wifi_set_device_name(uint8 *pu8DeviceName, uint8 u8DeviceNameL /** @defgroup WifiSetLsnIntFn m2m_wifi_set_lsn_int * @ingroup WLANAPI * Synchronous function for setting the wi-fi listen interval for power save operation. It is represented in units -* of AP Beacon periods. +* of AP Beacon periods. */ /**@{*/ /*! @@ -2184,7 +2198,7 @@ NMI_API sint8 m2m_wifi_set_device_name(uint8 *pu8DeviceName, uint8 u8DeviceNameL @param [in] pstrM2mLsnInt Structure holding the listen interval configurations. @pre Function m2m_wifi_set_sleep_mode shall be called first -@warning The function should be called once after initialization. +@warning The function should be called once after initialization. @see tstrM2mLsnInt m2m_wifi_set_sleep_mode @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise. @@ -2199,7 +2213,7 @@ NMI_API sint8 m2m_wifi_set_lsn_int(tstrM2mLsnInt *pstrM2mLsnInt); * The monitoring callback function must be implemented before starting the monitoring mode, in-order to handle the packets received. * Registering of the implemented callback function is through the callback pointer @ref tpfAppMonCb in the @ref tstrWifiInitParam structure. * passed to @ref m2m_wifi_init function at initialization. - * + * */ /**@{*/ /*! @@ -2207,8 +2221,8 @@ NMI_API sint8 m2m_wifi_set_lsn_int(tstrM2mLsnInt *pstrM2mLsnInt); * @param [in] pstrMtrCtrl * Pointer to @ref tstrM2MWifiMonitorModeCtrl structure holding the Filtering parameters. * @param [in] pu8PayloadBuffer - * Pointer to a Buffer allocated by the application. The buffer SHALL hold the Data field of - * the WIFI RX Packet (Or a part from it). If it is set to NULL, the WIFI data payload will + * Pointer to a Buffer allocated by the application. The buffer SHALL hold the Data field of + * the WIFI RX Packet (Or a part from it). If it is set to NULL, the WIFI data payload will * be discarded by the monitoring driver. * @param [in] u16BufferSize * The total size of the pu8PayloadBuffer in bytes. @@ -2217,29 +2231,29 @@ NMI_API sint8 m2m_wifi_set_lsn_int(tstrM2mLsnInt *pstrM2mLsnInt); * in reading specific information from the received packet. It must assign the offset to the starting * position of it relative to the DATA payload start.\n * \e Example, \e if \e the \e SSID \e is \e needed \e to \e be \e read \e from \e a \e PROBE \e REQ \e packet, \e the \e u16Offset \e MUST \e be \e set \e to \e 0. - * @warning This mode available as sniffer ONLY, you can not be connected in any modes (Station, Access Point, or P2P).\n + * @warning This mode available as sniffer ONLY, you can not be connected in any modes (Station, Access Point, or P2P).\n * @see tstrM2MWifiMonitorModeCtrl tstrM2MWifiRxPacketInfo tstrWifiInitParam tenuM2mScanCh - m2m_wifi_disable_monitoring_mode + m2m_wifi_disable_monitoring_mode * @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise. *\section Example * The example demonstrates the main function where-by the monitoring enable function is called after the initialization of the driver and the packets are * handled in the callback function. * @code - + #include "m2m_wifi.h" #include "m2m_types.h" - //Declare receive buffer + //Declare receive buffer uint8 gmgmt[1600]; - + //Callback functions void wifi_cb(uint8 u8WiFiEvent, void * pvMsg) { - ; + ; } void wifi_monitoring_cb(tstrM2MWifiRxPacketInfo *pstrWifiRxPacket, uint8 *pu8Payload, uint16 u16PayloadSize) { @@ -2253,16 +2267,16 @@ NMI_API sint8 m2m_wifi_set_lsn_int(tstrM2mLsnInt *pstrM2mLsnInt); } } } - + int main() { - //Register wifi_monitoring_cb + //Register wifi_monitoring_cb tstrWifiInitParam param; param.pfAppWifiCb = wifi_cb; param.pfAppMonCb = wifi_monitoring_cb; - + nm_bsp_init(); - + if(!m2m_wifi_init(¶m)) { //Enable Monitor Mode with filter to receive all data frames on channel 1 tstrM2MWifiMonitorModeCtrl strMonitorCtrl = {0}; @@ -2270,7 +2284,7 @@ NMI_API sint8 m2m_wifi_set_lsn_int(tstrM2mLsnInt *pstrM2mLsnInt); strMonitorCtrl.u8FrameType = DATA_BASICTYPE; strMonitorCtrl.u8FrameSubtype = M2M_WIFI_FRAME_SUB_TYPE_ANY; //Receive any subtype of data frame m2m_wifi_enable_monitoring_mode(&strMonitorCtrl, gmgmt, sizeof(gmgmt), 0); - + while(1) { m2m_wifi_handle_events(NULL); } @@ -2279,7 +2293,7 @@ NMI_API sint8 m2m_wifi_set_lsn_int(tstrM2mLsnInt *pstrM2mLsnInt); } * @endcode */ -NMI_API sint8 m2m_wifi_enable_monitoring_mode(tstrM2MWifiMonitorModeCtrl *pstrMtrCtrl, uint8 *pu8PayloadBuffer, +NMI_API sint8 m2m_wifi_enable_monitoring_mode(tstrM2MWifiMonitorModeCtrl *pstrMtrCtrl, uint8 *pu8PayloadBuffer, uint16 u16BufferSize, uint16 u16DataOffset); /**@}*/ /** @defgroup WifiDisableMonitorModeFn m2m_wifi_disable_monitoring_mode @@ -2290,7 +2304,7 @@ NMI_API sint8 m2m_wifi_enable_monitoring_mode(tstrM2MWifiMonitorModeCtrl *pstrMt /**@{*/ /*! * @fn NMI_API sint8 m2m_wifi_disable_monitoring_mode(void); - * @see m2m_wifi_enable_monitoring_mode + * @see m2m_wifi_enable_monitoring_mode * @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise. */ NMI_API sint8 m2m_wifi_disable_monitoring_mode(void); @@ -2302,17 +2316,17 @@ NMI_API sint8 m2m_wifi_disable_monitoring_mode(void); /**@{*/ /*! * @fn NMI_API sint8 m2m_wifi_send_wlan_pkt(uint8 *, uint16, uint16); - + * @param [in] pu8WlanPacket * Pointer to a buffer holding the whole WIFI frame. * @param [in] u16WlanHeaderLength * The size of the WIFI packet header ONLY. * @param [in] u16WlanPktSize - * The size of the whole bytes in packet. + * The size of the whole bytes in packet. * @see m2m_wifi_enable_monitoring_mode m2m_wifi_disable_monitoring_mode * @pre Enable Monitoring mode first using @ref m2m_wifi_enable_monitoring_mode - * @warning This function available in monitoring mode ONLY.\n + * @warning This function available in monitoring mode ONLY.\n * @note Packets are user's responsibility. * @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise. */ @@ -2320,8 +2334,8 @@ NMI_API sint8 m2m_wifi_send_wlan_pkt(uint8 *pu8WlanPacket, uint16 u16WlanHeaderL /**@}*/ /** @defgroup WifiSendEthernetPktFn m2m_wifi_send_ethernet_pkt * @ingroup WLANAPI - * Synchronous function to transmit an Ethernet packet. Transmit a packet directly in bypass mode where the TCP/IP stack is disabled and the implementation of this packet is left to the application developer. - * The Ethernet packet composition is left to the application developer. + * Synchronous function to transmit an Ethernet packet. Transmit a packet directly in bypass mode where the TCP/IP stack is disabled and the implementation of this packet is left to the application developer. + * The Ethernet packet composition is left to the application developer. */ /**@{*/ /*! @@ -2329,8 +2343,8 @@ NMI_API sint8 m2m_wifi_send_wlan_pkt(uint8 *pu8WlanPacket, uint16 u16WlanHeaderL * @param [in] pu8Packet * Pointer to a buffer holding the whole Ethernet frame. * @param [in] u16PacketSize - * The size of the whole bytes in packet. - * @attention This function available in Bypass mode ONLY. Make sure that firmware version built with macro \ref ETH_MODE.\n + * The size of the whole bytes in packet. + * @attention This function available in Bypass mode ONLY. Make sure that firmware version built with macro \ref ETH_MODE.\n * @note Packets are the user's responsibility. * @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise. @@ -2345,7 +2359,7 @@ NMI_API sint8 m2m_wifi_send_ethernet_pkt(uint8* pu8Packet,uint16 u16PacketSize); * The UTC is important for checking the expiration date of X509 certificates used while establishing * TLS (Transport Layer Security) connections. * It is highly recommended to use it if there is no other means to get the UTC time. If there is a RTC - * on the host MCU, the SNTP could be disabled and the host should set the system time to the firmware + * on the host MCU, the SNTP could be disabled and the host should set the system time to the firmware * using the @ref m2m_wifi_set_system_time function. */ /**@{*/ @@ -2354,8 +2368,8 @@ NMI_API sint8 m2m_wifi_send_ethernet_pkt(uint8* pu8Packet,uint16 u16PacketSize); * @param [in] bEnable * Enabling/Disabling flag * '0' :disable SNTP - * '1' :enable SNTP - * @see m2m_wifi_set_sytem_time + * '1' :enable SNTP + * @see m2m_wifi_set_sytem_time * @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise. */ NMI_API sint8 m2m_wifi_enable_sntp(uint8 bEnable); @@ -2367,9 +2381,9 @@ NMI_API sint8 m2m_wifi_enable_sntp(uint8 bEnable); */ /**@{*/ /*! - * @fn NMI_API sint8 m2m_wifi_set_sytem_time(uint32); - * @param [in] u32RTCSeconds - * UTC value in seconds. + * @fn NMI_API sint8 m2m_wifi_set_sytem_time(uint32); + * @param [in] u32UTCSeconds + * Seconds elapsed since January 1, 1900 (NTP Timestamp). * @see m2m_wifi_enable_sntp tstrSystemTime * @note If there is an RTC on the host MCU, the SNTP could be disabled and the host should set the system time to the firmware @@ -2495,13 +2509,13 @@ sint8 m2m_wifi_enable_firmware_logs(uint8 u8Enable); */ sint8 m2m_wifi_set_battery_voltage(uint16 u16BattVoltx100); /** -* @fn m2m_wifi_get_firmware_version(tstrM2mRev* M2mRev) +* @fn m2m_wifi_get_firmware_version(tstrM2mRev* pstrRev) * @brief Get Firmware version info * @param [out] M2mRev * pointer holds address of structure "tstrM2mRev" that contains the firmware version parameters * @version 1.0 */ -sint8 m2m_wifi_get_firmware_version(tstrM2mRev *M2mRev); +sint8 m2m_wifi_get_firmware_version(tstrM2mRev *pstrRev); /**@}*/ #ifdef ETH_MODE /** @defgroup WifiEnableMacMcastFn m2m_wifi_enable_mac_mcast @@ -2526,12 +2540,12 @@ NMI_API sint8 m2m_wifi_enable_mac_mcast(uint8* pu8MulticastMacAddress, uint8 u8A /**@}*/ /** @defgroup SetReceiveBufferFn m2m_wifi_set_receive_buffer * @ingroup WLANAPI - * Synchronous function for setting or changing the receiver buffer's length. + * Synchronous function for setting or changing the receiver buffer's length. * Changes are made according to the developer option in bypass mode and this function should be called in the receive callback handling. *@{*/ /*! * @fn NMI_API sint8 m2m_wifi_set_receive_buffer(void *, uint16); - + * @param [in] pvBuffer * Pointer to Buffer to receive data. * NULL pointer causes a negative error @ref M2M_ERR_FAIL. @@ -2539,15 +2553,24 @@ NMI_API sint8 m2m_wifi_enable_mac_mcast(uint8* pu8MulticastMacAddress, uint8 u8A * @param [in] u16BufferLen * Length of data to be received. Maximum length of data should not exceed the size defined by TCP/IP * defined as @ref SOCKET_BUFFER_MAX_LENGTH - * - * @warning This function is available in the bypass mode ONLY. Make sure that firmware version is built with macro @ref ETH_MODE.\n + * + * @warning This function is available in the bypass mode ONLY. Make sure that firmware version is built with macro @ref ETH_MODE.\n * @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise. */ NMI_API sint8 m2m_wifi_set_receive_buffer(void* pvBuffer,uint16 u16BufferLen); /**@}*/ -#endif - - +#endif /* ETH_MODE */ +/*! + * @fn sint8 m2m_wifi_prng_get_random_bytes(uint8 * pu8PRNGBuff,uint16 u16PRNGSize) + * @param [in] pu8PrngBuff + * Pointer to Buffer to receive data. + * Size greater than the maximum specified (@ref M2M_BUFFER_MAX_SIZE - sizeof(tstrPrng)) + * causes a negative error @ref M2M_ERR_FAIL. + * @param [in] u16PrngSize + request size in bytes + * @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise. + */ +sint8 m2m_wifi_prng_get_random_bytes(uint8 * pu8PrngBuff,uint16 u16PrngSize); #ifdef __cplusplus } #endif diff --git a/src/winc1500/include/driver/include/nmasic.h b/src/winc1500/include/driver/include/nmasic.h index 70aaced5d..ef0b56e28 100644 --- a/src/winc1500/include/driver/include/nmasic.h +++ b/src/winc1500/include/driver/include/nmasic.h @@ -47,11 +47,13 @@ #define NMI_CHIPID (NMI_PERIPH_REG_BASE) #define rNMI_GP_REG_0 (0x149c) #define rNMI_GP_REG_1 (0x14A0) +#define rNMI_GP_REG_2 (0xc0008) #define rNMI_GLB_RESET (0x1400) #define rNMI_BOOT_RESET_MUX (0x1118) #define NMI_STATE_REG (0x108c) #define BOOTROM_REG (0xc000c) #define NMI_REV_REG (0x207ac) /*Also, Used to load ATE firmware from SPI Flash and to ensure that it is running too*/ +#define NMI_REV_REG_ATE (0x1048) /*Revision info register in case of ATE FW*/ #define M2M_WAIT_FOR_HOST_REG (0x207bc) #define M2M_FINISH_INIT_STATE 0x02532636UL #define M2M_FINISH_BOOT_ROM 0x10add09eUL @@ -77,7 +79,12 @@ #define rHAVE_EXT_PA_INV_TX_RX (NBIT4) #define rHAVE_LEGACY_RF_SETTINGS (NBIT5) #define rHAVE_LOGS_DISABLED_BIT (NBIT6) +#define rHAVE_ETHERNET_MODE_BIT (NBIT7) +typedef struct{ + uint32 u32Mac_efuse_mib; + uint32 u32Firmware_Ota_rev; +}tstrGpRegs; #ifdef __cplusplus extern "C" { diff --git a/src/winc1500/include/driver/include/nmdrv.h b/src/winc1500/include/driver/include/nmdrv.h index a32cd001f..fadbedb64 100644 --- a/src/winc1500/include/driver/include/nmdrv.h +++ b/src/winc1500/include/driver/include/nmdrv.h @@ -45,11 +45,11 @@ #include "common/include/nm_common.h" /** -* @struct tstrM2mWifiGetRevision -* @brief Structure holding firmware version parameters -* @sa M2M_WIFI_AUTH_WEB, M2M_WIFI_AUTH_WPA, M2M_WIFI_AUTH_WPA2 +* @struct tstrM2mRev +* @brief Structure holding firmware version parameters and build date/time */ typedef struct { + uint32 u32Chipid; /* HW revision which will be basically the chip ID */ uint8 u8FirmwareMajor; /* Version Major Number which represents the official release base */ uint8 u8FirmwareMinor; /* Version Minor Number which represents the engineering release base */ uint8 u8FirmwarePatch; /* Version pathc Number which represents the pathces release base */ @@ -58,7 +58,7 @@ typedef struct { uint8 u8DriverPatch; /* Version Patch Number which represents the pathces release base */ uint8 BuildDate[sizeof(__DATE__)]; uint8 BuildTime[sizeof(__TIME__)]; - uint32 u32Chipid; /* HW revision which will be basically the chip ID */ + uint8 _PAD8_; } tstrM2mRev; #ifdef __cplusplus @@ -72,6 +72,23 @@ typedef struct { * @version 1.0 */ sint8 nm_get_firmware_info(tstrM2mRev* M2mRev); +/** +* @fn nm_get_firmware_full_info(tstrM2mRev* pstrRev) +* @brief Get Firmware version info +* @param [out] M2mRev +* pointer holds address of structure "tstrM2mRev" that contains the firmware version parameters +* @version 1.0 +*/ +sint8 nm_get_firmware_full_info(tstrM2mRev* pstrRev); +/** +* @fn nm_get_ota_firmware_info(tstrM2mRev* pstrRev) +* @brief Get Firmware version info +* @param [out] M2mRev +* pointer holds address of structure "tstrM2mRev" that contains the firmware version parameters + +* @version 1.0 +*/ +sint8 nm_get_ota_firmware_info(tstrM2mRev* pstrRev); /* * @fn nm_drv_init * @brief Initialize NMC1000 driver diff --git a/src/winc1500/include/socket/include/m2m_socket_host_if.h b/src/winc1500/include/socket/include/m2m_socket_host_if.h index 122327a71..c0d70494e 100644 --- a/src/winc1500/include/socket/include/m2m_socket_host_if.h +++ b/src/winc1500/include/socket/include/m2m_socket_host_if.h @@ -63,10 +63,10 @@ MACROS *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ #ifdef _FIRMWARE_ -#define HOSTNAME_MAX_SIZE (64) +#define HOSTNAME_MAX_SIZE (64) #endif -#define SSL_MAX_OPT_LEN HOSTNAME_MAX_SIZE +#define SSL_MAX_OPT_LEN HOSTNAME_MAX_SIZE @@ -76,7 +76,7 @@ MACROS */ -#define SOCKET_CMD_BIND 0x41 +#define SOCKET_CMD_BIND 0x41 /*!< Socket Binding command value. */ @@ -94,19 +94,19 @@ MACROS */ -#define SOCKET_CMD_CONNECT 0x44 +#define SOCKET_CMD_CONNECT 0x44 /*!< Socket Connecting command value. */ -#define SOCKET_CMD_SEND 0x45 +#define SOCKET_CMD_SEND 0x45 /*!< Socket send command value. */ -#define SOCKET_CMD_RECV 0x46 +#define SOCKET_CMD_RECV 0x46 /*!< Socket Recieve command value. */ @@ -118,7 +118,7 @@ MACROS */ -#define SOCKET_CMD_RECVFROM 0x48 +#define SOCKET_CMD_RECVFROM 0x48 /*!< Socket RecieveFrom command value. */ @@ -130,25 +130,25 @@ MACROS */ -#define SOCKET_CMD_DNS_RESOLVE 0x4A +#define SOCKET_CMD_DNS_RESOLVE 0x4A /*!< Socket DNS Resolve command value. */ -#define SOCKET_CMD_SSL_CONNECT 0x4B +#define SOCKET_CMD_SSL_CONNECT 0x4B /*!< SSL-Socket Connect command value. */ -#define SOCKET_CMD_SSL_SEND 0x4C +#define SOCKET_CMD_SSL_SEND 0x4C /*!< SSL-Socket Send command value. */ -#define SOCKET_CMD_SSL_RECV 0x4D +#define SOCKET_CMD_SSL_RECV 0x4D /*!< SSL-Socket Recieve command value. */ @@ -171,12 +171,12 @@ MACROS */ -#define SOCKET_CMD_SSL_SET_SOCK_OPT 0x51 +#define SOCKET_CMD_SSL_SET_SOCK_OPT 0x51 #define SOCKET_CMD_PING 0x52 - +#define SOCKET_CMD_SSL_SET_CS_LIST 0x53 #define PING_ERR_SUCCESS 0 @@ -297,7 +297,11 @@ typedef struct{ typedef struct{ SOCKET sock; sint8 s8Error; - uint16 u16SessionID; + uint16 u16AppDataOffset; + /*!< + In further packet send requests the host interface should put the user application + data at this offset in the allocated shared data packet. + */ }tstrConnectReply; @@ -309,7 +313,7 @@ typedef struct{ uint8 u8Void; uint16 u16DataSize; tstrSockAddr strAddr; - uint16 u16SessionID; + uint16 u16SessionID; uint16 u16Void; }tstrSendCmd; @@ -405,6 +409,11 @@ typedef struct{ uint8 __PAD24__[3]; }tstrPingReply; + +typedef struct{ + uint32 u32CsBMP; +}tstrSslSetActiveCsList; + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/winc1500/include/socket/include/socket.h b/src/winc1500/include/socket/include/socket.h index 74903dc94..231822c01 100644 --- a/src/winc1500/include/socket/include/socket.h +++ b/src/winc1500/include/socket/include/socket.h @@ -46,6 +46,13 @@ extern "C" { #endif +/** \defgroup SocketHeader Socket + * BSD alike socket interface beftween the host layer and the network + * protocol stacks in the firmware. + * These functions are used by the host application to send or receive + * packets and to do other socket operations. + */ + /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* INCLUDES *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ @@ -55,35 +62,40 @@ INCLUDES /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* MACROS *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ -/** @defgroup SocketDefines Defines +/** + * @defgroup SocketDefines Defines * @ingroup SocketHeader + */ + +/** @defgroup IPDefines TCP/IP Defines + * @ingroup SocketDefines * The following list of macros are used to define constants used throughout the socket layer. * @{ */ #define HOSTNAME_MAX_SIZE 64 -/*!< - Maximum allowed size for a host domain name passed to the function gethostbyname @ref gethostbyname. - command value. Used with the setsocketopt function. +/*!< + Maximum allowed size for a host domain name passed to the function gethostbyname @ref gethostbyname. + command value. Used with the setsockopt function. */ - + #define SOCKET_BUFFER_MAX_LENGTH 1400 -/*!< - Maximum allowed size for a socket data buffer. Used with @ref send socket - function to ensure that the buffer sent is within the allowed range. +/*!< + Maximum allowed size for a socket data buffer. Used with @ref send socket + function to ensure that the buffer sent is within the allowed range. */ #define AF_INET 2 -/*!< +/*!< The AF_INET is the address family used for IPv4. An IPv4 transport address is specified with the @ref sockaddr_in structure. - (It is the only supported type for the current implementation.) + (It is the only supported type for the current implementation.) */ #define SOCK_STREAM 1 -/*!< +/*!< One of the IPv4 supported socket types for reliable connection-oriented stream connection. - Passed to the @ref socket function for the socket creation operation. + Passed to the @ref socket function for the socket creation operation. */ #define SOCK_DGRAM 2 @@ -94,8 +106,8 @@ MACROS #define SOCKET_FLAGS_SSL 0x01 -/*!< - This flag shall be passed to the socket API for SSL session. +/*!< + This flag shall be passed to the socket API for SSL session. */ #define TCP_SOCK_MAX (7) @@ -113,49 +125,56 @@ MACROS Maximum number of Sockets. */ -#define SOL_SOCKET 1 +#define SOL_SOCKET 1 /*!< Socket option. - Used with the @ref setsocketopt function + Used with the @ref setsockopt function */ -#define SO_SET_UDP_SEND_CALLBACK 0x00 -/*!< - Socket option used by the application to enable/disable - the use of UDP send callbacks. - Used with the @ref setsocketopt function. -*/ - -#define IP_ADD_MEMBERSHIP 0x01 -/*!< - Set Socket Option Add Membership command value. - Used with the @ref setsocketopt function. -*/ - - -#define IP_DROP_MEMBERSHIP 0x02 -/*!< - Set Socket Option Drop Membership command value. - Used with the @ref setsocketopt function. -*/ - -//@} - - -/** @defgroup SSLSocketOptions Defines - * @ingroup SocketHeader - * The following list of macros are used to define SSL Socket options. - * @{ - */ - -#define SOL_SSL_SOCKET 2 +#define SOL_SSL_SOCKET 2 /*!< SSL Socket option level. - Used with the @ref setsocketopt function + Used with the @ref setsockopt function +*/ + +#define SO_SET_UDP_SEND_CALLBACK 0x00 +/*!< + Socket option used by the application to enable/disable + the use of UDP send callbacks. + Used with the @ref setsockopt function. +*/ + +#define IP_ADD_MEMBERSHIP 0x01 +/*!< + Set Socket Option Add Membership command value. + Used with the @ref setsockopt function. */ -#define SO_SSL_BYPASS_X509_VERIF 0x01 +#define IP_DROP_MEMBERSHIP 0x02 +/*!< + Set Socket Option Drop Membership command value. + Used with the @ref setsockopt function. +*/ + //@} + + + +/** + * @defgroup TLSDefines TLS Defines + * @ingroup SocketDefines + */ + + + +/** @defgroup SSLSocketOptions TLS Socket Options + * @ingroup TLSDefines + * The following list of macros are used to define SSL Socket options. + * @{ + * @sa setsockopt + */ + +#define SO_SSL_BYPASS_X509_VERIF 0x01 /*!< Allow an opened SSL socket to bypass the X509 certificate verification process. @@ -167,15 +186,85 @@ MACROS */ -#define SO_SSL_SNI 0x02 +#define SO_SSL_SNI 0x02 /*!< Set the Server Name Indicator (SNI) for an SSL socket. The SNI is a NULL terminated string containing the server name assocated with the connection. It must not exceed the size of HOSTNAME_MAX_SIZE. */ + + +#define SO_SSL_ENABLE_SESSION_CACHING 0x03 +/*!< + This option allow the TLS to cache the session information for fast + TLS session establishment in future connections using the + TLS Protocol session resume features. +*/ + +//@} + + + +/** @defgroup SSLCipherSuiteConfiguration TLS Cipher Suite Configurations + * @ingroup TLSDefines + * The following list of macros are used to define SSL Ciphersuite Configuration. + * @sa sslSetActiveCipherSuites + * @{ + */ + +#define SSL_ENABLE_ALL_SUITES 0xfffffffful +/*!< + Enable all possible supported cipher suites. +*/ + +#define SSL_ENABLE_RSA_SHA_SUITES 0x01 +/*!< + Enable RSA Hmac_SHA based Ciphersuites. For example, + TLS_RSA_WITH_AES_128_CBC_SHA +*/ + + +#define SSL_ENABLE_RSA_SHA256_SUITES 0x02 +/*!< + Enable RSA Hmac_SHA256 based Ciphersuites. For example, + TLS_RSA_WITH_AES_128_CBC_SHA256 +*/ + + +#define SSL_ENABLE_DHE_SHA_SUITES 0x04 +/*!< + Enable DHE Hmac_SHA based Ciphersuites. For example, + TLS_DHE_RSA_WITH_AES_128_CBC_SHA +*/ + + +#define SSL_ENABLE_DHE_SHA256_SUITES 0x08 +/*!< + Enable DHE Hmac_SHA256 based Ciphersuites. For example, + TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 +*/ + + +#define SSL_ENABLE_RSA_GCM_SUITES 0x10 +/*!< + Enable RSA AEAD based Ciphersuites. For example, + TLS_RSA_WITH_AES_128_GCM_SHA256 +*/ + + +#define SSL_ENABLE_DHE_GCM_SUITES 0x20 +/*!< + Enable DHE AEAD based Ciphersuites. For example, + TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 +*/ + //@} - + + + + + /************** Socket Errors **************/ @@ -185,82 +274,83 @@ Socket Errors * Errors are listed in numerical order with the error macro name. * @{ */ -#define SOCK_ERR_NO_ERROR 0 +#define SOCK_ERR_NO_ERROR 0 /*!< Successfull socket operation */ -#define SOCK_ERR_INVALID_ADDRESS -1 + +#define SOCK_ERR_INVALID_ADDRESS -1 /*!< - Socket address is invalid. The socket operation cannot be completed successfully without specifying a specific address + Socket address is invalid. The socket operation cannot be completed successfully without specifying a specific address For example: bind is called without specifying a port number */ -#define SOCK_ERR_ADDR_ALREADY_IN_USE -2 +#define SOCK_ERR_ADDR_ALREADY_IN_USE -2 /*!< - Socket operation cannot bind on the given address. With socket operations, only one IP address per socket is permitted. - Any attempt for a new socket to bind with an IP address already bound to another open socket, - will return the following error code. States that bind operation failed. + Socket operation cannot bind on the given address. With socket operations, only one IP address per socket is permitted. + Any attempt for a new socket to bind with an IP address already bound to another open socket, + will return the following error code. States that bind operation failed. */ -#define SOCK_ERR_MAX_TCP_SOCK -3 +#define SOCK_ERR_MAX_TCP_SOCK -3 /*!< - Exceeded the maximum number of TCP sockets. A maximum number of TCP sockets opened simultaneously is defined through TCP_SOCK_MAX. - It is not permitted to exceed that number at socket creation. Identifies that @ref socket operation failed. + Exceeded the maximum number of TCP sockets. A maximum number of TCP sockets opened simultaneously is defined through TCP_SOCK_MAX. + It is not permitted to exceed that number at socket creation. Identifies that @ref socket operation failed. */ -#define SOCK_ERR_MAX_UDP_SOCK -4 +#define SOCK_ERR_MAX_UDP_SOCK -4 /*!< - Exceeded the maximum number of UDP sockets. A maximum number of UDP sockets opened simultaneously is defined through UDP_SOCK_MAX. + Exceeded the maximum number of UDP sockets. A maximum number of UDP sockets opened simultaneously is defined through UDP_SOCK_MAX. It is not permitted to exceed that number at socket creation. Identifies that @ref socket operation failed */ -#define SOCK_ERR_INVALID_ARG -6 +#define SOCK_ERR_INVALID_ARG -6 /*!< - An invalid argument is passed to a function. + An invalid arguement is passed to a function. */ -#define SOCK_ERR_MAX_LISTEN_SOCK -7 +#define SOCK_ERR_MAX_LISTEN_SOCK -7 /*!< Exceeded the maximum number of TCP passive listening sockets. - Identifies Identifies that @ref listen operation failed. + Identifies Identifies that @ref listen operation failed. */ -#define SOCK_ERR_INVALID -9 +#define SOCK_ERR_INVALID -9 /*!< The requested socket operation is not valid in the - current socket state. + current socket state. For example: @ref accept is called on a TCP socket before @ref bind or @ref listen. */ -#define SOCK_ERR_ADDR_IS_REQUIRED -11 +#define SOCK_ERR_ADDR_IS_REQUIRED -11 /*!< Destination address is required. Failure to provide the socket address required for the socket operation to be completed. - It is generated as an error to the @ref sendto function when the address required to send the data to is not known. + It is generated as an error to the @ref sendto function when the address required to send the data to is not known. */ -#define SOCK_ERR_CONN_ABORTED -12 +#define SOCK_ERR_CONN_ABORTED -12 /*!< The socket is closed by the peer. The local socket is closed also. */ -#define SOCK_ERR_TIMEOUT -13 +#define SOCK_ERR_TIMEOUT -13 /*!< - The socket pending operation has timedout. + The socket pending operation has timedout. */ -#define SOCK_ERR_BUFFER_FULL -14 +#define SOCK_ERR_BUFFER_FULL -14 /*!< No buffer space available to be used for the requested socket operation. */ @@ -303,6 +393,10 @@ Socket Errors /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* DATA TYPES *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ +/** @defgroup SocketEnums Enumeration-Typedef + * @ingroup SocketHeader + * Specific Enumuration-typdefs used for socket operations + * @{ */ /*! @typedef \ @@ -316,10 +410,6 @@ DATA TYPES typedef sint8 SOCKET; -/** @defgroup SocketEnums Enumeration-Typedef - * @ingroup SocketHeader - * Specific Enumuration-typdefs used for socket operations - * @{ */ /*! @struct \ @@ -353,11 +443,11 @@ typedef struct{ */ struct sockaddr{ uint16 sa_family; - /*!< + /*!< Socket address family. */ uint8 sa_data[14]; - /*!< + /*!< Maximum size of all the different socket address structures. */ }; @@ -370,7 +460,6 @@ Socket address family. @brief Socket address structure for IPV4 addresses. Used to specify socket address infomation to which to connect to. Can be cast to @ref sockaddr structure. - */ struct sockaddr_in{ uint16 sin_family; @@ -381,7 +470,7 @@ struct sockaddr_in{ */ uint16 sin_port; /*!< - Port number of the socket. + Port number of the socket. Network sockets are identified by a pair of IP addresses and port number. It must be set in the Network Byte Order format , @ref _htons (e.g. _htons(80)). Can NOT have zero value. @@ -389,7 +478,7 @@ struct sockaddr_in{ in_addr sin_addr; /*!< IP Address of the socket. - The IP address is of type @ref in_addr structure. + The IP address is of type @ref in_addr structure. Can be set to "0" to accept any IP address for server operation. non zero otherwise. */ uint8 sin_zero[8]; @@ -408,10 +497,10 @@ struct sockaddr_in{ @brief Asynchronous APIs, make use of callback functions, in-order to return back the results once the corresponding socket operation is completed. - Hence resuming the normal execution of the application code while the socket operation returns the results. + Hence resuming the normal execution of the application code while the socket operation returns the results. Callback functions expect event messages to be passed in, in-order to identify the operation they're returning the results for. The following enum identifes the type of events that are received in the callback function. - + Application Use: In order for application developers to handle the pending events from the network controller through the callback functions. A function call must be made to the function @ref m2m_wifi_handle_events at least once for each socket operation. @@ -423,7 +512,7 @@ struct sockaddr_in{ connect send recv - + */ typedef enum{ SOCKET_MSG_BIND = 1, @@ -475,13 +564,13 @@ typedef enum{ This structure together with the event @ref SOCKET_MSG_BIND are passed in paramters to the callback function. @see bind - + */ typedef struct{ sint8 status; /*!< - The result of the bind operation. - Holding a value of ZERO for a successful bind or otherwise a negative + The result of the bind operation. + Holding a value of ZERO for a successful bind or otherwise a negative error code corresponding to the type of error. */ }tstrSocketBindMsg; @@ -489,7 +578,7 @@ typedef struct{ /*! @struct \ - tstrSocketListenMsg + tstrSocketListenMsg @brief Socket listen status. @@ -501,7 +590,7 @@ typedef struct{ typedef struct{ sint8 status; /*!< - Holding a value of ZERO for a successful listen or otherwise a negative + Holding a value of ZERO for a successful listen or otherwise a negative error code corresponding to the type of error. */ }tstrSocketListenMsg; @@ -515,12 +604,12 @@ typedef struct{ @brief Socket accept status. Socket accept information is returned through this structure in response to the asynchronous call to the @ref accept function. - This structure together with the event @ref SOCKET_MSG_ACCEPT are passed-in parameters to the callback function. + This structure together with the event @ref SOCKET_MSG_ACCEPT are passed-in parameters to the callback function. */ typedef struct{ SOCKET sock; /*!< - On a successful @ref accept operation, the return information is the socket ID for the accepted connection with the remote peer. + On a successful @ref accept operation, the return information is the socket ID for the accepted connection with the remote peer. Otherwise a negative error code is returned to indicate failure of the accept operation. */ struct sockaddr_in strAddr; @@ -546,8 +635,8 @@ typedef struct{ */ sint8 s8Error; /*!< - Connect error code. - Holding a value of ZERO for a successful connect or otherwise a negative + Connect error code. + Holding a value of ZERO for a successful connect or otherwise a negative error code corresponding to the type of error. */ }tstrSocketConnectMsg; @@ -561,8 +650,8 @@ typedef struct{ Socket receive information is returned through this structure in response to the asynchronous call to the recv or recvfrom socket functions. This structure together with the events @ref SOCKET_MSG_RECV or @ref SOCKET_MSG_RECVFROM are passed-in parameters to the callback function. -@remark - In case the received data from the remote peer is larger than the USER buffer size defined during the asynchronous call to the @ref recv function, the data is +@remark + In case the received data from the remote peer is larger than the USER buffer size defined during the asynchronous call to the @ref recv function, the data is delivered to the user in a number of consecutive chunks according to the USER Buffer size. a negative or zero buffer size indicates an error with the following code: @ref SOCK_ERR_NO_ERROR : Socket connection closed @@ -590,21 +679,20 @@ typedef struct{ }tstrSocketRecvMsg; - /*! @typedef \ tpfAppSocketCb @brief The main socket application callback function. Applications register their main socket application callback through this function by calling @ref registerSocketCallback. - In response to events received, the following callback function is called to handle the corresponding asynchronous function called. Example: @ref bind, @ref connect,...etc. + In response to events received, the following callback function is called to handle the corresponding asynchronous function called. Example: @ref bind, @ref connect,...etc. @param [in] sock Socket ID for the callback. - The socket callback function is called whenever a new event is recived in response + The socket callback function is called whenever a new event is recived in response to socket operations. - + @param [in] u8Msg Socket event type. Possible values are: - @ref SOCKET_MSG_BIND @@ -615,7 +703,7 @@ typedef struct{ - @ref SOCKET_MSG_SEND - @ref SOCKET_MSG_SENDTO - @ref SOCKET_MSG_RECVFROM - + @param [in] pvMsg Pointer to message structure. Existing types are: - tstrSocketBindMsg @@ -625,12 +713,12 @@ typedef struct{ - tstrSocketRecvMsg @see - tenuSocketCallbackMsgType + tenuSocketCallbackMsgType tstrSocketRecvMsg - tstrSocketConnectMsg + tstrSocketConnectMsg tstrSocketAcceptMsg tstrSocketListenMsg - tstrSocketBindMsg + tstrSocketBindMsg */ typedef void (*tpfAppSocketCb) (SOCKET sock, uint8 u8Msg, void * pvMsg); @@ -640,7 +728,7 @@ typedef void (*tpfAppSocketCb) (SOCKET sock, uint8 u8Msg, void * pvMsg); tpfAppResolveCb @brief - DNS resolution callback function. + DNS resolution callback function. Applications requiring DNS resolution should register their callback through this function by calling @ref registerSocketCallback. The following callback is triggered in response to asynchronous call to the @ref gethostbyname function (DNS Resolution callback). @@ -691,9 +779,9 @@ FUNCTION PROTOTYPES - Zero initializations to the global socket array (gastrSockets), which holds the list of TCP sockets. - Registers the socket (Host Interface)hif callback function through the call to the hif_register_cb function. This facilitates handling all of the socket related functions received through interrupts from the firmware. - + */ - /**@{*/ + /**@{*/ /*! @fn \ NMI_API void socketInit(void); @@ -702,9 +790,9 @@ FUNCTION PROTOTYPES @return void -@remarks +@remarks This initialization function must be invoked before any socket operation is performed. - No error codes from this initialization function since the socket array is statically allocated based in the maximum number of + No error codes from this initialization function since the socket array is statically allocated based in the maximum number of sockets @ref MAX_SOCKET based on the systems capibility. \section Example This example demonstrates the use of the socketinit for socket initialization for an mqtt chat application. @@ -716,19 +804,19 @@ This example demonstrates the use of the socketinit for socket initialization fo //Initialize the board. system_init(); - //Initialize the UART console. + //Initialize the UART console. configure_console(); // Initialize the BSP. nm_bsp_init(); - + ---------- - + // Initialize socket interface. socketInit(); registerSocketCallback(socket_event_handler, socket_resolve_handler); - // Connect to router. + // Connect to router. m2m_wifi_connect((char *)MAIN_WLAN_SSID, sizeof(MAIN_WLAN_SSID), MAIN_WLAN_AUTH, (char *)MAIN_WLAN_PSK, M2M_WIFI_CH_ALL); @@ -737,7 +825,7 @@ This example demonstrates the use of the socketinit for socket initialization fo NMI_API void socketInit(void); /*! -@fn \ +@fn \ NMI_API void socketDeinit(void); @brief Socket Layer De-initialization @@ -749,32 +837,32 @@ NMI_API void socketDeinit(void); /** @} */ /** @defgroup SocketCallbackFn registerSocketCallback * @ingroup SocketAPI - Register two callback functions one for asynchronous socket events and the other one for DNS callback registering function. + Register two callback functions one for asynchronous socket events and the other one for DNS callback registering function. The registered callback functions are used to retrieve information in response to the asynchronous socket functions called. */ - /**@{*/ + /**@{*/ /*! @fn \ NMI_API void registerSocketCallback(tpfAppSocketCb socket_cb, tpfAppResolveCb resolve_cb); - -@param [in] tpfAppSocketCb + +@param [in] tpfAppSocketCb Assignment of callback function to the global callback @ref tpfAppSocketCb gpfAppSocketCb. Delivers socket messages to the host application. In response to the asynchronous function calls, such as @ref bind @ref listen @ref accept @ref connect - -@param [in] tpfAppResolveCb - Assignment of callback function to the global callback @ref tpfAppResolveCb gpfAppResolveCb. - Used for DNS resolving functionalites. The DNS resolving technique is determined by the application + +@param [in] tpfAppResolveCb + Assignment of callback function to the global callback @ref tpfAppResolveCb gpfAppResolveCb. + Used for DNS resolving functionalites. The DNS resolving technique is determined by the application registering the callback. NULL is assigned when, DNS resolution is not required. - + @return void -@remarks +@remarks If any of the socket functionaities is not to be used, NULL is passed in as a parameter. It must be invoked after socketinit and before other socket layer operations. - + \section Example This example demonstrates the use of the registerSocketCallback to register a socket callback function with DNS resolution CB set to null for a simple UDP server example. @@ -786,9 +874,9 @@ NMI_API void socketDeinit(void); // Initialize the board system_init(); - //Initialize the UART console. + //Initialize the UART console. configure_console(); - + // Initialize the BSP. nm_bsp_init(); @@ -797,7 +885,7 @@ NMI_API void socketDeinit(void); addr.sin_port = _htons(MAIN_WIFI_M2M_SERVER_PORT); addr.sin_addr.s_addr = _htonl(MAIN_WIFI_M2M_SERVER_IP); - // Initialize Wi-Fi parameters structure. + // Initialize Wi-Fi parameters structure. memset((uint8_t *)¶m, 0, sizeof(tstrWifiInitParam)); // Initialize Wi-Fi driver with data and status callbacks. @@ -817,22 +905,21 @@ NMI_API void socketDeinit(void); m2m_wifi_connect((char *)MAIN_WLAN_SSID, sizeof(MAIN_WLAN_SSID), MAIN_WLAN_AUTH, (char *)MAIN_WLAN_PSK, M2M_WIFI_CH_ALL); \endcode */ - NMI_API void registerSocketCallback(tpfAppSocketCb socket_cb, tpfAppResolveCb resolve_cb); /** @} */ /** @defgroup SocketFn socket * @ingroup SocketAPI - * Synchronous socket allocation function based on the specified socket type. Created sockets are non-blocking and their possible types are either TCP or a UDP sockets. - * The maximum allowed number of TCP sockets is @ref TCP_SOCK_MAX sockets while the maximum number of UDP sockets that can be created simultaneously is @ref UDP_SOCK_MAX sockets. - * + * Synchronous socket allocation function based on the specified socket type. Created sockets are non-blocking and their possible types are either TCP or a UDP sockets. + * The maximum allowed number of TCP sockets is @ref TCP_SOCK_MAX sockets while the maximum number of UDP sockets that can be created simultaneously is @ref UDP_SOCK_MAX sockets. + * */ /**@{*/ /*! @fn \ NMI_API SOCKET socket(uint16 u16Domain, uint8 u8Type, uint8 u8Flags); - + @param [in] u16Domain Socket family. The only allowed value is AF_INET (IPv4.0) for TCP/UDP sockets. @@ -862,12 +949,12 @@ NMI_API void registerSocketCallback(tpfAppSocketCb socket_cb, tpfAppResolveCb re close setsockopt getsockopt - -@return + +@return On successful socket creation, a non-blocking socket type is created and a socket ID is returned In case of failure the function returns a negative value, identifying one of the socket error codes defined. - For example: @ref SOCK_ERR_INVALID for invalid argument or - @ref SOCK_ERR_MAX_TCP_SOCK if the number of TCP allocated sockets exceeds the number of available sockets. + For example: @ref SOCK_ERR_INVALID for invalid argument or + @ref SOCK_ERR_MAX_TCP_SOCK if the number of TCP allocated sockets exceeds the number of available sockets. @remarks The socket function must be called apriori any other related socket functions "e.g. send, recv, close ..etc" @@ -877,9 +964,9 @@ socket operations. Socket creation is dependent on the socket type. \subsection sub1 UDP example @code SOCKET UdpServerSocket = -1; - + UdpServerSocket = socket(AF_INET, SOCK_DGRAM, 0); - + @endcode \subsection sub2 TCP example @code @@ -892,27 +979,27 @@ NMI_API SOCKET WINC1500_EXPORT(socket)(uint16 u16Domain, uint8 u8Type, uint8 u8F /** @} */ /** @defgroup BindFn bind * @ingroup SocketAPI -* Asynchronous bind function associates the provided address and local port to the socket. -* The function can be used with both TCP and UDP sockets it's mandatory to call the @ref bind function before starting any UDP or TCP server operation. -* Upon socket bind completion, the application will receive a @ref SOCKET_MSG_BIND message in the socket callback. +* Asynchronous bind function associates the provided address and local port to the socket. +* The function can be used with both TCP and UDP sockets it's mandatory to call the @ref bind function before starting any UDP or TCP server operation. +* Upon socket bind completion, the application will receive a @ref SOCKET_MSG_BIND message in the socket callback. */ /**@{*/ /*! \fn \ NMI_API sint8 bind(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen); - + @param [in] sock Socket ID, must hold a non negative value. A negative value will return a socket error @ref SOCK_ERR_INVALID_ARG. Indicating that an invalid argument is passed in. @param [in] pstrAddr - Pointer to socket address structure "sockaddr_in" + Pointer to socket address structure "sockaddr_in" [sockaddr_in](@ref sockaddr_in) - + @param [in] u8AddrLen - Size of the given socket address structure in bytes. + Size of the given socket address structure in bytes. @pre The socket function must be called to allocate a socket before passing the socket ID to the bind function. @@ -927,12 +1014,12 @@ NMI_API SOCKET WINC1500_EXPORT(socket)(uint16 u16Domain, uint8 u8Type, uint8 u8F send sendto -@return - The function returns ZERO for successful operations and a negative value otherwise. +@return + The function returns ZERO for successful operations and a negative value otherwise. The possible error values are: - - [SOCK_ERR_NO_ERROR](@ref SOCK_ERR_NO_ERROR) + - [SOCK_ERR_NO_ERROR](@ref SOCK_ERR_NO_ERROR) Indicating that the operation was successful. - + - [SOCK_ERR_INVALID_ARG](@ref SOCK_ERR_INVALID_ARG) Indicating passing invalid arguments such as negative socket ID or NULL socket address structure. @@ -944,7 +1031,7 @@ NMI_API SOCKET WINC1500_EXPORT(socket)(uint16 u16Domain, uint8 u8Type, uint8 u8F struct sockaddr_in addr; SOCKET udpServerSocket =-1; int ret = -1; - + if(udpServerSocket == -1) { udpServerSocket = socket(AF_INET,SOCK_DGRAM,0); @@ -968,21 +1055,21 @@ NMI_API SOCKET WINC1500_EXPORT(socket)(uint16 u16Domain, uint8 u8Type, uint8 u8F return; } } -@endcode +@endcode */ NMI_API sint8 WINC1500_EXPORT(bind)(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen); /** @} */ /** @defgroup ListenFn listen * @ingroup SocketAPI - * After successful socket binding to an IP address and port on the system, start listening on a passive socket for incoming connections. - The socket must be bound on a local port or the listen operationfails. + * After successful socket binding to an IP address and port on the system, start listening on a passive socket for incoming connections. + The socket must be bound on a local port or the listen operationfails. Upon the call to the asynchronous listen function, response is received through the event [SOCKET_MSG_BIND](@ref SOCKET_MSG_BIND) in the socket callback. - A successful listen means the TCP server operation is active. If a connection is accepted, then the application socket callback function is + A successful listen means the TCP server operation is active. If a connection is accepted, then the application socket callback function is notified with the new connected socket through the event @ref SOCKET_MSG_ACCEPT. Hence there is no need to call the @ref accept function after calling @ref listen. - + After a connection is accepted, the user is then required to call the @ref recv to recieve any packets transmitted by the remote host or to recieve notification of socket connection termination. */ @@ -997,7 +1084,7 @@ NMI_API sint8 WINC1500_EXPORT(bind)(SOCKET sock, struct sockaddr *pstrAddr, uint @param [in] backlog Not used by the current implementation. - + @pre The bind function must be called to assign the port number and IP address to the socket before the listen operation. @@ -1009,12 +1096,12 @@ NMI_API sint8 WINC1500_EXPORT(bind)(SOCKET sock, struct sockaddr *pstrAddr, uint send sendto -@return - The function returns ZERO for successful operations and a negative value otherwise. +@return + The function returns ZERO for successful operations and a negative value otherwise. The possible error values are: - - [SOCK_ERR_NO_ERROR](@ref SOCK_ERR_NO_ERROR) + - [SOCK_ERR_NO_ERROR](@ref SOCK_ERR_NO_ERROR) Indicating that the operation was successful. - + - [SOCK_ERR_INVALID_ARG](@ref SOCK_ERR_INVALID_ARG) Indicating passing invalid arguments such as negative socket ID. @@ -1024,11 +1111,11 @@ NMI_API sint8 WINC1500_EXPORT(bind)(SOCKET sock, struct sockaddr *pstrAddr, uint This example demonstrates the call of the listen socket operation after a successful socket operation. @code static void TCP_Socketcallback(SOCKET sock, uint8 u8Msg, void * pvMsg) - { + { int ret =-1; - + switch(u8Msg) - { + { case SOCKET_MSG_BIND: { tstrSocketBindMsg *pstrBind = (tstrSocketBindMsg*)pvMsg; @@ -1037,7 +1124,7 @@ This example demonstrates the call of the listen socket operation after a succes if(pstrBind->status == 0) { ret = listen(sock, 0); - + if(ret <0) printf("Listen failure! Error = %d\n",ret); } @@ -1072,7 +1159,7 @@ This example demonstrates the call of the listen socket operation after a succes case SOCKET_MSG_ACCEPT: { tstrSocketAcceptMsg *pstrAccept = (tstrSocketAcceptMsg*)pvMsg; - + if(pstrAccept->sock >= 0) { TcpNotificationSocket = pstrAccept->sock; @@ -1084,7 +1171,7 @@ This example demonstrates the call of the listen socket operation after a succes } } break; - + default: break; } @@ -1096,7 +1183,7 @@ NMI_API sint8 WINC1500_EXPORT(listen)(SOCKET sock, uint8 backlog); /** @} */ /** @defgroup AcceptFn accept * @ingroup SocketAPI - * The function has no current implementation. An empty deceleration is used to prevent errors when legacy application code is used. + * The function has no current implementation. An empty deceleration is used to prevent errors when legacy application code is used. * For recent application use, the accept function can be saferIt has no effect and could be safely removed from any application using it. */ /**@{*/ @@ -1113,12 +1200,12 @@ NMI_API sint8 WINC1500_EXPORT(listen)(SOCKET sock, uint8 backlog); @param [in] addrlen Not used in the current implementation. -@return - The function returns ZERO for successful operations and a negative value otherwise. +@return + The function returns ZERO for successful operations and a negative value otherwise. The possible error values are: - - [SOCK_ERR_NO_ERROR](@ref SOCK_ERR_NO_ERROR) + - [SOCK_ERR_NO_ERROR](@ref SOCK_ERR_NO_ERROR) Indicating that the operation was successful. - + - [SOCK_ERR_INVALID_ARG](@ref SOCK_ERR_INVALID_ARG) Indicating passing invalid arguments such as negative socket ID. */ @@ -1128,14 +1215,14 @@ NMI_API sint8 WINC1500_EXPORT(accept)(SOCKET sock, struct sockaddr *addr, uint8 * @ingroup SocketAPI * Establishes a TCP connection with a remote server. The asynchronous connect function must be called after receiving a valid socket ID from the @ref socket function. - The application socket callback function is notified of a successful new socket connection through the event @ref SOCKET_MSG_CONNECT. + The application socket callback function is notified of a successful new socket connection through the event @ref SOCKET_MSG_CONNECT. A successful connect means the TCP session is active. The application is then required to make a call to the @ref recv to recieve any packets transmitted by the remote server, unless the application is interrupted by a notification of socket connection termination. */ /**@{*/ /*! -@fn \ +@fn \ NMI_API sint8 connect(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen); @param [in] sock @@ -1145,11 +1232,11 @@ NMI_API sint8 WINC1500_EXPORT(accept)(SOCKET sock, struct sockaddr *addr, uint8 @param [in] pstrAddr Address of the remote server. @param [in] pstrAddr - Pointer to socket address structure "sockaddr_in" + Pointer to socket address structure "sockaddr_in" [sockaddr_in](@ref sockaddr_in) @param [in] u8AddrLen - Size of the given socket address structure in bytes. + Size of the given socket address structure in bytes. Not currently used, implemented for BSD compatibility only. @pre The socket function must be called to allocate a TCP socket before passing the socket ID to the bind function. @@ -1160,27 +1247,27 @@ NMI_API sint8 WINC1500_EXPORT(accept)(SOCKET sock, struct sockaddr *addr, uint8 recv send close - -@return - The function returns ZERO for successful operations and a negative value otherwise. + +@return + The function returns ZERO for successful operations and a negative value otherwise. The possible error values are: - - [SOCK_ERR_NO_ERROR](@ref SOCK_ERR_NO_ERROR) + - [SOCK_ERR_NO_ERROR](@ref SOCK_ERR_NO_ERROR) Indicating that the operation was successful. - + - [SOCK_ERR_INVALID_ARG](@ref SOCK_ERR_INVALID_ARG) Indicating passing invalid arguments such as negative socket ID or NULL socket address structure. - [SOCK_ERR_INVALID](@ref SOCK_ERR_INVALID) Indicate socket connect failure. \section Example - The example demonstrates a TCP application, showing how the asynchronous call to the connect function is made through the main function and how the + The example demonstrates a TCP application, showing how the asynchronous call to the connect function is made through the main function and how the callback function handles the @ref SOCKET_MSG_CONNECT event. \subsection sub1 Main Function @code struct sockaddr_in Serv_Addr; SOCKET TcpClientSocket =-1; int ret = -1 - + TcpClientSocket = socket(AF_INET,SOCK_STREAM,0); Serv_Addr.sin_family = AF_INET; Serv_Addr.sin_port = _htons(1234); @@ -1199,7 +1286,7 @@ NMI_API sint8 WINC1500_EXPORT(accept)(SOCKET sock, struct sockaddr *addr, uint8 printf("Connection successful.\n"); break; } - }while(1) + }while(1) @endcode \subsection sub2 Socket Callback @code @@ -1212,7 +1299,7 @@ NMI_API sint8 WINC1500_EXPORT(accept)(SOCKET sock, struct sockaddr *addr, uint8 uint16 u16MsgSize; printf("Connect success!\n"); - + u16MsgSize = FormatMsg(u8ClientID, acBuffer); send(sock, acBuffer, u16MsgSize, 0); recv(pstrNotification->Socket, (void*)au8Msg,GROWL_DESCRIPTION_MAX_LENGTH, GROWL_RX_TIMEOUT); @@ -1230,11 +1317,11 @@ NMI_API sint8 WINC1500_EXPORT(connect)(SOCKET sock, struct sockaddr *pstrAddr, u /** @} */ /** @defgroup ReceiveFn recv * @ingroup SocketAPI - * An asynchrnonous receive function, used to retrieve data from a TCP stream. - Before calling the recv function, a successful socket connection status must have been received through any of the two socket events + * An asynchrnonous receive function, used to retrieve data from a TCP stream. + Before calling the recv function, a successful socket connection status must have been received through any of the two socket events [SOCKET_MSG_CONNECT] or [SOCKET_MSG_ACCEPT], from the socket callback. Hence, indicating that the socket is already connected to a remote - host. - The application receives the required data in response to this asynchronous call through the reception of the event @ref SOCKET_MSG_RECV in the + host. + The application receives the required data in response to this asynchronous call through the reception of the event @ref SOCKET_MSG_RECV in the socket callback. Recieving the SOCKET_MSG_RECV message in the callback with zero or negative buffer length indicates the following: @@ -1247,14 +1334,14 @@ NMI_API sint8 WINC1500_EXPORT(connect)(SOCKET sock, struct sockaddr *pstrAddr, u /*! @fn \ NMI_API sint16 recv(SOCKET sock, void *pvRecvBuf, uint16 u16BufLen, uint32 u32Timeoutmsec); - + @param [in] sock Socket ID, must hold a non negative value. A negative value will return a socket error @ref SOCK_ERR_INVALID_ARG. Indicating that an invalid argument is passed in. @param [in] pvRecvBuf - Pointer to a buffer that will hold the received data. The buffer is used + Pointer to a buffer that will hold the received data. The buffer is used in the recv callback to deliver the received data to the caller. The buffer must be resident in memory (heap or global buffer). @@ -1268,7 +1355,7 @@ NMI_API sint8 WINC1500_EXPORT(connect)(SOCKET sock, struct sockaddr *pstrAddr, u @pre - The socket function must be called to allocate a TCP socket before passing the socket ID to the recv function. - The socket in a connected state is expected to receive data through the socket interface. - + @see socket connect @@ -1276,26 +1363,26 @@ NMI_API sint8 WINC1500_EXPORT(connect)(SOCKET sock, struct sockaddr *pstrAddr, u listen recvfrom close + - -@return +@return The function returns ZERO for successful operations and a negative value otherwise. The possible error values are: - - [SOCK_ERR_NO_ERROR](@ref SOCK_ERR_NO_ERROR) + - [SOCK_ERR_NO_ERROR](@ref SOCK_ERR_NO_ERROR) Indicating that the operation was successful. - + - [SOCK_ERR_INVALID_ARG](@ref SOCK_ERR_INVALID_ARG) Indicating passing invalid arguments such as negative socket ID or NULL Recieve buffer. - [SOCK_ERR_BUFFER_FULL](@ref SOCK_ERR_BUFFER_FULL) Indicate socket recieve failure. \section Example - The example demonstrates a code snippet for the calling of the recv function in the socket callback upon notification of the accept or connect events, and the parsing of the + The example demonstrates a code snippet for the calling of the recv function in the socket callback upon notification of the accept or connect events, and the parsing of the received data when the SOCKET_MSG_RECV event is received. @code - + switch(u8Msg) - { + { case SOCKET_MSG_ACCEPT: { @@ -1316,11 +1403,11 @@ NMI_API sint8 WINC1500_EXPORT(connect)(SOCKET sock, struct sockaddr *pstrAddr, u case SOCKET_MSG_RECV: { tstrSocketRecvMsg *pstrRx = (tstrSocketRecvMsg*)pvMsg; - + if(pstrRx->s16BufferSize > 0) { - - recv(sock,gau8RxBuffer,sizeof(gau8RxBuffer),TEST_RECV_TIMEOUT); + + recv(sock,gau8RxBuffer,sizeof(gau8RxBuffer),TEST_RECV_TIMEOUT); } else { @@ -1329,7 +1416,7 @@ NMI_API sint8 WINC1500_EXPORT(connect)(SOCKET sock, struct sockaddr *pstrAddr, u } } break; - + default: break; } @@ -1347,9 +1434,9 @@ NMI_API sint16 WINC1500_EXPORT(recv)(SOCKET sock, void *pvRecvBuf, uint16 u16Buf * with successful status in the socket callback). * * Upon calling the recvfrom function with a successful return code, the application is expected to receive a notification -* in the socket callback whenever a message is recieved through the @ref SOCKET_MSG_RECVFROM event. +* in the socket callback whenever a message is recieved through the @ref SOCKET_MSG_RECVFROM event. * -* Receiving the SOCKET_MSG_RECVFROM message in the callback with zero, indicates that the socket is closed. +* Receiving the SOCKET_MSG_RECVFROM message in the callback with zero, indicates that the socket is closed. * Whereby a negative buffer length indicates one of the socket error codes such as socket timeout error @SOCK_ERR_TIMEOUT: * * The recvfrom callback can also be used to show the IP address of the remote host that sent the frame by @@ -1357,7 +1444,7 @@ NMI_API sint16 WINC1500_EXPORT(recv)(SOCKET sock, void *pvRecvBuf, uint16 u16Buf */ /**@{*/ /*! -@fn \ +@fn \ NMI_API sint16 recvfrom(SOCKET sock, void *pvRecvBuf, uint16 u16BufLen, uint32 u32TimeoutSeconds); @param [in] sock @@ -1379,29 +1466,29 @@ NMI_API sint16 WINC1500_EXPORT(recv)(SOCKET sock, void *pvRecvBuf, uint16 u16Buf @pre - The socket function must be called to allocate a TCP socket before passing the socket ID to the recv function. - The socket corresponding to the socket ID must be successfully bound to a local port through the call to a @ref bind function. - + @see socket bind close -@return +@return The function returns ZERO for successful operations and a negative value otherwise. The possible error values are: - - [SOCK_ERR_NO_ERROR](@ref SOCK_ERR_NO_ERROR) + - [SOCK_ERR_NO_ERROR](@ref SOCK_ERR_NO_ERROR) Indicating that the operation was successful. - + - [SOCK_ERR_INVALID_ARG](@ref SOCK_ERR_INVALID_ARG) Indicating passing invalid arguments such as negative socket ID or NULL Recieve buffer. - [SOCK_ERR_BUFFER_FULL](@ref SOCK_ERR_BUFFER_FULL) Indicate socket recieve failure. \section Example - The example demonstrates a code snippet for the calling of the recvfrom function in the socket callback upon notification of a successful bind event, and the parsing of the + The example demonstrates a code snippet for the calling of the recvfrom function in the socket callback upon notification of a successful bind event, and the parsing of the received data when the SOCKET_MSG_RECVFROM event is received. @code switch(u8Msg) - { + { case SOCKET_MSG_BIND: { @@ -1425,7 +1512,7 @@ NMI_API sint16 WINC1500_EXPORT(recv)(SOCKET sock, void *pvRecvBuf, uint16 u16Buf case SOCKET_MSG_RECVFROM: { tstrSocketRecvMsg *pstrRx = (tstrSocketRecvMsg*)pvMsg; - + if(pstrRx->s16BufferSize > 0) { //get the remote host address and port number @@ -1433,8 +1520,8 @@ NMI_API sint16 WINC1500_EXPORT(recv)(SOCKET sock, void *pvRecvBuf, uint16 u16Buf uint32 strRemoteHostAddr = pstrRx->strRemoteAddr.sin_addr.s_addr; printf("Recieved frame with size = %d.\tHost address=%x, Port number = %d\n\n",pstrRx->s16BufferSize,strRemoteHostAddr, u16port); - - ret = recvfrom(sock,gau8SocketTestBuffer,sizeof(gau8SocketTestBuffer),TEST_RECV_TIMEOUT); + + ret = recvfrom(sock,gau8SocketTestBuffer,sizeof(gau8SocketTestBuffer),TEST_RECV_TIMEOUT); } else { @@ -1443,7 +1530,7 @@ NMI_API sint16 WINC1500_EXPORT(recv)(SOCKET sock, void *pvRecvBuf, uint16 u16Buf } } break; - + default: break; } @@ -1459,59 +1546,59 @@ NMI_API sint16 WINC1500_EXPORT(recvfrom)(SOCKET sock, void *pvRecvBuf, uint16 u1 * Called by the application code when there is outgoing data available required to be sent on a specific socket handler. * The only difference between this function and the similar @ref sendto function, is the type of socket the data is sent on and the parameters passed in. * @ref send function is most commonly called for sockets in a connected state. -* After the data is sent, the socket callback function registered using registerSocketCallback(), is expected to receive an event of type +* After the data is sent, the socket callback function registered using registerSocketCallback(), is expected to receive an event of type * @ref SOCKET_MSG_SEND holding information containing the number of data bytes sent. */ /**@{*/ /*! -@fn \ +@fn \ NMI_API sint16 send(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 u16Flags); @param [in] sock Socket ID, must hold a non negative value. A negative value will return a socket error @ref SOCK_ERR_INVALID_ARG. Indicating that an invalid argument is passed in. - + @param [in] pvSendBuffer - Pointer to a buffer holding data to be transmitted. + Pointer to a buffer holding data to be transmitted. @param [in] u16SendLength The buffer size in bytes. @param [in] u16Flags Not used in the current implementation. - -@pre - Sockets must be initialized using socketInit. \n - + +@pre + Sockets must be initialized using socketInit. \n + For TCP Socket:\n - Must use a successfully connected Socket (so that the intended recipient address is known ahead of sending the data). + Must use a successfully connected Socket (so that the intended recipient address is known ahead of sending the data). Hence this function is expected to be called after a successful socket connect operation(in client case or accept in the the server case).\n - + For UDP Socket:\n UDP sockets most commonly use @ref sendto function, where the destination address is defined. However, in-order to send outgoing data - using the @ref send function, atleast one successful call must be made to the @ref sendto function apriori the consecutive calls to the @ref send function, + using the @ref send function, atleast one successful call must be made to the @ref sendto function apriori the consecutive calls to the @ref send function, to ensure that the destination address is saved in the firmware. - + @see socketInit recv sendto socket connect - accept - sendto - + accept + sendto + @warning u16SendLength must not exceed @ref SOCKET_BUFFER_MAX_LENGTH. \n Use a valid socket identifer through the aprior call to the @ref socket function. Must use a valid buffer pointer. Successful completion of a call to send() does not guarantee delivery of the message, A negative return value indicates only locally-detected errors - - -@return - The function shall return @ref SOCK_ERR_NO_ERROR for successful operation and a negative value (indicating the error) otherwise. + + +@return + The function shall return @ref SOCK_ERR_NO_ERROR for successful operation and a negative value (indicating the error) otherwise. */ NMI_API sint16 WINC1500_EXPORT(send)(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 u16Flags); /** @} */ @@ -1519,10 +1606,10 @@ NMI_API sint16 WINC1500_EXPORT(send)(SOCKET sock, void *pvSendBuffer, uint16 u16 * @ingroup SocketAPI * Asynchronous sending function, used to send data on a UDP socket. * Called by the application code when there is data required to be sent on a UDP socket handler. -* The application code is expected to receive data from a successful bounded socket node. +* The application code is expected to receive data from a successful bounded socket node. * The only difference between this function and the similar @ref send function, is the type of socket the data is received on. This function works * only with UDP sockets. -* After the data is sent, the socket callback function registered using registerSocketCallback(), is expected to receive an event of type +* After the data is sent, the socket callback function registered using registerSocketCallback(), is expected to receive an event of type * @ref SOCKET_MSG_SENDTO. */ /**@{*/ @@ -1535,7 +1622,7 @@ NMI_API sint16 WINC1500_EXPORT(send)(SOCKET sock, void *pvSendBuffer, uint16 u16 A negative value will return a socket error @ref SOCK_ERR_INVALID_ARG. Indicating that an invalid argument is passed in. @param [in] pvSendBuffer - Pointer to a buffer holding data to be transmitted. + Pointer to a buffer holding data to be transmitted. A NULL value will return a socket error @ref SOCK_ERR_INVALID_ARG. Indicating that an invalid argument is passed in. @param [in] u16SendLength @@ -1548,29 +1635,29 @@ NMI_API sint16 WINC1500_EXPORT(send)(SOCKET sock, void *pvSendBuffer, uint16 u16 The destination address. @param [in] u8AddrLen - Destination address length in bytes. + Destination address length in bytes. Not used in the current implementation, only included for BSD compatibility. -@pre +@pre Sockets must be initialized using socketInit. - + @see - socketInit + socketInit recvfrom sendto socket connect - accept - send - + accept + send + @warning u16SendLength must not exceed @ref SOCKET_BUFFER_MAX_LENGTH. \n Use a valid socket (returned from socket ). - A valid buffer pointer must be used (not NULL). \n + A valid buffer pointer must be used (not NULL). \n Successful completion of a call to sendto() does not guarantee delivery of the message, A negative return value indicates only locally-detected errors @return - The function returns @ref SOCK_ERR_NO_ERROR for successful operation and a negative value (indicating the error) otherwise. + The function returns @ref SOCK_ERR_NO_ERROR for successful operation and a negative value (indicating the error) otherwise. */ NMI_API sint16 WINC1500_EXPORT(sendto)(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 flags, struct sockaddr *pstrDestAddr, uint8 u8AddrLen); /** @} */ @@ -1586,11 +1673,11 @@ NMI_API sint16 WINC1500_EXPORT(sendto)(SOCKET sock, void *pvSendBuffer, uint16 u @param [in] sock Socket ID, must hold a non negative value. A negative value will return a socket error @ref SOCK_ERR_INVALID_ARG. Indicating that an invalid argument is passed in. - -@pre + +@pre Sockets must be initialized through the call of the socketInit function. @ref close is called only for valid socket identifers created through the @ref socket function. - + @warning If @ref close is called while there are still pending messages (sent or received ) they will be discarded. @@ -1598,8 +1685,8 @@ NMI_API sint16 WINC1500_EXPORT(sendto)(SOCKET sock, void *pvSendBuffer, uint16 u socketInit socket -@return - The function returned @ref SOCK_ERR_NO_ERROR for successful operation and a negative value (indicating the error) otherwise. +@return + The function returned @ref SOCK_ERR_NO_ERROR for successful operation and a negative value (indicating the error) otherwise. */ NMI_API sint8 WINC1500_EXPORT(close)(SOCKET sock); /** @} */ @@ -1608,8 +1695,8 @@ NMI_API sint8 WINC1500_EXPORT(close)(SOCKET sock); * Synchronous function which returns a BSD socket compliant Internet Protocol (IPv4) socket address. * This IPv4 address in the input string parameter could either be specified as a hostname, or as a numeric string representation like n.n.n.n known as the IPv4 dotted-decimal format * (i.e. "192.168.10.1"). -* This function is used whenever an ip address needs to be set in the proper format -* (i.e. for the @ref tstrM2MIPConfig structure). +* This function is used whenever an ip address needs to be set in the proper format +* (i.e. for the @ref tstrM2MIPConfig structure). */ /**@{*/ /*! @@ -1622,14 +1709,14 @@ NMI_API sint8 WINC1500_EXPORT(close)(SOCKET sock); @return Unsigned 32-bit integer representing the IP address in Network byte order (eg. "192.168.10.1" will be expressed as 0x010AA8C0). - + */ NMI_API uint32 nmi_inet_addr(char *pcIpAddr); /** @} */ /** @defgroup gethostbynameFn gethostbyname * @ingroup SocketAPI -* Asynchronous DNS resolving function. This function use DNS to resolve a domain name into the corresponding IP address. -* A call to this function will cause a DNS request to be sent and the response will be delivered to the DNS callback function registered using registerSocketCallback() +* Asynchronous DNS resolving function. This function use DNS to resolve a domain name into the corresponding IP address. +* A call to this function will cause a DNS request to be sent and the response will be delivered to the DNS callback function registered using registerSocketCallback() */ /**@{*/ /*! @@ -1639,10 +1726,10 @@ NMI_API uint32 nmi_inet_addr(char *pcIpAddr); @param [in] pcHostName NULL terminated string containing the domain name for the remote host. Its size must not exceed [HOSTNAME_MAX_SIZE](@ref HOSTNAME_MAX_SIZE). - + @see registerSocketCallback - ) + @warning Successful completion of a call to gethostbyname() does not guarantee success of the DNS request, a negative return value indicates only locally-detected errors @@ -1653,7 +1740,46 @@ NMI_API uint32 nmi_inet_addr(char *pcIpAddr); */ NMI_API sint8 WINC1500_EXPORT(gethostbyname)(uint8 * pcHostName); -NMI_API sint8 sslSetSockOpt(SOCKET sock, uint8 u8Opt, const void *pvOptVal, uint16 u16OptLen); + + +/** @} */ +/** @defgroup sslSetActiveCipherSuitesFn sslSetActiveCipherSuites + * @ingroup SocketAPI + * Overrides the default active SSL ciphers in the SSL module with a certain combination of ciphers selected by the caller using + * a bitmap containing the required ciphers list. + * There API is required only if the will not change the default ciphersuites, otherwise, it is not recommended to use. + */ + /**@{*/ +/*! +@fn \ + NMI_API sint8 sslSetActiveCipherSuites(uint32 u32SslCsBMP); + +@param [in] u32SslCsBMP +

A non-zero 32-bit integer bitmap containing the bitwise OR of the desired ciphers to be enabled +for the SSL module. The ciphersuites are defined in groups as follows:

+ +@return + Possible return values are [SOCK_ERR_NO_ERROR](@ref SOCK_ERR_NO_ERROR) if case of success + or [SOCK_ERR_INVALID_ARG](@ref SOCK_ERR_INVALID_ARG) if the map is zero. +@remarks +The default supported ciphersuites are the combination of all the above groups. The caller can override the default with any desired combination. +For example, to disable SHA based ciphers the function should be called with this syntax: +\code + sslSetActiveCipherSuites(SSL_ENABLE_ALL_SUITES & ~(SSL_ENABLE_RSA_SHA_SUITES|SSL_ENABLE_DHE_SHA_SUITES)); +\endcode +@note Passing the u32SslCsBMP as zero will not change the current active list. +*/ +NMI_API sint8 sslSetActiveCipherSuites(uint32 u32SslCsBMP); + + /** @} */ /** @defgroup SetSocketOptionFn setsockopt @@ -1662,24 +1788,57 @@ NMI_API sint8 sslSetSockOpt(SOCKET sock, uint8 u8Opt, const void *pvOptVal, uin * argument, at the protocol level specified by the level argument, to the value * pointed to by the option_value argument for the socke specified by the socket argument. * -* Possible Options: -* SO_SET_UDP_SEND_CALLBACK: -* Enable/Disable callback messages for sendto().Since UDP is unreliable by default the user maybe interested (or not) -* in receiving a message of /ref SOCKET_MSG_SENDTO for each call of sendto(). -* Enabled if option_value equals /ref BTRUE Disabled otherwise. -* IP_ADD_MEMBERSHIP: -* valid for UDP sockets,this option is used to receive frames sent to a multicast group. -* option_value shall be a pointer to Unsigned 32 bit integer containing the Multicast ipv4 address. -* IP_DROP_MEMBERSHIP: -* valid for UDP sockets,this option is used to Stop receiving frames sent to a multicast group. -* option_value shall be a pointer to Unsigned 32 bit integer containing the Multicast ipv4 address. -* -* Possible values for s32Level: -* This argument is ignored. +*

Possible protcol level values supported are @ref SOL_SOCKET and @ref SOL_SSL_SOCKET. +* Possible options when the protocol level is @ref SOL_SOCKET :

+* +* +* +* +* +* +* +* +* +* +* +* +* +*
@ref SO_SET_UDP_SEND_CALLBACKEnable/Disable callback messages for sendto(). +* Since UDP is unreliable by default the user maybe interested (or not) in +* receiving a message of @ref SOCKET_MSG_SENDTO for each call of sendto(). +* Enabled if option value equals @ref TRUE, disabled otherwise.
@ref IP_ADD_MEMBERSHIPValid for UDP sockets. This option is used to receive frames sent to +* a multicast group. option_value shall be a pointer to Unsigned 32-bit +* integer containing the multicast IPv4 address.
@ref IP_DROP_MEMBERSHIPValid for UDP sockets. This option is used to stop receiving frames +* sent to a multicast group. option_value shall be a pointer to Unsigned +* 32-bit integer containing the multicast IPv4 address.
+*

Possible options when the protcol leve  is @ref SOL_SSL_SOCKET

+* +* +* +* +* +* +* +* +* +* +* +* +* +*
+* @ref SO_SSL_BYPASS_X509_VERIFAllow an opened SSL socket to bypass the X509 +* certificate verification process. It is highly recommended NOT to use +* this socket option in production software applications. The option is +* supported for debugging and testing purposes. The option value should be +* casted to int type and it is handled as a boolean flag.
@ref SO_SSL_SNISet the Server Name Indicator (SNI) for an SSL socket. The SNI is a +* null terminated string containing the server name assocated with the +* connection. It must not exceed the size of @ref HOSTNAME_MAX_SIZE.
@ref SO_SSL_ENABLE_SESSION_CACHINGThis option allow the TLS to cache the session information for fast +* TLS session establishment in future connections using the TLS Protocol +* session resume features.
*/ /**@{*/ /*! -@fn \ +@fn \ NMI_API sint8 setsockopt(SOCKET socket, uint8 u8Level, uint8 option_name, const void *option_value, uint16 u16OptionLen); @@ -1687,25 +1846,25 @@ NMI_API sint8 sslSetSockOpt(SOCKET sock, uint8 u8Opt, const void *pvOptVal, uin Socket handler. @param [in] level - protocol level. always SOL_SOCKET for now. + protocol level. See description above. @param [in] option_name - option to be set. + option to be set. See description above. @param [in] option_value pointer to user provided value. @param [in] option_len - length of the option value. -@warning - -Note that sending IGMP packets to Join/Leave multicast groups is not implemented at the current moment. \n - calling this function will Pass/Filter packets packets sent to Multicast address provided in the option_value -@return - The function shall return \ref SOCK_ERR_NO_ERROR for successful operation - and a negative value (indicating the error) otherwise. + length of the option value in bytes. +@return + The function shall return \ref SOCK_ERR_NO_ERROR for successful operation + and a negative value (indicating the error) otherwise. +@sa SOL_SOCKET, SOL_SSL_SOCKET, */ NMI_API sint8 WINC1500_EXPORT(setsockopt)(SOCKET socket, uint8 u8Level, uint8 option_name, const void *option_value, uint16 u16OptionLen); + + /** @} */ /** @defgroup GetSocketOptionsFn getsockopt * @ingroup SocketAPI @@ -1718,7 +1877,7 @@ NMI_API sint8 WINC1500_EXPORT(setsockopt)(SOCKET socket, uint8 u8Level, uint8 op sint8 getsockopt(SOCKET sock, uint8 u8Level, uint8 u8OptName, const void *pvOptValue, uint8 * pu8OptLen); @brief - + @param [in] sock Socket Identifie. diff --git a/src/winc1500/src/m2m_ate_mode.c b/src/winc1500/src/m2m_ate_mode.c index 3f37c9e06..680a79f57 100644 --- a/src/winc1500/src/m2m_ate_mode.c +++ b/src/winc1500/src/m2m_ate_mode.c @@ -133,13 +133,32 @@ FUNCTION IMPLEMENTATION sint8 m2m_ate_init(void) { sint8 s8Ret = M2M_SUCCESS; - uint8 u8WifiMode = M2M_WIFI_MODE_CONFIG; + uint8 u8WifiMode = M2M_WIFI_MODE_ATE_HIGH; s8Ret = nm_drv_init(&u8WifiMode); return s8Ret; } +/*! +@fn \ + sint8 m2m_ate_init(tstrM2mAteInit *pstrInit); + +@brief + This function used to download ATE firmware from flash and start it + +@return + The function SHALL return 0 for success and a negative value otherwise. +*/ +sint8 m2m_ate_init_param(tstrM2mAteInit *pstrInit) +{ + sint8 s8Ret = M2M_SUCCESS; + + s8Ret = nm_drv_init((void*)&pstrInit->u8RxPwrMode); + + return s8Ret; +} + /*! @fn \ sint8 m2m_ate_deinit(void); @@ -465,7 +484,7 @@ sint8 m2m_ate_get_rx_status(void) */ sint8 m2m_ate_start_rx(tstrM2mAteRx * strM2mAteRxStr) { - sint8 s8Ret = M2M_SUCCESS; + sint8 s8Ret = M2M_SUCCESS; uint32 val32; if(NULL == strM2mAteRxStr) { diff --git a/src/winc1500/src/m2m_crypto.c b/src/winc1500/src/m2m_crypto.c new file mode 100644 index 000000000..90b313495 --- /dev/null +++ b/src/winc1500/src/m2m_crypto.c @@ -0,0 +1,1010 @@ +/** + * + * \file + * + * \brief WINC Crypto module. + * + * Copyright (c) 2015 Atmel Corporation. All rights reserved. + * + * \asf_license_start + * + * \page License + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. 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. + * + * 3. The name of Atmel may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * + * \asf_license_stop + * + */ + +/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* +INCLUDES +*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ + +#include "driver/include/m2m_crypto.h" +#include "driver/include/nmbus.h" +#include "driver/include/nmasic.h" + +#ifdef CONF_CRYPTO_HW + +/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* +MACROS +*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ + +/*======*======*======*======*======*=======* +* WINC SHA256 HW Engine Register Definition * +*======*======*======*======*======*========*/ + +#define SHA_BLOCK_SIZE (64) + +#define SHARED_MEM_BASE (0xd0000) + + +#define SHA256_MEM_BASE (0x180000UL) +#define SHA256_ENGINE_ADDR (0x180000ul) + +/* SHA256 Registers */ +#define SHA256_CTRL (SHA256_MEM_BASE+0x00) +#define SHA256_CTRL_START_CALC_MASK (NBIT0) +#define SHA256_CTRL_START_CALC_SHIFT (0) +#define SHA256_CTRL_PREPROCESS_MASK (NBIT1) +#define SHA256_CTRL_PREPROCESS_SHIFT (1) +#define SHA256_CTRL_HASH_HASH_MASK (NBIT2) +#define SHA256_CTRL_HASH_HASH_SHIFT (2) +#define SHA256_CTRL_INIT_SHA256_STATE_MASK (NBIT3) +#define SHA256_CTRL_INIT_SHA256_STATE_SHIFT (3) +#define SHA256_CTRL_WR_BACK_HASH_VALUE_MASK (NBIT4) +#define SHA256_CTRL_WR_BACK_HASH_VALUE_SHIFT (4) +#define SHA256_CTRL_FORCE_SHA256_QUIT_MASK (NBIT5) +#define SHA256_CTRL_FORCE_SHA256_QUIT_SHIFT (5) + +#define SHA256_REGS_SHA256_CTRL_AHB_BYTE_REV_EN (NBIT6) +#define SHA256_REGS_SHA256_CTRL_RESERVED (NBIT7) +#define SHA256_REGS_SHA256_CTRL_CORE_TO_AHB_CLK_RATIO (NBIT8+ NBIT9+ NBIT10) +#define SHA256_REGS_SHA256_CTRL_CORE_TO_AHB_CLK_RATIO_MASK (NBIT2+ NBIT1+ NBIT0) +#define SHA256_REGS_SHA256_CTRL_CORE_TO_AHB_CLK_RATIO_SHIFT (8) +#define SHA256_REGS_SHA256_CTRL_RESERVED_11 (NBIT11) +#define SHA256_REGS_SHA256_CTRL_SHA1_CALC (NBIT12) +#define SHA256_REGS_SHA256_CTRL_PBKDF2_SHA1_CALC (NBIT13) + + +#define SHA256_START_RD_ADDR (SHA256_MEM_BASE+0x04UL) +#define SHA256_DATA_LENGTH (SHA256_MEM_BASE+0x08UL) +#define SHA256_START_WR_ADDR (SHA256_MEM_BASE+0x0cUL) +#define SHA256_COND_CHK_CTRL (SHA256_MEM_BASE+0x10) +#define SHA256_COND_CHK_CTRL_HASH_VAL_COND_CHK_MASK (NBIT1 | NBIT0) +#define SHA256_COND_CHK_CTRL_HASH_VAL_COND_CHK_SHIFT (0) +#define SHA256_COND_CHK_CTRL_STEP_VAL_MASK (NBIT6 | NBIT5 | NBIT4 | NBIT3 | NBIT2) +#define SHA256_COND_CHK_CTRL_STEP_VAL_SHIFT (2) +#define SHA256_COND_CHK_CTRL_COND_CHK_RESULT_MASK (NBIT7) +#define SHA256_COND_CHK_CTRL_COND_CHK_RESULT_SHIFT (7) + +#define SHA256_MOD_DATA_RANGE (SHA256_MEM_BASE+0x14) +#define SHA256_MOD_DATA_RANGE_ST_BYTE_2_ADD_STP_MASK (NBIT24-1) +#define SHA256_MOD_DATA_RANGE_ST_BYTE_2_ADD_STP_SHIFT (0) +#define SHA256_MOD_DATA_RANGE_MOD_DATA_LEN_MASK (NBIT24 | NBIT25| NBIT26) +#define SHA256_MOD_DATA_RANGE_MOD_DATA_LEN_SHIFT (24) + + +#define SHA256_COND_CHK_STS_1 (SHA256_MEM_BASE+0x18) +#define SHA256_COND_CHK_STS_2 (SHA256_MEM_BASE+0x1c) +#define SHA256_DONE_INTR_ENABLE (SHA256_MEM_BASE+0x20) +#define SHA256_DONE_INTR_STS (SHA256_MEM_BASE+0x24) +#define SHA256_TARGET_HASH_H1 (SHA256_MEM_BASE+0x28) +#define SHA256_TARGET_HASH_H2 (SHA256_MEM_BASE+0x2c) +#define SHA256_TARGET_HASH_H3 (SHA256_MEM_BASE+0x30) +#define SHA256_TARGET_HASH_H4 (SHA256_MEM_BASE+0x34) +#define SHA256_TARGET_HASH_H5 (SHA256_MEM_BASE+0x38) +#define SHA256_TARGET_HASH_H6 (SHA256_MEM_BASE+0x3c) +#define SHA256_TARGET_HASH_H7 (SHA256_MEM_BASE+0x40) +#define SHA256_TARGET_HASH_H8 (SHA256_MEM_BASE+0x44) + +/*======*======*======*======*======*=======* +* WINC BIGINT HW Engine Register Definition * +*======*======*======*======*======*========*/ + + +#define BIGINT_ENGINE_ADDR (0x180080ul) +#define BIGINT_VERSION (BIGINT_ENGINE_ADDR + 0x00) + +#define BIGINT_MISC_CTRL (BIGINT_ENGINE_ADDR + 0x04) +#define BIGINT_MISC_CTRL_CTL_START (NBIT0) +#define BIGINT_MISC_CTRL_CTL_RESET (NBIT1) +#define BIGINT_MISC_CTRL_CTL_MSW_FIRST (NBIT2) +#define BIGINT_MISC_CTRL_CTL_SWAP_BYTE_ORDER (NBIT3) +#define BIGINT_MISC_CTRL_CTL_FORCE_BARRETT (NBIT4) +#define BIGINT_MISC_CTRL_CTL_M_PRIME_VALID (NBIT5) + +#define BIGINT_M_PRIME (BIGINT_ENGINE_ADDR + 0x08) + +#define BIGINT_STATUS (BIGINT_ENGINE_ADDR + 0x0C) +#define BIGINT_STATUS_STS_DONE (NBIT0) + +#define BIGINT_CLK_COUNT (BIGINT_ENGINE_ADDR + 0x10) +#define BIGINT_ADDR_X (BIGINT_ENGINE_ADDR + 0x14) +#define BIGINT_ADDR_E (BIGINT_ENGINE_ADDR + 0x18) +#define BIGINT_ADDR_M (BIGINT_ENGINE_ADDR + 0x1C) +#define BIGINT_ADDR_R (BIGINT_ENGINE_ADDR + 0x20) +#define BIGINT_LENGTH (BIGINT_ENGINE_ADDR + 0x24) + +#define BIGINT_IRQ_STS (BIGINT_ENGINE_ADDR + 0x28) +#define BIGINT_IRQ_STS_DONE (NBIT0) +#define BIGINT_IRQ_STS_CHOOSE_MONT (NBIT1) +#define BIGINT_IRQ_STS_M_READ (NBIT2) +#define BIGINT_IRQ_STS_X_READ (NBIT3) +#define BIGINT_IRQ_STS_START (NBIT4) +#define BIGINT_IRQ_STS_PRECOMP_FINISH (NBIT5) + +#define BIGINT_IRQ_MASK (BIGINT_ENGINE_ADDR + 0x2C) +#define BIGINT_IRQ_MASK_CTL_IRQ_MASK_START (NBIT4) + +#define ENABLE_FLIPPING 1 + + + + +#define GET_UINT32(BUF,OFFSET) (((uint32)((BUF)[OFFSET])) | ((uint32)(((BUF)[OFFSET + 1]) << 8)) | \ +((uint32)(((BUF)[OFFSET + 2]) << 16)) | ((uint32)(((BUF)[OFFSET + 3]) << 24))) + +#define PUTU32(VAL32,BUF,OFFSET) \ +do \ +{ \ + (BUF)[OFFSET ] = BYTE_3((VAL32)); \ + (BUF)[OFFSET +1 ] = BYTE_2((VAL32)); \ + (BUF)[OFFSET +2 ] = BYTE_1((VAL32)); \ + (BUF)[OFFSET +3 ] = BYTE_0((VAL32)); \ +}while(0) + + +/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* +DATA TYPES +*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ + +/*! +@struct \ + tstrHashContext + +@brief +*/ +typedef struct{ + uint32 au32HashState[M2M_SHA256_DIGEST_LEN/4]; + uint8 au8CurrentBlock[64]; + uint32 u32TotalLength; + uint8 u8InitHashFlag; +}tstrSHA256HashCtxt; + + + +/*======*======*======*======*======*=======* +* SHA256 IMPLEMENTATION * +*======*======*======*======*======*========*/ + +sint8 m2m_crypto_sha256_hash_init(tstrM2mSha256Ctxt *pstrSha256Ctxt) +{ + tstrSHA256HashCtxt *pstrSHA256 = (tstrSHA256HashCtxt*)pstrSha256Ctxt; + if(pstrSHA256 != NULL) + { + m2m_memset((uint8*)pstrSha256Ctxt, 0, sizeof(tstrM2mSha256Ctxt)); + pstrSHA256->u8InitHashFlag = 1; + } + return 0; +} + +sint8 m2m_crypto_sha256_hash_update(tstrM2mSha256Ctxt *pstrSha256Ctxt, uint8 *pu8Data, uint16 u16DataLength) +{ + sint8 s8Ret = M2M_ERR_FAIL; + tstrSHA256HashCtxt *pstrSHA256 = (tstrSHA256HashCtxt*)pstrSha256Ctxt; + if(pstrSHA256 != NULL) + { + uint32 u32ReadAddr; + uint32 u32WriteAddr = SHARED_MEM_BASE; + uint32 u32Addr = u32WriteAddr; + uint32 u32ResidualBytes; + uint32 u32NBlocks; + uint32 u32Offset; + uint32 u32CurrentBlock = 0; + uint8 u8IsDone = 0; + + /* Get the remaining bytes from the previous update (if the length is not block aligned). */ + u32ResidualBytes = pstrSHA256->u32TotalLength % SHA_BLOCK_SIZE; + + /* Update the total data length. */ + pstrSHA256->u32TotalLength += u16DataLength; + + if(u32ResidualBytes != 0) + { + if((u32ResidualBytes + u16DataLength) >= SHA_BLOCK_SIZE) + { + u32Offset = SHA_BLOCK_SIZE - u32ResidualBytes; + m2m_memcpy(&pstrSHA256->au8CurrentBlock[u32ResidualBytes], pu8Data, u32Offset); + pu8Data += u32Offset; + u16DataLength -= u32Offset; + + nm_write_block(u32Addr, pstrSHA256->au8CurrentBlock, SHA_BLOCK_SIZE); + u32Addr += SHA_BLOCK_SIZE; + u32CurrentBlock = 1; + } + else + { + m2m_memcpy(&pstrSHA256->au8CurrentBlock[u32ResidualBytes], pu8Data, u16DataLength); + u16DataLength = 0; + } + } + + /* Get the number of HASH BLOCKs and the residual bytes. */ + u32NBlocks = u16DataLength / SHA_BLOCK_SIZE; + u32ResidualBytes = u16DataLength % SHA_BLOCK_SIZE; + + if(u32NBlocks != 0) + { + nm_write_block(u32Addr, pu8Data, (uint16)(u32NBlocks * SHA_BLOCK_SIZE)); + pu8Data += (u32NBlocks * SHA_BLOCK_SIZE); + } + + u32NBlocks += u32CurrentBlock; + if(u32NBlocks != 0) + { + uint32 u32RegVal = 0; + + nm_write_reg(SHA256_CTRL, u32RegVal); + u32RegVal |= SHA256_CTRL_FORCE_SHA256_QUIT_MASK; + nm_write_reg(SHA256_CTRL, u32RegVal); + + if(pstrSHA256->u8InitHashFlag) + { + pstrSHA256->u8InitHashFlag = 0; + u32RegVal |= SHA256_CTRL_INIT_SHA256_STATE_MASK; + } + + u32ReadAddr = u32WriteAddr + (u32NBlocks * SHA_BLOCK_SIZE); + nm_write_reg(SHA256_DATA_LENGTH, (u32NBlocks * SHA_BLOCK_SIZE)); + nm_write_reg(SHA256_START_RD_ADDR, u32WriteAddr); + nm_write_reg(SHA256_START_WR_ADDR, u32ReadAddr); + + u32RegVal |= SHA256_CTRL_START_CALC_MASK; + + u32RegVal &= ~(0x7 << 8); + u32RegVal |= (2 << 8); + + nm_write_reg(SHA256_CTRL, u32RegVal); + + /* 5. Wait for done_intr */ + while(!u8IsDone) + { + u32RegVal = nm_read_reg(SHA256_DONE_INTR_STS); + u8IsDone = u32RegVal & NBIT0; + } + } + if(u32ResidualBytes != 0) + { + m2m_memcpy(pstrSHA256->au8CurrentBlock, pu8Data, u32ResidualBytes); + } + s8Ret = M2M_SUCCESS; + } + return s8Ret; +} + + +sint8 m2m_crypto_sha256_hash_finish(tstrM2mSha256Ctxt *pstrSha256Ctxt, uint8 *pu8Sha256Digest) +{ + sint8 s8Ret = M2M_ERR_FAIL; + tstrSHA256HashCtxt *pstrSHA256 = (tstrSHA256HashCtxt*)pstrSha256Ctxt; + if(pstrSHA256 != NULL) + { + uint32 u32ReadAddr; + uint32 u32WriteAddr = SHARED_MEM_BASE; + uint32 u32Addr = u32WriteAddr; + uint16 u16Offset; + uint16 u16PaddingLength; + uint16 u16NBlocks = 1; + uint32 u32RegVal = 0; + uint32 u32Idx,u32ByteIdx; + uint32 au32Digest[M2M_SHA256_DIGEST_LEN / 4]; + uint8 u8IsDone = 0; + + nm_write_reg(SHA256_CTRL,u32RegVal); + u32RegVal |= SHA256_CTRL_FORCE_SHA256_QUIT_MASK; + nm_write_reg(SHA256_CTRL,u32RegVal); + + if(pstrSHA256->u8InitHashFlag) + { + pstrSHA256->u8InitHashFlag = 0; + u32RegVal |= SHA256_CTRL_INIT_SHA256_STATE_MASK; + } + + /* Calculate the offset of the last data byte in the current block. */ + u16Offset = (uint16)(pstrSHA256->u32TotalLength % SHA_BLOCK_SIZE); + + /* Add the padding byte 0x80. */ + pstrSHA256->au8CurrentBlock[u16Offset ++] = 0x80; + + /* Calculate the required padding to complete + one Hash Block Size. + */ + u16PaddingLength = SHA_BLOCK_SIZE - u16Offset; + m2m_memset(&pstrSHA256->au8CurrentBlock[u16Offset], 0, u16PaddingLength); + + /* If the padding count is not enough to hold 64-bit representation of + the total input message length, one padding block is required. + */ + if(u16PaddingLength < 8) + { + nm_write_block(u32Addr, pstrSHA256->au8CurrentBlock, SHA_BLOCK_SIZE); + u32Addr += SHA_BLOCK_SIZE; + m2m_memset(pstrSHA256->au8CurrentBlock, 0, SHA_BLOCK_SIZE); + u16NBlocks ++; + } + + /* pack the length at the end of the padding block */ + PUTU32(pstrSHA256->u32TotalLength << 3, pstrSHA256->au8CurrentBlock, (SHA_BLOCK_SIZE - 4)); + + u32ReadAddr = u32WriteAddr + (u16NBlocks * SHA_BLOCK_SIZE); + nm_write_block(u32Addr, pstrSHA256->au8CurrentBlock, SHA_BLOCK_SIZE); + nm_write_reg(SHA256_DATA_LENGTH, (u16NBlocks * SHA_BLOCK_SIZE)); + nm_write_reg(SHA256_START_RD_ADDR, u32WriteAddr); + nm_write_reg(SHA256_START_WR_ADDR, u32ReadAddr); + + u32RegVal |= SHA256_CTRL_START_CALC_MASK; + u32RegVal |= SHA256_CTRL_WR_BACK_HASH_VALUE_MASK; + u32RegVal &= ~(0x7UL << 8); + u32RegVal |= (0x2UL << 8); + + nm_write_reg(SHA256_CTRL,u32RegVal); + + + /* 5. Wait for done_intr */ + while(!u8IsDone) + { + u32RegVal = nm_read_reg(SHA256_DONE_INTR_STS); + u8IsDone = u32RegVal & NBIT0; + } + nm_read_block(u32ReadAddr, (uint8*)au32Digest, 32); + + /* Convert the output words to an array of bytes. + */ + u32ByteIdx = 0; + for(u32Idx = 0; u32Idx < (M2M_SHA256_DIGEST_LEN / 4); u32Idx ++) + { + pu8Sha256Digest[u32ByteIdx ++] = BYTE_3(au32Digest[u32Idx]); + pu8Sha256Digest[u32ByteIdx ++] = BYTE_2(au32Digest[u32Idx]); + pu8Sha256Digest[u32ByteIdx ++] = BYTE_1(au32Digest[u32Idx]); + pu8Sha256Digest[u32ByteIdx ++] = BYTE_0(au32Digest[u32Idx]); + } + s8Ret = M2M_SUCCESS; + } + return s8Ret; +} + + +/*======*======*======*======*======*=======* +* RSA IMPLEMENTATION * +*======*======*======*======*======*========*/ + +static void FlipBuffer(uint8 *pu8InBuffer, uint8 *pu8OutBuffer, uint16 u16BufferSize) +{ + uint16 u16Idx; + for(u16Idx = 0; u16Idx < u16BufferSize; u16Idx ++) + { +#if ENABLE_FLIPPING == 1 + pu8OutBuffer[u16Idx] = pu8InBuffer[u16BufferSize - u16Idx - 1]; +#else + pu8OutBuffer[u16Idx] = pu8InBuffer[u16Idx]; +#endif + } +} + +void BigInt_ModExp +( + uint8 *pu8X, uint16 u16XSize, + uint8 *pu8E, uint16 u16ESize, + uint8 *pu8M, uint16 u16MSize, + uint8 *pu8R, uint16 u16RSize + ) +{ + uint32 u32Reg; + uint8 au8Tmp[780] = {0}; + uint32 u32XAddr = SHARED_MEM_BASE; + uint32 u32MAddr; + uint32 u32EAddr; + uint32 u32RAddr; + uint8 u8EMswBits = 32; + uint32 u32Mprime = 0x7F; + uint16 u16XSizeWords,u16ESizeWords; + uint32 u32Exponent; + + u16XSizeWords = (u16XSize + 3) / 4; + u16ESizeWords = (u16ESize + 3) / 4; + + u32MAddr = u32XAddr + (u16XSizeWords * 4); + u32EAddr = u32MAddr + (u16XSizeWords * 4); + u32RAddr = u32EAddr + (u16ESizeWords * 4); + + /* Reset the core. + */ + u32Reg = 0; + u32Reg |= BIGINT_MISC_CTRL_CTL_RESET; + u32Reg = nm_read_reg(BIGINT_MISC_CTRL); + u32Reg &= ~BIGINT_MISC_CTRL_CTL_RESET; + u32Reg = nm_read_reg(BIGINT_MISC_CTRL); + + nm_write_block(u32RAddr,au8Tmp, u16RSize); + + /* Write Input Operands to Chip Memory. + */ + /*------- X -------*/ + FlipBuffer(pu8X,au8Tmp,u16XSize); + nm_write_block(u32XAddr,au8Tmp,u16XSizeWords * 4); + + /*------- E -------*/ + m2m_memset(au8Tmp, 0, sizeof(au8Tmp)); + FlipBuffer(pu8E, au8Tmp, u16ESize); + nm_write_block(u32EAddr, au8Tmp, u16ESizeWords * 4); + u32Exponent = GET_UINT32(au8Tmp, (u16ESizeWords * 4) - 4); + while((u32Exponent & NBIT31)== 0) + { + u32Exponent <<= 1; + u8EMswBits --; + } + + /*------- M -------*/ + m2m_memset(au8Tmp, 0, sizeof(au8Tmp)); + FlipBuffer(pu8M, au8Tmp, u16XSize); + nm_write_block(u32MAddr, au8Tmp, u16XSizeWords * 4); + + /* Program the addresses of the input operands. + */ + nm_write_reg(BIGINT_ADDR_X, u32XAddr); + nm_write_reg(BIGINT_ADDR_E, u32EAddr); + nm_write_reg(BIGINT_ADDR_M, u32MAddr); + nm_write_reg(BIGINT_ADDR_R, u32RAddr); + + /* Mprime. + */ + nm_write_reg(BIGINT_M_PRIME,u32Mprime); + + /* Length. + */ + u32Reg = (u16XSizeWords & 0xFF); + u32Reg += ((u16ESizeWords & 0xFF) << 8); + u32Reg += (u8EMswBits << 16); + nm_write_reg(BIGINT_LENGTH,u32Reg); + + /* CTRL Register. + */ + u32Reg = nm_read_reg(BIGINT_MISC_CTRL); + u32Reg ^= BIGINT_MISC_CTRL_CTL_START; + u32Reg |= BIGINT_MISC_CTRL_CTL_FORCE_BARRETT; + //u32Reg |= BIGINT_MISC_CTRL_CTL_M_PRIME_VALID; +#if ENABLE_FLIPPING == 0 + u32Reg |= BIGINT_MISC_CTRL_CTL_MSW_FIRST; +#endif + nm_write_reg(BIGINT_MISC_CTRL,u32Reg); + + /* Wait for computation to complete. */ + while(1) + { + u32Reg = nm_read_reg(BIGINT_IRQ_STS); + if(u32Reg & BIGINT_IRQ_STS_DONE) + { + break; + } + } + nm_write_reg(BIGINT_IRQ_STS,0); + m2m_memset(au8Tmp, 0, sizeof(au8Tmp)); + nm_read_block(u32RAddr, au8Tmp, u16RSize); + FlipBuffer(au8Tmp, pu8R, u16RSize); +} + + + +#define MD5_DIGEST_SIZE (16) +#define SHA1_DIGEST_SIZE (20) + +static const uint8 au8TEncodingMD5[] = +{ + 0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, + 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05, 0x05, 0x00, + 0x04 +}; +/*!< Fixed part of the Encoding T for the MD5 hash algorithm. +*/ + + +static const uint8 au8TEncodingSHA1[] = +{ + 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x0E, + 0x03, 0x02, 0x1A, 0x05, 0x00, 0x04 +}; +/*!< Fixed part of the Encoding T for the SHA-1 hash algorithm. +*/ + + +static const uint8 au8TEncodingSHA2[] = +{ + 0x30, 0x31, 0x30, 0x0D, 0x06, 0x09, 0x60, 0x86, + 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, + 0x00, 0x04 +}; +/*!< Fixed part of the Encoding T for the SHA-2 hash algorithm. +*/ + + +sint8 m2m_crypto_rsa_sign_verify(uint8 *pu8N, uint16 u16NSize, uint8 *pu8E, uint16 u16ESize, uint8 *pu8SignedMsgHash, + uint16 u16HashLength, uint8 *pu8RsaSignature) +{ + sint8 s8Ret = M2M_RSA_SIGN_FAIL; + + if((pu8N != NULL) && (pu8E != NULL) && (pu8RsaSignature != NULL) && (pu8SignedMsgHash != NULL)) + { + uint16 u16TLength, u16TEncodingLength; + uint8 *pu8T; + uint8 au8EM[512]; + + /* Selection of correct T Encoding based on the hash size. + */ + if(u16HashLength == MD5_DIGEST_SIZE) + { + pu8T = (uint8*)au8TEncodingMD5; + u16TEncodingLength = sizeof(au8TEncodingMD5); + } + else if(u16HashLength == SHA1_DIGEST_SIZE) + { + pu8T = (uint8*)au8TEncodingSHA1; + u16TEncodingLength = sizeof(au8TEncodingSHA1); + } + else + { + pu8T = (uint8*)au8TEncodingSHA2; + u16TEncodingLength = sizeof(au8TEncodingSHA2); + } + u16TLength = u16TEncodingLength + 1 + u16HashLength; + + /* If emLen < tLen + 11. + */ + if(u16NSize >= (u16TLength + 11)) + { + uint32 u32PSLength,u32Idx = 0; + + /* + RSA verification + */ + BigInt_ModExp(pu8RsaSignature, u16NSize, pu8E, u16ESize, pu8N, u16NSize, au8EM, u16NSize); + + u32PSLength = u16NSize - u16TLength - 3; + + /* + The calculated EM must match the following pattern. + *======*======*======*======*======* + * 0x00 || 0x01 || PS || 0x00 || T * + *======*======*======*======*======* + Where PS is all 0xFF + T is defined based on the hash algorithm. + */ + if((au8EM[0] == 0x00) && (au8EM[1] == 0x01)) + { + for(u32Idx = 2; au8EM[u32Idx] == 0xFF; u32Idx ++); + if(u32Idx == (u32PSLength + 2)) + { + if(au8EM[u32Idx ++] == 0x00) + { + if(!m2m_memcmp(&au8EM[u32Idx], pu8T, u16TEncodingLength)) + { + u32Idx += u16TEncodingLength; + if(au8EM[u32Idx ++] == u16HashLength) + s8Ret = m2m_memcmp(&au8EM[u32Idx], pu8SignedMsgHash, u16HashLength); + } + } + } + } + } + } + return s8Ret; +} + + +sint8 m2m_crypto_rsa_sign_gen(uint8 *pu8N, uint16 u16NSize, uint8 *pu8d, uint16 u16dSize, uint8 *pu8SignedMsgHash, + uint16 u16HashLength, uint8 *pu8RsaSignature) +{ + sint8 s8Ret = M2M_RSA_SIGN_FAIL; + + if((pu8N != NULL) && (pu8d != NULL) && (pu8RsaSignature != NULL) && (pu8SignedMsgHash != NULL)) + { + uint16 u16TLength, u16TEncodingLength; + uint8 *pu8T; + uint8 au8EM[512]; + + /* Selection of correct T Encoding based on the hash size. + */ + if(u16HashLength == MD5_DIGEST_SIZE) + { + pu8T = (uint8*)au8TEncodingMD5; + u16TEncodingLength = sizeof(au8TEncodingMD5); + } + else if(u16HashLength == SHA1_DIGEST_SIZE) + { + pu8T = (uint8*)au8TEncodingSHA1; + u16TEncodingLength = sizeof(au8TEncodingSHA1); + } + else + { + pu8T = (uint8*)au8TEncodingSHA2; + u16TEncodingLength = sizeof(au8TEncodingSHA2); + } + u16TLength = u16TEncodingLength + 1 + u16HashLength; + + /* If emLen < tLen + 11. + */ + if(u16NSize >= (u16TLength + 11)) + { + uint16 u16PSLength = 0; + uint16 u16Offset = 0; + + /* + The calculated EM must match the following pattern. + *======*======*======*======*======* + * 0x00 || 0x01 || PS || 0x00 || T * + *======*======*======*======*======* + Where PS is all 0xFF + T is defined based on the hash algorithm. + */ + au8EM[u16Offset ++] = 0; + au8EM[u16Offset ++] = 1; + u16PSLength = u16NSize - u16TLength - 3; + m2m_memset(&au8EM[u16Offset], 0xFF, u16PSLength); + u16Offset += u16PSLength; + au8EM[u16Offset ++] = 0; + m2m_memcpy(&au8EM[u16Offset], pu8T, u16TEncodingLength); + u16Offset += u16TEncodingLength; + au8EM[u16Offset ++] = u16HashLength; + m2m_memcpy(&au8EM[u16Offset], pu8SignedMsgHash, u16HashLength); + + /* + RSA Signature Generation + */ + BigInt_ModExp(au8EM, u16NSize, pu8d, u16dSize, pu8N, u16NSize, pu8RsaSignature, u16NSize); + s8Ret = M2M_RSA_SIGN_OK; + } + } + return s8Ret; +} + +#endif /* CONF_CRYPTO */ + +#ifdef CONF_CRYPTO_SOFT + +typedef struct { + tpfAppCryproCb pfAppCryptoCb; + uint8 * pu8Digest; + uint8 * pu8Rsa; + uint8 u8CryptoBusy; +}tstrCryptoCtxt; + +typedef struct { + uint8 au8N[M2M_MAX_RSA_LEN]; + uint8 au8E[M2M_MAX_RSA_LEN]; + uint8 au8Hash[M2M_SHA256_DIGEST_LEN]; + uint16 u16Nsz; + uint16 u16Esz; + uint16 u16Hsz; + uint8 _pad16_[2]; +}tstrRsaPayload; + +static tstrCryptoCtxt gstrCryptoCtxt; + + +/** +* @fn m2m_crypto_cb(uint8 u8OpCode, uint16 u16DataSize, uint32 u32Addr) +* @brief WiFi call back function +* @param [in] u8OpCode +* HIF Opcode type. +* @param [in] u16DataSize +* HIF data length. +* @param [in] u32Addr +* HIF address. +* @author +* @date +* @version 1.0 +*/ +static void m2m_crypto_cb(uint8 u8OpCode, uint16 u16DataSize, uint32 u32Addr) +{ + sint8 ret = M2M_SUCCESS; + gstrCryptoCtxt.u8CryptoBusy = 0; + if(u8OpCode == M2M_CRYPTO_RESP_SHA256_INIT) + { + tstrM2mSha256Ctxt strCtxt; + if (hif_receive(u32Addr, (uint8*) &strCtxt,sizeof(tstrM2mSha256Ctxt), 0) == M2M_SUCCESS) + { + tstrCyptoResp strResp; + if(hif_receive(u32Addr + sizeof(tstrM2mSha256Ctxt), (uint8*) &strResp,sizeof(tstrCyptoResp), 1) == M2M_SUCCESS) + { + if (gstrCryptoCtxt.pfAppCryptoCb) + gstrCryptoCtxt.pfAppCryptoCb(u8OpCode,&strResp,&strCtxt); + } + } + } + else if(u8OpCode == M2M_CRYPTO_RESP_SHA256_UPDATE) + { + tstrM2mSha256Ctxt strCtxt; + if (hif_receive(u32Addr, (uint8*) &strCtxt,sizeof(tstrM2mSha256Ctxt), 0) == M2M_SUCCESS) + { + tstrCyptoResp strResp; + if (hif_receive(u32Addr + sizeof(tstrM2mSha256Ctxt), (uint8*) &strResp,sizeof(tstrCyptoResp), 1) == M2M_SUCCESS) + { + if (gstrCryptoCtxt.pfAppCryptoCb) + gstrCryptoCtxt.pfAppCryptoCb(u8OpCode,&strResp,&strCtxt); + } + } + + } + else if(u8OpCode == M2M_CRYPTO_RESP_SHA256_FINSIH) + { + tstrCyptoResp strResp; + if (hif_receive(u32Addr + sizeof(tstrM2mSha256Ctxt), (uint8*) &strResp,sizeof(tstrCyptoResp), 0) == M2M_SUCCESS) + { + if (hif_receive(u32Addr + sizeof(tstrM2mSha256Ctxt) + sizeof(tstrCyptoResp), (uint8*)gstrCryptoCtxt.pu8Digest,M2M_SHA256_DIGEST_LEN, 1) == M2M_SUCCESS) + { + if (gstrCryptoCtxt.pfAppCryptoCb) + gstrCryptoCtxt.pfAppCryptoCb(u8OpCode,&strResp,gstrCryptoCtxt.pu8Digest); + + } + } + } + else if(u8OpCode == M2M_CRYPTO_RESP_RSA_SIGN_GEN) + { + tstrCyptoResp strResp; + if (hif_receive(u32Addr + sizeof(tstrRsaPayload), (uint8*)&strResp,sizeof(tstrCyptoResp), 0) == M2M_SUCCESS) + { + if (hif_receive(u32Addr + sizeof(tstrRsaPayload) + sizeof(tstrCyptoResp), (uint8*)gstrCryptoCtxt.pu8Rsa,M2M_MAX_RSA_LEN, 0) == M2M_SUCCESS) + { + if (gstrCryptoCtxt.pfAppCryptoCb) + gstrCryptoCtxt.pfAppCryptoCb(u8OpCode,&strResp,gstrCryptoCtxt.pu8Rsa); + } + } + } + else if(u8OpCode == M2M_CRYPTO_RESP_RSA_SIGN_VERIFY) + { + tstrCyptoResp strResp; + if (hif_receive(u32Addr + sizeof(tstrRsaPayload), (uint8*)&strResp,sizeof(tstrCyptoResp), 1) == M2M_SUCCESS) + { + if (gstrCryptoCtxt.pfAppCryptoCb) + gstrCryptoCtxt.pfAppCryptoCb(u8OpCode,&strResp,NULL); + } + } + else + { + M2M_ERR("u8Code %d ??\n",u8OpCode); + } + +} +/*! +@fn \ + sint8 m2m_crypto_init(); + +@brief crypto initialization + +@param[in] pfAppCryproCb + +*/ +sint8 m2m_crypto_init(tpfAppCryproCb pfAppCryproCb) +{ + sint8 ret = M2M_ERR_FAIL; + m2m_memset((uint8*)&gstrCryptoCtxt,0,sizeof(tstrCryptoCtxt)); + if(pfAppCryproCb != NULL) + { + gstrCryptoCtxt.pfAppCryptoCb = pfAppCryproCb; + ret = hif_register_cb(M2M_REQ_GROUP_CRYPTO,m2m_crypto_cb); + } + return ret; +} +/*! +@fn \ + sint8 m2m_sha256_hash_init(tstrM2mSha256Ctxt *psha256Ctxt); + +@brief SHA256 hash initialization + +@param[in] psha256Ctxt + Pointer to a sha256 context allocated by the caller. +*/ +sint8 m2m_crypto_sha256_hash_init(tstrM2mSha256Ctxt *psha256Ctxt) +{ + sint8 ret = M2M_ERR_FAIL; + if((psha256Ctxt != NULL)&&(!gstrCryptoCtxt.u8CryptoBusy)) + { + ret = hif_send(M2M_REQ_GROUP_CRYPTO,M2M_CRYPTO_REQ_SHA256_INIT|M2M_REQ_DATA_PKT,(uint8*)psha256Ctxt,sizeof(tstrM2mSha256Ctxt),NULL,0,0); + } + return ret; +} + + +/*! +@fn \ + sint8 m2m_sha256_hash_update(tstrM2mSha256Ctxt *psha256Ctxt, uint8 *pu8Data, uint16 u16DataLength); + +@brief SHA256 hash update + +@param [in] psha256Ctxt + Pointer to the sha256 context. + +@param [in] pu8Data + Buffer holding the data submitted to the hash. + +@param [in] u16DataLength + Size of the data bufefr in bytes. +*/ +sint8 m2m_crypto_sha256_hash_update(tstrM2mSha256Ctxt *psha256Ctxt, uint8 *pu8Data, uint16 u16DataLength) +{ + sint8 ret = M2M_ERR_FAIL; + if((!gstrCryptoCtxt.u8CryptoBusy) && (psha256Ctxt != NULL) && (pu8Data != NULL) && (u16DataLength < M2M_SHA256_MAX_DATA)) + { + ret = hif_send(M2M_REQ_GROUP_CRYPTO,M2M_CRYPTO_REQ_SHA256_UPDATE|M2M_REQ_DATA_PKT,(uint8*)psha256Ctxt,sizeof(tstrM2mSha256Ctxt),pu8Data,u16DataLength,sizeof(tstrM2mSha256Ctxt) + sizeof(tstrCyptoResp)); + } + return ret; + +} + + +/*! +@fn \ + sint8 m2m_sha256_hash_finish(tstrM2mSha256Ctxt *psha256Ctxt, uint8 *pu8Sha256Digest); + +@brief SHA256 hash finalization + +@param[in] psha256Ctxt + Pointer to a sha256 context allocated by the caller. + +@param [in] pu8Sha256Digest + Buffer allocated by the caller which will hold the resultant SHA256 Digest. It must be allocated no less than M2M_SHA256_DIGEST_LEN. +*/ +sint8 m2m_crypto_sha256_hash_finish(tstrM2mSha256Ctxt *psha256Ctxt, uint8 *pu8Sha256Digest) +{ + sint8 ret = M2M_ERR_FAIL; + if((!gstrCryptoCtxt.u8CryptoBusy) && (psha256Ctxt != NULL) && (pu8Sha256Digest != NULL)) + { + gstrCryptoCtxt.pu8Digest = pu8Sha256Digest; + ret = hif_send(M2M_REQ_GROUP_CRYPTO,M2M_CRYPTO_REQ_SHA256_FINSIH|M2M_REQ_DATA_PKT,(uint8*)psha256Ctxt,sizeof(tstrM2mSha256Ctxt),NULL,0,0); + } + return ret; +} + + + + +/*! +@fn \ + sint8 m2m_rsa_sign_verify(uint8 *pu8N, uint16 u16NSize, uint8 *pu8E, uint16 u16ESize, uint8 *pu8SignedMsgHash, \ + uint16 u16HashLength, uint8 *pu8RsaSignature); + +@brief RSA Signature Verification + + The function shall request the RSA Signature verification from the WINC Firmware for the given message. The signed message shall be + compressed to the corresponding hash algorithm before calling this function. + The hash type is identified by the given hash length. For example, if the hash length is 32 bytes, then it is SHA256. + +@param[in] pu8N + RSA Key modulus n. + +@param[in] u16NSize + Size of the RSA modulus n in bytes. + +@param[in] pu8E + RSA public exponent. + +@param[in] u16ESize + Size of the RSA public exponent in bytes. + +@param[in] pu8SignedMsgHash + The hash digest of the signed message. + +@param[in] u16HashLength + The length of the hash digest. + +@param[out] pu8RsaSignature + Signature value to be verified. +*/ + + +sint8 m2m_crypto_rsa_sign_verify(uint8 *pu8N, uint16 u16NSize, uint8 *pu8E, uint16 u16ESize, uint8 *pu8SignedMsgHash, + uint16 u16HashLength, uint8 *pu8RsaSignature) +{ + sint8 ret = M2M_ERR_FAIL; + if((!gstrCryptoCtxt.u8CryptoBusy) && (pu8N != NULL) && (pu8E != NULL) && (pu8RsaSignature != NULL) && (pu8SignedMsgHash != NULL) + && (u16NSize != 0) && (u16ESize != 0) && (u16HashLength != 0) && (pu8RsaSignature != NULL) ) + + { + tstrRsaPayload strRsa = {0}; + + m2m_memcpy(strRsa.au8N,pu8N,u16NSize); + m2m_memcpy(strRsa.au8E,pu8E,u16ESize); + m2m_memcpy(strRsa.au8Hash,pu8SignedMsgHash,u16HashLength); + + strRsa.u16Esz = u16ESize; + strRsa.u16Hsz = u16HashLength; + strRsa.u16Nsz = u16NSize; + + ret = hif_send(M2M_REQ_GROUP_CRYPTO,M2M_CRYPTO_REQ_RSA_SIGN_VERIFY|M2M_REQ_DATA_PKT,(uint8*)&strRsa,sizeof(tstrRsaPayload),NULL,0,0); + + } + return ret; +} + + +/*! +@fn \ + sint8 m2m_rsa_sign_gen(uint8 *pu8N, uint16 u16NSize, uint8 *pu8d, uint16 u16dSize, uint8 *pu8SignedMsgHash, \ + uint16 u16HashLength, uint8 *pu8RsaSignature); + +@brief RSA Signature Generation + + The function shall request the RSA Signature generation from the WINC Firmware for the given message. The signed message shall be + compressed to the corresponding hash algorithm before calling this function. + The hash type is identified by the given hash length. For example, if the hash length is 32 bytes, then it is SHA256. + +@param[in] pu8N + RSA Key modulus n. + +@param[in] u16NSize + Size of the RSA modulus n in bytes. + +@param[in] pu8d + RSA private exponent. + +@param[in] u16dSize + Size of the RSA private exponent in bytes. + +@param[in] pu8SignedMsgHash + The hash digest of the signed message. + +@param[in] u16HashLength + The length of the hash digest. + +@param[out] pu8RsaSignature + Pointer to a user buffer allocated by teh caller shall hold the generated signature. +*/ +sint8 m2m_crypto_rsa_sign_gen(uint8 *pu8N, uint16 u16NSize, uint8 *pu8d, uint16 u16dSize, uint8 *pu8SignedMsgHash, + uint16 u16HashLength, uint8 *pu8RsaSignature) +{ + sint8 ret = M2M_ERR_FAIL; + if((!gstrCryptoCtxt.u8CryptoBusy) && (pu8N != NULL) && (pu8d != NULL) && (pu8RsaSignature != NULL) && (pu8SignedMsgHash != NULL) + && (u16NSize != 0) && (u16dSize != 0) && (u16HashLength != 0) && (pu8RsaSignature != NULL)) + + { + tstrRsaPayload strRsa = {0}; + + m2m_memcpy(strRsa.au8N,pu8N,u16NSize); + m2m_memcpy(strRsa.au8E,pu8d,u16dSize); + m2m_memcpy(strRsa.au8Hash,pu8SignedMsgHash,u16HashLength); + + strRsa.u16Esz = u16dSize; + strRsa.u16Hsz = u16HashLength; + strRsa.u16Nsz = u16NSize; + + gstrCryptoCtxt.pu8Rsa = pu8RsaSignature; + ret = hif_send(M2M_REQ_GROUP_CRYPTO,M2M_CRYPTO_REQ_RSA_SIGN_GEN|M2M_REQ_DATA_PKT,(uint8*)&strRsa,sizeof(tstrRsaPayload),NULL,0,0); + + } + return ret; +} + +#endif diff --git a/src/winc1500/src/m2m_hif.c b/src/winc1500/src/m2m_hif.c index 952a2e48b..ca7448c22 100644 --- a/src/winc1500/src/m2m_hif.c +++ b/src/winc1500/src/m2m_hif.c @@ -77,7 +77,9 @@ static volatile uint8 gu8Interrupt = 0; tpfHifCallBack pfWifiCb = NULL; /*!< pointer to Wi-Fi call back function */ tpfHifCallBack pfIpCb = NULL; /*!< pointer to Socket call back function */ tpfHifCallBack pfOtaCb = NULL; /*!< pointer to OTA call back function */ +tpfHifCallBack pfSigmaCb = NULL; tpfHifCallBack pfHifCb = NULL; +tpfHifCallBack pfCryptoCb = NULL; static void isr(void) { @@ -202,7 +204,7 @@ sint8 hif_chip_sleep(void) { gu8ChipSleep--; } - + if(gu8ChipSleep == 0) { if((gu8ChipMode == M2M_PS_DEEP_AUTOMATIC)||(gu8ChipMode == M2M_PS_MANUAL)) @@ -245,7 +247,7 @@ sint8 hif_init(void * arg) gu8Interrupt = 0; nm_bsp_register_isr(isr); - hif_register_cb(M2M_REQ_GRP_HIF,m2m_hif_cb); + hif_register_cb(M2M_REQ_GROUP_HIF,m2m_hif_cb); return M2M_SUCCESS; } @@ -370,11 +372,17 @@ sint8 hif_send(uint8 u8Gid,uint8 u8Opcode,uint8 *pu8CtrlBuf,uint16 u16CtrlBufSiz u32CurrAddr = dma_addr; strHif.u16Length=NM_BSP_B_L_16(strHif.u16Length); ret = nm_write_block(u32CurrAddr, (uint8*)&strHif, M2M_HIF_HDR_OFFSET); + #ifdef CONF_WINC_USE_I2C + nm_bsp_sleep(1); + #endif if(M2M_SUCCESS != ret) goto ERR1; u32CurrAddr += M2M_HIF_HDR_OFFSET; if(pu8CtrlBuf != NULL) { ret = nm_write_block(u32CurrAddr, pu8CtrlBuf, u16CtrlBufSize); + #ifdef CONF_WINC_USE_I2C + nm_bsp_sleep(1); + #endif if(M2M_SUCCESS != ret) goto ERR1; u32CurrAddr += u16CtrlBufSize; } @@ -382,6 +390,9 @@ sint8 hif_send(uint8 u8Gid,uint8 u8Opcode,uint8 *pu8CtrlBuf,uint16 u16CtrlBufSiz { u32CurrAddr += (u16DataOffset - u16CtrlBufSize); ret = nm_write_block(u32CurrAddr, pu8DataBuf, u16DataSize); + #ifdef CONF_WINC_USE_I2C + nm_bsp_sleep(1); + #endif if(M2M_SUCCESS != ret) goto ERR1; u32CurrAddr += u16DataSize; } @@ -426,7 +437,7 @@ static sint8 hif_isr(void) ret = hif_chip_wake(); if(ret == M2M_SUCCESS) { - ret = nm_read_reg_with_ret(0x1070, ®); + ret = nm_read_reg_with_ret(WIFI_HOST_RCV_CTRL_0, ®); if(M2M_SUCCESS == ret) { if(reg & 0x1) /* New interrupt has been received */ @@ -435,19 +446,9 @@ static sint8 hif_isr(void) nm_bsp_interrupt_ctrl(0); /*Clearing RX interrupt*/ - ret = nm_read_reg_with_ret(WIFI_HOST_RCV_CTRL_0,®); - if(ret != M2M_SUCCESS)goto ERR1; reg &= ~(1<<0); ret = nm_write_reg(WIFI_HOST_RCV_CTRL_0,reg); if(ret != M2M_SUCCESS)goto ERR1; - /* read the rx size */ - ret = nm_read_reg_with_ret(WIFI_HOST_RCV_CTRL_0, ®); - if(M2M_SUCCESS != ret) - { - M2M_ERR("(hif) WIFI_HOST_RCV_CTRL_0 bus fail\n"); - nm_bsp_interrupt_ctrl(1); - goto ERR1; - } gu8HifSizeDone = 0; size = (uint16)((reg >> 2) & 0xfff); if (size > 0) { @@ -482,22 +483,32 @@ static sint8 hif_isr(void) } } - if(M2M_REQ_GRP_WIFI == strHif.u8Gid) + if(M2M_REQ_GROUP_WIFI == strHif.u8Gid) { if(pfWifiCb) pfWifiCb(strHif.u8Opcode,strHif.u16Length - M2M_HIF_HDR_OFFSET, address + M2M_HIF_HDR_OFFSET); } - else if(M2M_REQ_GRP_IP == strHif.u8Gid) + else if(M2M_REQ_GROUP_IP == strHif.u8Gid) { if(pfIpCb) pfIpCb(strHif.u8Opcode,strHif.u16Length - M2M_HIF_HDR_OFFSET, address + M2M_HIF_HDR_OFFSET); } - else if(M2M_REQ_GRP_OTA == strHif.u8Gid) + else if(M2M_REQ_GROUP_OTA == strHif.u8Gid) { if(pfOtaCb) pfOtaCb(strHif.u8Opcode,strHif.u16Length - M2M_HIF_HDR_OFFSET, address + M2M_HIF_HDR_OFFSET); } + else if(M2M_REQ_GROUP_CRYPTO == strHif.u8Gid) + { + if(pfCryptoCb) + pfCryptoCb(strHif.u8Opcode,strHif.u16Length - M2M_HIF_HDR_OFFSET, address + M2M_HIF_HDR_OFFSET); + } + else if(M2M_REQ_GROUP_SIGMA == strHif.u8Gid) + { + if(pfSigmaCb) + pfSigmaCb(strHif.u8Opcode,strHif.u16Length - M2M_HIF_HDR_OFFSET, address + M2M_HIF_HDR_OFFSET); + } else { M2M_ERR("(hif) invalid group ID\n"); @@ -596,13 +607,15 @@ sint8 hif_receive(uint32 u32Addr, uint8 *pu8Buf, uint16 u16Sz, uint8 isDone) if(isDone) { gu8HifSizeDone = 1; - + /* set RX done */ ret = hif_set_rx_done(); } - - ret = M2M_ERR_FAIL; - M2M_ERR(" hif_receive: Invalid argument\n"); + else + { + ret = M2M_ERR_FAIL; + M2M_ERR(" hif_receive: Invalid argument\n"); + } goto ERR1; } @@ -614,9 +627,6 @@ sint8 hif_receive(uint32 u32Addr, uint8 *pu8Buf, uint16 u16Sz, uint8 isDone) ret = nm_read_reg_with_ret(WIFI_HOST_RCV_CTRL_1,&address); if(ret != M2M_SUCCESS)goto ERR1; - /* Receive the payload */ - ret = nm_read_block(u32Addr, pu8Buf, u16Sz); - if(ret != M2M_SUCCESS)goto ERR1; if(u16Sz > size) { @@ -630,9 +640,13 @@ sint8 hif_receive(uint32 u32Addr, uint8 *pu8Buf, uint16 u16Sz, uint8 isDone) M2M_ERR("APP Requested Address beyond the recived buffer address and length\n"); goto ERR1; } + + /* Receive the payload */ + ret = nm_read_block(u32Addr, pu8Buf, u16Sz); + if(ret != M2M_SUCCESS)goto ERR1; /* check if this is the last packet */ - if((((address+size) - (u32Addr+u16Sz)) <= 0) || isDone) + if((((address + size) - (u32Addr + u16Sz)) <= 0) || isDone) { gu8HifSizeDone = 1; @@ -661,18 +675,24 @@ sint8 hif_register_cb(uint8 u8Grp,tpfHifCallBack fn) sint8 ret = M2M_SUCCESS; switch(u8Grp) { - case M2M_REQ_GRP_IP: + case M2M_REQ_GROUP_IP: pfIpCb = fn; break; - case M2M_REQ_GRP_WIFI: + case M2M_REQ_GROUP_WIFI: pfWifiCb = fn; break; - case M2M_REQ_GRP_OTA: + case M2M_REQ_GROUP_OTA: pfOtaCb = fn; break; - case M2M_REQ_GRP_HIF: + case M2M_REQ_GROUP_HIF: pfHifCb = fn; break; + case M2M_REQ_GROUP_CRYPTO: + pfCryptoCb = fn; + break; + case M2M_REQ_GROUP_SIGMA: + pfSigmaCb = fn; + break; default: M2M_ERR("GRp ? %d\n",u8Grp); ret = M2M_ERR_FAIL; diff --git a/src/winc1500/src/m2m_ota.c b/src/winc1500/src/m2m_ota.c index 4cdf321b8..1c7725c44 100644 --- a/src/winc1500/src/m2m_ota.c +++ b/src/winc1500/src/m2m_ota.c @@ -44,7 +44,6 @@ /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* INCLUDES *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ - #include "common/include/nm_common.h" #include "driver/include/m2m_types.h" #include "driver/include/m2m_ota.h" @@ -140,7 +139,7 @@ NMI_API sint8 m2m_ota_init(tpfOtaUpdateCb pfOtaUpdateCb, tpfOtaNotifCb pfOtaNot M2M_ERR("Invaild Ota notify cb\n"); } - hif_register_cb(M2M_REQ_GRP_OTA,m2m_ota_cb); + hif_register_cb(M2M_REQ_GROUP_OTA,m2m_ota_cb); return ret; } @@ -164,7 +163,7 @@ NMI_API sint8 m2m_ota_notif_set_url(uint8 * u8Url) /*Todo: we may change it to data pkt but we need to give it higer priority but the priorty is not implemnted yet in data pkt */ - ret = hif_send(M2M_REQ_GRP_OTA,M2M_OTA_REQ_START_UPDATE,u8Url,u16UrlSize,NULL,0,0); + ret = hif_send(M2M_REQ_GROUP_OTA,M2M_OTA_REQ_START_UPDATE,u8Url,u16UrlSize,NULL,0,0); return ret; } @@ -182,7 +181,7 @@ NMI_API sint8 m2m_ota_notif_set_url(uint8 * u8Url) NMI_API sint8 m2m_ota_notif_check_for_update(void) { sint8 ret = M2M_SUCCESS; - ret = hif_send(M2M_REQ_GRP_OTA,M2M_OTA_REQ_NOTIF_CHECK_FOR_UPDATE,NULL,0,NULL,0,0); + ret = hif_send(M2M_REQ_GROUP_OTA,M2M_OTA_REQ_NOTIF_CHECK_FOR_UPDATE,NULL,0,NULL,0,0); return ret; } @@ -202,7 +201,7 @@ NMI_API sint8 m2m_ota_notif_check_for_update(void) NMI_API sint8 m2m_ota_notif_sched(uint32 u32Period) { sint8 ret = M2M_SUCCESS; - ret = hif_send(M2M_REQ_GRP_OTA,M2M_OTA_REQ_NOTIF_CHECK_FOR_UPDATE,NULL,0,NULL,0,0); + ret = hif_send(M2M_REQ_GROUP_OTA,M2M_OTA_REQ_NOTIF_CHECK_FOR_UPDATE,NULL,0,NULL,0,0); return ret; } @@ -227,7 +226,7 @@ NMI_API sint8 m2m_ota_start_update(uint8 * u8DownloadUrl) /*Todo: we may change it to data pkt but we need to give it higer priority but the priorty is not implemnted yet in data pkt */ - ret = hif_send(M2M_REQ_GRP_OTA,M2M_OTA_REQ_START_UPDATE,u8DownloadUrl,u16DurlSize,NULL,0,0); + ret = hif_send(M2M_REQ_GROUP_OTA,M2M_OTA_REQ_START_UPDATE,u8DownloadUrl,u16DurlSize,NULL,0,0); return ret; } @@ -245,7 +244,7 @@ NMI_API sint8 m2m_ota_start_update(uint8 * u8DownloadUrl) NMI_API sint8 m2m_ota_rollback(void) { sint8 ret = M2M_SUCCESS; - ret = hif_send(M2M_REQ_GRP_OTA,M2M_OTA_REQ_ROLLBACK,NULL,0,NULL,0,0); + ret = hif_send(M2M_REQ_GROUP_OTA,M2M_OTA_REQ_ROLLBACK,NULL,0,NULL,0,0); return ret; } @@ -263,7 +262,28 @@ NMI_API sint8 m2m_ota_rollback(void) NMI_API sint8 m2m_ota_switch_firmware(void) { sint8 ret = M2M_SUCCESS; - ret = hif_send(M2M_REQ_GRP_OTA,M2M_OTA_REQ_SWITCH_FIRMWARE,NULL,0,NULL,0,0); + ret = hif_send(M2M_REQ_GROUP_OTA,M2M_OTA_REQ_SWITCH_FIRMWARE,NULL,0,NULL,0,0); + return ret; +} +/*! +@fn \ + NMI_API sint8 m2m_ota_get_firmware_version(tstrM2mRev * pstrRev); + +@brief + Get the OTA Firmware version. + +@return + The function SHALL return 0 for success and a negative value otherwise. +*/ +NMI_API sint8 m2m_ota_get_firmware_version(tstrM2mRev * pstrRev) +{ + sint8 ret = M2M_SUCCESS; + ret = hif_chip_wake(); + if(ret == M2M_SUCCESS) + { + ret = nm_get_ota_firmware_info(pstrRev); + hif_chip_sleep(); + } return ret; } #if 0 @@ -301,7 +321,7 @@ NMI_API sint8 m2m_ota_test(void) } printf("page %d\n", (int)page); fread(buffer,page,1,fp); - ret = hif_send(M2M_REQ_GRP_OTA,M2M_OTA_REQ_TEST|M2M_REQ_DATA_PKT,NULL,0,(uint8*)&buffer,page,0); + ret = hif_send(M2M_REQ_GROUP_OTA,M2M_OTA_REQ_TEST|M2M_REQ_DATA_PKT,NULL,0,(uint8*)&buffer,page,0); if(ret != M2M_SUCCESS) { M2M_ERR("\n"); diff --git a/src/winc1500/src/m2m_periph.c b/src/winc1500/src/m2m_periph.c index 2d529827b..6d749843c 100644 --- a/src/winc1500/src/m2m_periph.c +++ b/src/winc1500/src/m2m_periph.c @@ -67,6 +67,10 @@ static sint8 get_gpio_idx(uint8 u8GpioNum) if(u8GpioNum == M2M_PERIPH_GPIO15) { return 15; } else if(u8GpioNum == M2M_PERIPH_GPIO16) { return 16; } else if(u8GpioNum == M2M_PERIPH_GPIO18) { return 18; + } else if(u8GpioNum == M2M_PERIPH_GPIO3) { return 3; + } else if(u8GpioNum == M2M_PERIPH_GPIO4) { return 4; + } else if(u8GpioNum == M2M_PERIPH_GPIO5) { return 5; + } else if(u8GpioNum == M2M_PERIPH_GPIO6) { return 6; } else { return -2; } diff --git a/src/winc1500/src/m2m_wifi.c b/src/winc1500/src/m2m_wifi.c index e31e7d29f..25b77852d 100644 --- a/src/winc1500/src/m2m_wifi.c +++ b/src/winc1500/src/m2m_wifi.c @@ -54,8 +54,8 @@ static uint8* gau8ethRcvBuf=NULL; static uint16 gu16ethRcvBufSize ; #endif -#define CONF_MGMT +//#define CONF_MGMT #ifdef CONF_MGMT static tpfAppMonCb gpfAppMonCb = NULL; static struct _tstrMgmtCtrl @@ -147,7 +147,7 @@ static void m2m_wifi_cb(uint8 u8OpCode, uint16 u16DataSize, uint32 u32Addr) uint32 u32ConflictedIP; if(hif_receive(u32Addr, (uint8 *)&u32ConflictedIP, sizeof(u32ConflictedIP), 0) == M2M_SUCCESS) { - M2M_INFO("Conflicted IP \" %u.%u.%u.%u \" \n", + M2M_INFO("Conflicted IP \" %u.%u.%u.%u \" \n", BYTE_0(u32ConflictedIP),BYTE_1(u32ConflictedIP),BYTE_2(u32ConflictedIP),BYTE_3(u32ConflictedIP)); if (gpfAppWifiCb) gpfAppWifiCb(M2M_WIFI_RESP_IP_CONFLICT, NULL); @@ -208,31 +208,47 @@ static void m2m_wifi_cb(uint8 u8OpCode, uint16 u16DataSize, uint32 u32Addr) gpfAppWifiCb(M2M_WIFI_RESP_DEFAULT_CONNECT, &strResp); } } -#ifdef ETH_MODE - else if(u8OpCode == M2M_WIFI_RESP_ETHERNET_RX_PACKET) + + else if(u8OpCode == M2M_WIFI_RESP_GET_PRNG) + { + tstrPrng strPrng; + if(hif_receive(u32Addr, (uint8*)&strPrng,sizeof(tstrPrng), 0) == M2M_SUCCESS) { - if(hif_receive(u32Addr, rx_buf ,sizeof(tstrM2mIpRsvdPkt), 0) == M2M_SUCCESS) + if(hif_receive(u32Addr + sizeof(tstrPrng),strPrng.pu8RngBuff,strPrng.u16PrngSize, 1) == M2M_SUCCESS) + { + if(gpfAppWifiCb) + gpfAppWifiCb(M2M_WIFI_RESP_GET_PRNG,&strPrng); + } + } + } +#ifdef ETH_MODE + else if(u8OpCode == M2M_WIFI_RESP_ETHERNET_RX_PACKET) + { + uint8 u8SetRxDone; + tstrM2mIpRsvdPkt strM2mRsvd; + if(hif_receive(u32Addr, &strM2mRsvd ,sizeof(tstrM2mIpRsvdPkt), 0) == M2M_SUCCESS) { - tstrM2mIpRsvdPkt * pstrM2MIpRxPkt = (tstrM2mIpRsvdPkt*)rx_buf; tstrM2mIpCtrlBuf strM2mIpCtrlBuf; - uint16 u16Offset = pstrM2MIpRxPkt->u16PktOffset; - - strM2mIpCtrlBuf.u16RemainigDataSize = pstrM2MIpRxPkt->u16PktSz; - if((gpfAppEthCb) &&(gau8ethRcvBuf)&& (gu16ethRcvBufSize > 0)) + uint16 u16Offset = strM2mRsvd.u16PktOffset; + strM2mIpCtrlBuf.u16RemainigDataSize = strM2mRsvd.u16PktSz; + if((gpfAppEthCb) && (gau8ethRcvBuf) && (gu16ethRcvBufSize > 0)) { - while (strM2mIpCtrlBuf.u16RemainigDataSize > 0) + do { + u8SetRxDone = 1; if(strM2mIpCtrlBuf.u16RemainigDataSize > gu16ethRcvBufSize) { - strM2mIpCtrlBuf.u16DataSize = gu16ethRcvBufSize ; + u8SetRxDone = 0; + strM2mIpCtrlBuf.u16DataSize = gu16ethRcvBufSize; } else { strM2mIpCtrlBuf.u16DataSize = strM2mIpCtrlBuf.u16RemainigDataSize; } - if(hif_receive(u32Addr+u16Offset, gau8ethRcvBuf, strM2mIpCtrlBuf.u16DataSize, 0) == M2M_SUCCESS) + + if(hif_receive(u32Addr + u16Offset, gau8ethRcvBuf, strM2mIpCtrlBuf.u16DataSize, u8SetRxDone) == M2M_SUCCESS) { - strM2mIpCtrlBuf.u16RemainigDataSize -= strM2mIpCtrlBuf.u16DataSize; + strM2mIpCtrlBuf.u16RemainigDataSize -= strM2mIpCtrlBuf.u16DataSize; u16Offset += strM2mIpCtrlBuf.u16DataSize; gpfAppEthCb(M2M_WIFI_RESP_ETHERNET_RX_PACKET, gau8ethRcvBuf, &(strM2mIpCtrlBuf)); } @@ -240,15 +256,15 @@ static void m2m_wifi_cb(uint8 u8OpCode, uint16 u16DataSize, uint32 u32Addr) { break; } - } + }while (strM2mIpCtrlBuf.u16RemainigDataSize > 0); } } } -#endif - +#endif /* ETH_MODE */ #ifdef CONF_MGMT else if(u8OpCode == M2M_WIFI_RESP_WIFI_RX_PACKET) { + tstrM2MWifiRxPacketInfo strRxPacketInfo; if(u16DataSize >= sizeof(tstrM2MWifiRxPacketInfo)) { if(hif_receive(u32Addr, (uint8*)&strRxPacketInfo, sizeof(tstrM2MWifiRxPacketInfo), 0) == M2M_SUCCESS) @@ -261,10 +277,7 @@ static void m2m_wifi_cb(uint8 u8OpCode, uint16 u16DataSize, uint32 u32Addr) u16DataSize = gstrMgmtCtrl.u16Sz; } u32Addr += sizeof(tstrM2MWifiRxPacketInfo) + gstrMgmtCtrl.u16Offset; - if(hif_receive(u32Addr , gstrMgmtCtrl.pu8Buf, u16DataSize, 1) != M2M_SUCCESS) - { - u16DataSize = 0; - } + if(hif_receive(u32Addr , gstrMgmtCtrl.pu8Buf, u16DataSize, 1) != M2M_SUCCESS) return; } if(gpfAppMonCb) gpfAppMonCb(&strRxPacketInfo, gstrMgmtCtrl.pu8Buf,u16DataSize); @@ -409,7 +422,9 @@ static sint8 m2m_validate_scan_options(tstrM2MScanOption* ptstrM2MScanOption) sint8 m2m_wifi_init(tstrWifiInitParam * param) { + tstrM2mRev strtmp; sint8 ret = M2M_SUCCESS; + uint8 u8WifiMode = M2M_WIFI_MODE_NORMAL; if(param == NULL) { ret = M2M_ERR_FAIL; @@ -417,25 +432,36 @@ sint8 m2m_wifi_init(tstrWifiInitParam * param) } gpfAppWifiCb = param->pfAppWifiCb; - + #ifdef ETH_MODE - gpfAppEthCb = param->strEthInitParam.pfAppEthCb; + gpfAppEthCb = param->strEthInitParam.pfAppEthCb; gau8ethRcvBuf = param->strEthInitParam.au8ethRcvBuf; gu16ethRcvBufSize = param->strEthInitParam.u16ethRcvBufSize; -#endif + u8WifiMode = param->strEthInitParam.u8EthernetEnable; +#endif /* ETH_MODE */ #ifdef CONF_MGMT gpfAppMonCb = param->pfAppMonCb; #endif gu8scanInProgress = 0; /* Apply device specific initialization. */ - ret = nm_drv_init(NULL); + ret = nm_drv_init(&u8WifiMode); if(ret != M2M_SUCCESS) goto _EXIT0; /* Initialize host interface module */ ret = hif_init(NULL); if(ret != M2M_SUCCESS) goto _EXIT1; - hif_register_cb(M2M_REQ_GRP_WIFI,m2m_wifi_cb); + hif_register_cb(M2M_REQ_GROUP_WIFI,m2m_wifi_cb); + + ret = nm_get_firmware_info(&strtmp); + + M2M_INFO("Firmware ver : %u.%u.%u\n", strtmp.u8FirmwareMajor, strtmp.u8FirmwareMinor, strtmp.u8FirmwarePatch); + M2M_INFO("Min driver ver : %u.%u.%u\n", strtmp.u8DriverMajor, strtmp.u8DriverMinor, strtmp.u8DriverPatch); + M2M_INFO("Curr driver ver: %u.%u.%u\n", M2M_DRIVER_VERSION_MAJOR_NO, M2M_DRIVER_VERSION_MINOR_NO, M2M_DRIVER_VERSION_PATCH_NO); + if(M2M_ERR_FW_VER_MISMATCH == ret) + { + M2M_ERR("Mismatch Firmawre Version\n"); + } goto _EXIT0; @@ -463,7 +489,7 @@ sint8 m2m_wifi_handle_events(void * arg) sint8 m2m_wifi_default_connect(void) { - return hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_DEFAULT_CONNECT, NULL, 0,NULL, 0,0); + return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_DEFAULT_CONNECT, NULL, 0,NULL, 0,0); } sint8 m2m_wifi_connect(char *pcSsid, uint8 u8SsidLen, uint8 u8SecType, void *pvAuthInfo, uint16 u16Ch) @@ -484,6 +510,21 @@ sint8 m2m_wifi_connect_sc(char *pcSsid, uint8 u8SsidLen, uint8 u8SecType, void * ret = M2M_ERR_FAIL; goto ERR1; } + if((u8SecType == M2M_WIFI_SEC_WPA_PSK) && (m2m_strlen(pvAuthInfo) == (M2M_MAX_PSK_LEN-1))) + { + uint8 i = 0; + uint8* pu8Psk = (uint8*)pvAuthInfo; + while(i < (M2M_MAX_PSK_LEN-1)) + { + if(pu8Psk[i]<'0' || (pu8Psk[i]>'9' && pu8Psk[i] < 'A')|| (pu8Psk[i]>'F' && pu8Psk[i] < 'a') || pu8Psk[i] > 'f') + { + M2M_ERR("Invalid Key\n"); + ret = M2M_ERR_FAIL; + goto ERR1; + } + i++; + } + } } if((u8SsidLen<=0)||(u8SsidLen>=M2M_MAX_SSID_LEN)) { @@ -562,7 +603,7 @@ sint8 m2m_wifi_connect_sc(char *pcSsid, uint8 u8SsidLen, uint8 u8SecType, void * goto ERR1; } - ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_CONNECT, (uint8*)&strConnect, sizeof(tstrM2mWifiConnect),NULL, 0,0); + ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_CONNECT, (uint8*)&strConnect, sizeof(tstrM2mWifiConnect),NULL, 0,0); ERR1: return ret; @@ -570,13 +611,13 @@ ERR1: sint8 m2m_wifi_disconnect(void) { - return hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_DISCONNECT, NULL, 0, NULL, 0,0); + return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_DISCONNECT, NULL, 0, NULL, 0,0); } sint8 m2m_wifi_set_mac_address(uint8 au8MacAddress[6]) { tstrM2mSetMacAddress strTmp; m2m_memcpy((uint8*) strTmp.au8Mac, (uint8*) au8MacAddress, 6); - return hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SET_MAC_ADDRESS, + return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_MAC_ADDRESS, (uint8*) &strTmp, sizeof(tstrM2mSetMacAddress), NULL, 0,0); } @@ -588,7 +629,7 @@ sint8 m2m_wifi_set_static_ip(tstrM2MIPConfig * pstrStaticIPConf) pstrStaticIPConf->u32StaticIP); pstrStaticIPConf->u32SubnetMask = NM_BSP_B_L_32( pstrStaticIPConf->u32SubnetMask); - return hif_send(M2M_REQ_GRP_IP, M2M_IP_REQ_STATIC_IP_CONF, + return hif_send(M2M_REQ_GROUP_IP, M2M_IP_REQ_STATIC_IP_CONF, (uint8*) pstrStaticIPConf, sizeof(tstrM2MIPConfig), NULL, 0,0); } @@ -611,26 +652,35 @@ sint8 m2m_wifi_request_dhcp_server(uint8* addr) @return The function SHALL return 0 for success and a negative value otherwise. @sa tstrM2mLsnInt , m2m_wifi_set_sleep_mode @pre m2m_wifi_set_sleep_mode shall be called first -@warning The Function called once after initialization. +@warning The Function called once after initialization. */ sint8 m2m_wifi_enable_dhcp(uint8 u8DhcpEn ) { uint8 u8Req; u8Req = u8DhcpEn ? M2M_IP_REQ_ENABLE_DHCP : M2M_IP_REQ_DISABLE_DHCP; - return hif_send(M2M_REQ_GRP_IP, u8Req, NULL, 0, NULL, 0, 0); + return hif_send(M2M_REQ_GROUP_IP, u8Req, NULL, 0, NULL, 0, 0); } sint8 m2m_wifi_set_lsn_int(tstrM2mLsnInt* pstrM2mLsnInt) { - return hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_LSN_INT, (uint8*)pstrM2mLsnInt, sizeof(tstrM2mLsnInt), NULL, 0, 0); + return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_LSN_INT, (uint8*)pstrM2mLsnInt, sizeof(tstrM2mLsnInt), NULL, 0, 0); } sint8 m2m_wifi_set_cust_InfoElement(uint8* pau8M2mCustInfoElement) { - return hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_CUST_INFO_ELEMENT, (uint8*)pau8M2mCustInfoElement, pau8M2mCustInfoElement[0]+1, NULL, 0, 0); + + sint8 ret = M2M_ERR_FAIL; + if(pau8M2mCustInfoElement != NULL) + { + if((pau8M2mCustInfoElement[0] + 1) < M2M_CUST_IE_LEN_MAX) + { + ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_CUST_INFO_ELEMENT|M2M_REQ_DATA_PKT, (uint8*)pau8M2mCustInfoElement, pau8M2mCustInfoElement[0]+1, NULL, 0, 0); + } + } + return ret; } sint8 m2m_wifi_set_scan_options(tstrM2MScanOption* ptstrM2MScanOption) @@ -638,7 +688,7 @@ sint8 m2m_wifi_set_scan_options(tstrM2MScanOption* ptstrM2MScanOption) sint8 s8Ret = M2M_ERR_FAIL; if(m2m_validate_scan_options (ptstrM2MScanOption) == M2M_SUCCESS) { - s8Ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SET_SCAN_OPTION, (uint8*)ptstrM2MScanOption, sizeof(tstrM2MScanOption),NULL, 0,0); + s8Ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_SCAN_OPTION, (uint8*)ptstrM2MScanOption, sizeof(tstrM2MScanOption),NULL, 0,0); } return s8Ret; } @@ -647,7 +697,7 @@ sint8 m2m_wifi_set_scan_region(uint16 ScanRegion) sint8 s8Ret = M2M_ERR_FAIL; tstrM2MScanRegion strScanRegion; strScanRegion.u16ScanRegion = ScanRegion; - s8Ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SET_SCAN_REGION, (uint8*)&strScanRegion, sizeof(tstrM2MScanRegion),NULL, 0,0); + s8Ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_SCAN_REGION, (uint8*)&strScanRegion, sizeof(tstrM2MScanRegion),NULL, 0,0); return s8Ret; } sint8 m2m_wifi_request_scan(uint8 ch) @@ -660,7 +710,7 @@ sint8 m2m_wifi_request_scan(uint8 ch) { tstrM2MScan strtmp; strtmp.u8ChNum = ch; - s8Ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SCAN, (uint8*)&strtmp, sizeof(tstrM2MScan),NULL, 0,0); + s8Ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SCAN, (uint8*)&strtmp, sizeof(tstrM2MScan),NULL, 0,0); if(s8Ret == M2M_SUCCESS) { gu8scanInProgress = 1; @@ -688,24 +738,24 @@ sint8 m2m_wifi_wps(uint8 u8TriggerType,const char *pcPinNumber) /*If WPS is using PIN METHOD*/ if (u8TriggerType == WPS_PIN_TRIGGER) m2m_memcpy ((uint8*)strtmp.acPinNumber,(uint8*) pcPinNumber,8); - return hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_WPS, (uint8*)&strtmp,sizeof(tstrM2MWPSConnect), NULL, 0,0); + return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_WPS, (uint8*)&strtmp,sizeof(tstrM2MWPSConnect), NULL, 0,0); } sint8 m2m_wifi_wps_disable(void) { sint8 ret = M2M_SUCCESS; - ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_DISABLE_WPS, NULL,0, NULL, 0, 0); + ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_DISABLE_WPS, NULL,0, NULL, 0, 0); return ret; } /*! @fn NMI_API sint8 m2m_wifi_req_client_ctrl(uint8 cmd); -@brief Send a command to the PS Client (An WINC1500 board running the ps_firmware), +@brief Send a command to the PS Client (An WINC1500 board running the ps_firmware), if the PS client send any commands it will be received in wifi_cb M2M_WIFI_RESP_CLIENT_INFO @param [in] cmd Control command sent from PS Server to PS Client (command values defined by the application) @return The function SHALL return M2M_SUCCESE for success and a negative value otherwise. @sa m2m_wifi_req_server_init, M2M_WIFI_RESP_CLIENT_INFO @pre m2m_wifi_req_server_init should be called first -@warning +@warning */ sint8 m2m_wifi_req_client_ctrl(uint8 u8Cmd) { @@ -714,7 +764,7 @@ sint8 m2m_wifi_req_client_ctrl(uint8 u8Cmd) #ifdef _PS_SERVER_ tstrM2Mservercmd strCmd; strCmd.u8cmd = u8Cmd; - ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_CLIENT_CTRL, (uint8*)&strCmd, sizeof(tstrM2Mservercmd), NULL, 0, 0); + ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_CLIENT_CTRL, (uint8*)&strCmd, sizeof(tstrM2Mservercmd), NULL, 0, 0); #else M2M_ERR("_PS_SERVER_ is not defined\n"); #endif @@ -722,7 +772,7 @@ sint8 m2m_wifi_req_client_ctrl(uint8 u8Cmd) } /*! @fn NMI_API sint8 m2m_wifi_req_server_init(uint8 ch); -@brief Initialize the PS Server, The WINC1500 support Non secure communication with another WINC1500, +@brief Initialize the PS Server, The WINC1500 support Non secure communication with another WINC1500, (SERVER/CLIENT) through one byte command (probe request and probe response) without any connection setup @param [in] ch Server listening channel @@ -736,7 +786,7 @@ sint8 m2m_wifi_req_server_init(uint8 ch) #ifdef _PS_SERVER_ tstrM2mServerInit strServer; strServer.u8Channel = ch; - ret = hif_send(M2M_REQ_GRP_WIFI,M2M_WIFI_REQ_SERVER_INIT, (uint8*)&strServer, sizeof(tstrM2mServerInit), NULL, 0, 0); + ret = hif_send(M2M_REQ_GROUP_WIFI,M2M_WIFI_REQ_SERVER_INIT, (uint8*)&strServer, sizeof(tstrM2mServerInit), NULL, 0, 0); #else M2M_ERR("_PS_SERVER_ is not defined\n"); #endif @@ -749,7 +799,7 @@ sint8 m2m_wifi_p2p(uint8 u8Channel) { tstrM2MP2PConnect strtmp; strtmp.u8ListenChannel = u8Channel; - ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_ENABLE_P2P, (uint8*)&strtmp, sizeof(tstrM2MP2PConnect), NULL, 0,0); + ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_ENABLE_P2P, (uint8*)&strtmp, sizeof(tstrM2MP2PConnect), NULL, 0,0); } else { @@ -761,7 +811,7 @@ sint8 m2m_wifi_p2p(uint8 u8Channel) sint8 m2m_wifi_p2p_disconnect(void) { sint8 ret = M2M_SUCCESS; - ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_DISABLE_P2P, NULL, 0, NULL, 0, 0); + ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_DISABLE_P2P, NULL, 0, NULL, 0, 0); return ret; } sint8 m2m_wifi_enable_ap(CONST tstrM2MAPConfig* pstrM2MAPConfig) @@ -769,27 +819,27 @@ sint8 m2m_wifi_enable_ap(CONST tstrM2MAPConfig* pstrM2MAPConfig) sint8 ret = M2M_ERR_FAIL; if(M2M_SUCCESS == m2m_validate_ap_parameters(pstrM2MAPConfig)) { - ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_ENABLE_AP, (uint8 *)pstrM2MAPConfig, sizeof(tstrM2MAPConfig), NULL, 0, 0); + ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_ENABLE_AP, (uint8 *)pstrM2MAPConfig, sizeof(tstrM2MAPConfig), NULL, 0, 0); } return ret; } sint8 m2m_wifi_disable_ap(void) { sint8 ret = M2M_SUCCESS; - ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_DISABLE_AP, NULL, 0, NULL, 0, 0); + ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_DISABLE_AP, NULL, 0, NULL, 0, 0); return ret; } /*! @fn NMI_API sint8 m2m_wifi_req_curr_rssi(void); -@brief Request the current RSSI for the current connected AP, - the response received in wifi_cb M2M_WIFI_RESP_CURRENT_RSSI -@sa M2M_WIFI_RESP_CURRENT_RSSI +@brief Request the current RSSI for the current connected AP, + the response received in wifi_cb M2M_WIFI_RESP_CURRENT_RSSI +@sa M2M_WIFI_RESP_CURRENT_RSSI @return The function shall return M2M_SUCCESS for success and a negative value otherwise. */ sint8 m2m_wifi_req_curr_rssi(void) { sint8 ret = M2M_SUCCESS; - ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_CURRENT_RSSI, NULL, 0, NULL,0, 0); + ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_CURRENT_RSSI, NULL, 0, NULL,0, 0); return ret; } sint8 m2m_wifi_send_ethernet_pkt(uint8* pu8Packet,uint16 u16PacketSize) @@ -801,7 +851,7 @@ sint8 m2m_wifi_send_ethernet_pkt(uint8* pu8Packet,uint16 u16PacketSize) strTxPkt.u16PacketSize = u16PacketSize; strTxPkt.u16HeaderLength = M2M_ETHERNET_HDR_LEN; - s8Ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SEND_ETHERNET_PACKET | M2M_REQ_DATA_PKT, + s8Ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SEND_ETHERNET_PACKET | M2M_REQ_DATA_PKT, (uint8*)&strTxPkt, sizeof(tstrM2MWifiTxPacketInfo), pu8Packet, u16PacketSize, M2M_ETHERNET_HDR_OFFSET - M2M_HIF_HDR_OFFSET); } return s8Ret; @@ -809,14 +859,14 @@ sint8 m2m_wifi_send_ethernet_pkt(uint8* pu8Packet,uint16 u16PacketSize) /*! @fn NMI_API sint8 m2m_wifi_get_otp_mac_address(uint8 *pu8MacAddr, uint8 * pu8IsValid); @brief Request the MAC address stored on the OTP (one time programmable) memory of the device. - (the function is Blocking until response received) + (the function is Blocking until response received) @param [out] pu8MacAddr Output MAC address buffer of 6 bytes size. Valid only if *pu8Valid=1. @param [out] pu8IsValid - A output boolean value to indicate the validity of pu8MacAddr in OTP. - Output zero if the OTP memory is not programmed, non-zero otherwise. + A output boolean value to indicate the validity of pu8MacAddr in OTP. + Output zero if the OTP memory is not programmed, non-zero otherwise. @return The function shall return M2M_SUCCESS for success and a negative value otherwise. -@sa m2m_wifi_get_mac_address +@sa m2m_wifi_get_mac_address @pre m2m_wifi_init required to call any WIFI/socket function */ sint8 m2m_wifi_get_otp_mac_address(uint8 *pu8MacAddr, uint8* pu8IsValid) @@ -836,11 +886,11 @@ sint8 m2m_wifi_get_otp_mac_address(uint8 *pu8MacAddr, uint8* pu8IsValid) /*! @fn NMI_API sint8 m2m_wifi_get_mac_address(uint8 *pu8MacAddr) @brief Request the current MAC address of the device (the working mac address). - (the function is Blocking until response received) + (the function is Blocking until response received) @param [out] pu8MacAddr - Output MAC address buffer of 6 bytes size. + Output MAC address buffer of 6 bytes size. @return The function shall return M2M_SUCCESS for success and a negative value otherwise. -@sa m2m_wifi_get_otp_mac_address +@sa m2m_wifi_get_otp_mac_address @pre m2m_wifi_init required to call any WIFI/socket function */ sint8 m2m_wifi_get_mac_address(uint8 *pu8MacAddr) @@ -860,18 +910,18 @@ sint8 m2m_wifi_get_mac_address(uint8 *pu8MacAddr) } /*! @fn NMI_API sint8 m2m_wifi_req_scan_result(uint8 index); -@brief Reads the AP information from the Scan Result list with the given index, - the response received in wifi_cb M2M_WIFI_RESP_SCAN_RESULT, - the response pointer should be casted with tstrM2mWifiscanResult structure -@param [in] index - Index for the requested result, the index range start from 0 till number of AP's found -@sa tstrM2mWifiscanResult,m2m_wifi_get_num_ap_found,m2m_wifi_request_scan +@brief Reads the AP information from the Scan Result list with the given index, + the response received in wifi_cb M2M_WIFI_RESP_SCAN_RESULT, + the response pointer should be casted with tstrM2mWifiscanResult structure +@param [in] index + Index for the requested result, the index range start from 0 till number of AP's found +@sa tstrM2mWifiscanResult,m2m_wifi_get_num_ap_found,m2m_wifi_request_scan @return The function shall return M2M_SUCCESE for success and a negative value otherwise -@pre m2m_wifi_request_scan need to be called first, then m2m_wifi_get_num_ap_found +@pre m2m_wifi_request_scan need to be called first, then m2m_wifi_get_num_ap_found to get the number of AP's found @warning Function used only in STA mode only. the scan result updated only if scan request called, - else it will be cashed in firmware for the host scan request result, - which mean if large delay occur between the scan request and the scan result request, + else it will be cashed in firmware for the host scan request result, + which mean if large delay occur between the scan request and the scan result request, the result will not be up-to-date */ @@ -880,18 +930,18 @@ sint8 m2m_wifi_req_scan_result(uint8 index) sint8 ret = M2M_SUCCESS; tstrM2mReqScanResult strReqScanRlt; strReqScanRlt.u8Index = index; - ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SCAN_RESULT, (uint8*) &strReqScanRlt, sizeof(tstrM2mReqScanResult), NULL, 0, 0); + ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SCAN_RESULT, (uint8*) &strReqScanRlt, sizeof(tstrM2mReqScanResult), NULL, 0, 0); return ret; } /*! @fn NMI_API uint8 m2m_wifi_get_num_ap_found(void); -@brief Reads the number of AP's found in the last Scan Request, - The function read the number of AP's from global variable which updated in the - wifi_cb in M2M_WIFI_RESP_SCAN_DONE. -@sa m2m_wifi_request_scan +@brief Reads the number of AP's found in the last Scan Request, + The function read the number of AP's from global variable which updated in the + wifi_cb in M2M_WIFI_RESP_SCAN_DONE. +@sa m2m_wifi_request_scan @return Return the number of AP's found in the last Scan Request. -@pre m2m_wifi_request_scan need to be called first -@warning That function need to be called in the wifi_cb in M2M_WIFI_RESP_SCAN_DONE, +@pre m2m_wifi_request_scan need to be called first +@warning That function need to be called in the wifi_cb in M2M_WIFI_RESP_SCAN_DONE, calling that function in any other place will return undefined/undated numbers. Function used only in STA mode only. */ @@ -911,17 +961,17 @@ uint8 m2m_wifi_get_sleep_mode(void) } /*! @fn NMI_API sint8 m2m_wifi_set_sleep_mode(uint8 PsTyp, uint8 BcastEn); -@brief Set the power saving mode for the WINC1500. +@brief Set the power saving mode for the WINC1500. @param [in] PsTyp Desired power saving mode. Supported types are defined in tenuPowerSaveModes. @param [in] BcastEn - Broadcast reception enable flag. + Broadcast reception enable flag. If it is 1, the WINC1500 must be awake each DTIM Beacon for receiving Broadcast traffic. - If it is 0, the WINC1500 will not wakeup at the DTIM Beacon, but its wakeup depends only - on the the configured Listen Interval. + If it is 0, the WINC1500 will not wakeup at the DTIM Beacon, but its wakeup depends only + on the the configured Listen Interval. @return The function SHALL return 0 for success and a negative value otherwise. @sa tenuPowerSaveModes -@warning The function called once after initialization. +@warning The function called once after initialization. */ sint8 m2m_wifi_set_sleep_mode(uint8 PsTyp, uint8 BcastEn) { @@ -929,7 +979,7 @@ sint8 m2m_wifi_set_sleep_mode(uint8 PsTyp, uint8 BcastEn) tstrM2mPsType strPs; strPs.u8PsType = PsTyp; strPs.u8BcastEn = BcastEn; - ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SLEEP, (uint8*) &strPs,sizeof(tstrM2mPsType), NULL, 0, 0); + ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SLEEP, (uint8*) &strPs,sizeof(tstrM2mPsType), NULL, 0, 0); M2M_INFO("POWER SAVE %d\n",PsTyp); hif_set_sleep_mode(PsTyp); return ret; @@ -938,10 +988,10 @@ sint8 m2m_wifi_set_sleep_mode(uint8 PsTyp, uint8 BcastEn) @fn NMI_API sint8 m2m_wifi_request_sleep(void) @brief Request from WINC1500 device to Sleep for specific time in the M2M_PS_MANUAL Power save mode (only). @param [in] u32SlpReqTime - Request Sleep in ms + Request Sleep in ms @return The function SHALL return M2M_SUCCESS for success and a negative value otherwise. @sa tenuPowerSaveModes , m2m_wifi_set_sleep_mode -@warning the Function should be called in M2M_PS_MANUAL power save only +@warning the Function should be called in M2M_PS_MANUAL power save only */ sint8 m2m_wifi_request_sleep(uint32 u32SlpReqTime) { @@ -952,7 +1002,7 @@ sint8 m2m_wifi_request_sleep(uint32 u32SlpReqTime) { tstrM2mSlpReqTime strPs; strPs.u32SleepTime = u32SlpReqTime; - ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_DOZE, (uint8*) &strPs,sizeof(tstrM2mSlpReqTime), NULL, 0, 0); + ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_DOZE, (uint8*) &strPs,sizeof(tstrM2mSlpReqTime), NULL, 0, 0); } return ret; } @@ -964,7 +1014,7 @@ sint8 m2m_wifi_request_sleep(uint32 u32SlpReqTime) @param [in] u8DeviceNameLength Length of the device name. @return The function SHALL return M2M_SUCCESS for success and a negative value otherwise. -@warning The Function called once after initialization. +@warning The Function called once after initialization. */ sint8 m2m_wifi_set_device_name(uint8 *pu8DeviceName, uint8 u8DeviceNameLength) { @@ -976,9 +1026,20 @@ sint8 m2m_wifi_set_device_name(uint8 *pu8DeviceName, uint8 u8DeviceNameLength) //pu8DeviceName[u8DeviceNameLength] = '\0'; u8DeviceNameLength ++; m2m_memcpy(strDeviceName.au8DeviceName, pu8DeviceName, u8DeviceNameLength); - return hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SET_DEVICE_NAME, + return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_DEVICE_NAME, (uint8*)&strDeviceName, sizeof(tstrM2MDeviceNameConfig), NULL, 0,0); } +sint8 m2m_wifi_get_firmware_version(tstrM2mRev *pstrRev) +{ + sint8 ret = M2M_SUCCESS; + ret = hif_chip_wake(); + if(ret == M2M_SUCCESS) + { + ret = nm_get_firmware_full_info(pstrRev); + hif_chip_sleep(); + } + return ret; +} #ifdef CONF_MGMT sint8 m2m_wifi_enable_monitoring_mode(tstrM2MWifiMonitorModeCtrl *pstrMtrCtrl, uint8 *pu8PayloadBuffer, uint16 u16BufferSize, uint16 u16DataOffset) @@ -989,18 +1050,15 @@ sint8 m2m_wifi_enable_monitoring_mode(tstrM2MWifiMonitorModeCtrl *pstrMtrCtrl, u gstrMgmtCtrl.pu8Buf = pu8PayloadBuffer; gstrMgmtCtrl.u16Sz = u16BufferSize; gstrMgmtCtrl.u16Offset = u16DataOffset; - s8Ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_ENABLE_MONITORING, + s8Ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_ENABLE_MONITORING, (uint8*)pstrMtrCtrl, sizeof(tstrM2MWifiMonitorModeCtrl), NULL, 0,0); } return s8Ret; } -sint8 m2m_wifi_get_firmware_version(tstrM2mRev *M2mRev) -{ - return nm_get_firmware_info(M2mRev); -} + sint8 m2m_wifi_disable_monitoring_mode(void) { - return hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_DISABLE_MONITORING, NULL, 0, NULL, 0,0); + return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_DISABLE_MONITORING, NULL, 0, NULL, 0,0); } sint8 m2m_wifi_send_wlan_pkt(uint8 *pu8WlanPacket, uint16 u16WlanHeaderLength, uint16 u16WlanPktSize) @@ -1012,7 +1070,7 @@ sint8 m2m_wifi_send_wlan_pkt(uint8 *pu8WlanPacket, uint16 u16WlanHeaderLength, u strTxPkt.u16PacketSize = u16WlanPktSize; strTxPkt.u16HeaderLength = u16WlanHeaderLength; - s8Ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SEND_WIFI_PACKET | M2M_REQ_DATA_PKT, + s8Ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SEND_WIFI_PACKET | M2M_REQ_DATA_PKT, (uint8*)&strTxPkt, sizeof(tstrM2MWifiTxPacketInfo), pu8WlanPacket, u16WlanPktSize, sizeof(tstrM2MWifiTxPacketInfo)); } return s8Ret; @@ -1036,11 +1094,11 @@ sint8 m2m_wifi_start_provision_mode(tstrM2MAPConfig *pstrAPConfig, char *pcHttpS } m2m_memcpy((uint8*)strProvConfig.acHttpServerDomainName, (uint8*)pcHttpServerDomainName, 64); strProvConfig.u8EnableRedirect = bEnableHttpRedirect; - + /* Stop Scan if it is ongoing. */ gu8scanInProgress = 0; - s8Ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_START_PROVISION_MODE | M2M_REQ_DATA_PKT, + s8Ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_START_PROVISION_MODE | M2M_REQ_DATA_PKT, (uint8*)&strProvConfig, sizeof(tstrM2MProvisionModeConfig), NULL, 0, 0); } else @@ -1054,17 +1112,20 @@ ERR1: sint8 m2m_wifi_stop_provision_mode(void) { - return hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_STOP_PROVISION_MODE, NULL, 0, NULL, 0, 0); + return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_STOP_PROVISION_MODE, NULL, 0, NULL, 0, 0); } sint8 m2m_wifi_get_connection_info(void) { - return hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_GET_CONN_INFO, NULL, 0, NULL, 0, 0); + return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_GET_CONN_INFO, NULL, 0, NULL, 0, 0); } sint8 m2m_wifi_set_sytem_time(uint32 u32UTCSeconds) { - return hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SET_SYS_TIME, (uint8*)&u32UTCSeconds, sizeof(tstrSystemTime), NULL, 0, 0); + /* + The firmware accepts timestamps relative to 1900 like NTP Timestamp. + */ + return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_SYS_TIME, (uint8*)&u32UTCSeconds, sizeof(tstrSystemTime), NULL, 0, 0); } /*! * @fn NMI_API sint8 m2m_wifi_get_sytem_time(void); @@ -1076,7 +1137,7 @@ sint8 m2m_wifi_set_sytem_time(uint32 u32UTCSeconds) */ sint8 m2m_wifi_get_sytem_time(void) { - return hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_GET_SYS_TIME, NULL,0, NULL, 0, 0); + return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_GET_SYS_TIME, NULL,0, NULL, 0, 0); } sint8 m2m_wifi_enable_sntp(uint8 bEnable) @@ -1084,7 +1145,7 @@ sint8 m2m_wifi_enable_sntp(uint8 bEnable) uint8 u8Req; u8Req = bEnable ? M2M_WIFI_REQ_ENABLE_SNTP_CLIENT : M2M_WIFI_REQ_DISABLE_SNTP_CLIENT; - return hif_send(M2M_REQ_GRP_WIFI, u8Req, NULL, 0, NULL, 0, 0); + return hif_send(M2M_REQ_GROUP_WIFI, u8Req, NULL, 0, NULL, 0, 0); } /*! @fn NMI_API sint8 m2m_wifi_set_power_profile(uint8 u8PwrMode); @@ -1102,7 +1163,7 @@ sint8 m2m_wifi_set_power_profile(uint8 u8PwrMode) sint8 ret = M2M_SUCCESS; tstrM2mPwrMode strM2mPwrMode; strM2mPwrMode.u8PwrMode = u8PwrMode; - ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SET_POWER_PROFILE, (uint8*)&strM2mPwrMode,sizeof(tstrM2mPwrMode), NULL, 0, 0); + ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_POWER_PROFILE, (uint8*)&strM2mPwrMode,sizeof(tstrM2mPwrMode), NULL, 0, 0); return ret; } /*! @@ -1120,7 +1181,7 @@ sint8 m2m_wifi_set_tx_power(uint8 u8TxPwrLevel) sint8 ret = M2M_SUCCESS; tstrM2mTxPwrLevel strM2mTxPwrLevel; strM2mTxPwrLevel.u8TxPwrLevel = u8TxPwrLevel; - ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SET_TX_POWER, (uint8*)&strM2mTxPwrLevel,sizeof(tstrM2mTxPwrLevel), NULL, 0, 0); + ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_TX_POWER, (uint8*)&strM2mTxPwrLevel,sizeof(tstrM2mTxPwrLevel), NULL, 0, 0); return ret; } @@ -1140,7 +1201,7 @@ sint8 m2m_wifi_enable_firmware_logs(uint8 u8Enable) sint8 ret = M2M_SUCCESS; tstrM2mEnableLogs strM2mEnableLogs; strM2mEnableLogs.u8Enable = u8Enable; - ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SET_ENABLE_LOGS, (uint8*)&strM2mEnableLogs,sizeof(tstrM2mEnableLogs), NULL, 0, 0); + ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_ENABLE_LOGS, (uint8*)&strM2mEnableLogs,sizeof(tstrM2mEnableLogs), NULL, 0, 0); return ret; } @@ -1160,10 +1221,34 @@ sint8 m2m_wifi_set_battery_voltage(uint16 u16BattVoltx100) sint8 ret = M2M_SUCCESS; tstrM2mBatteryVoltage strM2mBattVol = {0}; strM2mBattVol.u16BattVolt = u16BattVoltx100; - ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SET_BATTERY_VOLTAGE, (uint8*)&strM2mBattVol,sizeof(tstrM2mBatteryVoltage), NULL, 0, 0); + ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_BATTERY_VOLTAGE, (uint8*)&strM2mBattVol,sizeof(tstrM2mBatteryVoltage), NULL, 0, 0); + return ret; +} +/*! +@fn sint8 m2m_wifi_prng_get_random_bytes(uint8 * pu8PrngBuff,uint16 u16PrngSize) +@brief Get random bytes using the PRNG bytes. +@param [in] u16PrngSize + Size of the required random bytes to be generated. +@param [in] pu8PrngBuff + Pointer to user allocated buffer. +@return The function SHALL return M2M_SUCCESE for success and a negative value otherwise. +*/ +sint8 m2m_wifi_prng_get_random_bytes(uint8 * pu8PrngBuff,uint16 u16PrngSize) +{ + sint8 ret = M2M_ERR_FAIL; + tstrPrng strRng = {0}; + if((u16PrngSize < (M2M_BUFFER_MAX_SIZE - sizeof(tstrPrng)))&&(pu8PrngBuff != NULL)) + { + strRng.u16PrngSize = u16PrngSize; + strRng.pu8RngBuff = pu8PrngBuff; + ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_GET_PRNG|M2M_REQ_DATA_PKT,(uint8 *)&strRng, sizeof(tstrPrng),NULL,0, 0); + } + else + { + M2M_ERR("PRNG Buffer exceeded maximum size %d or NULL Buffer\n",u16PrngSize); + } return ret; } - #ifdef ETH_MODE /*! @fn \ @@ -1190,7 +1275,7 @@ NMI_API sint8 m2m_wifi_enable_mac_mcast(uint8* pu8MulticastMacAddress, uint8 u8A strMulticastMac.u8AddRemove = u8AddRemove; m2m_memcpy(strMulticastMac.au8macaddress,pu8MulticastMacAddress,M2M_MAC_ADDRES_LEN); M2M_DBG("mac multicast: %x:%x:%x:%x:%x:%x\r\n",strMulticastMac.au8macaddress[0],strMulticastMac.au8macaddress[1],strMulticastMac.au8macaddress[2],strMulticastMac.au8macaddress[3],strMulticastMac.au8macaddress[4],strMulticastMac.au8macaddress[5]); - s8ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SET_MAC_MCAST, (uint8 *)&strMulticastMac,sizeof(tstrM2MMulticastMac),NULL,0,0); + s8ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_MAC_MCAST, (uint8 *)&strMulticastMac,sizeof(tstrM2MMulticastMac),NULL,0,0); } return s8ret; @@ -1227,5 +1312,5 @@ NMI_API sint8 m2m_wifi_set_receive_buffer(void* pvBuffer,uint16 u16BufferLen) } return s8ret; } -#endif +#endif /* ETH_MODE */ diff --git a/src/winc1500/src/nmasic.c b/src/winc1500/src/nmasic.c index b5fc6dea6..dca1df01a 100644 --- a/src/winc1500/src/nmasic.c +++ b/src/winc1500/src/nmasic.c @@ -43,15 +43,16 @@ #include "driver/include/nmbus.h" #include "bsp/include/nm_bsp.h" #include "driver/include/nmasic.h" +#include "driver/include/m2m_types.h" -#define NMI_GLB_RESET_0 (NMI_PERIPH_REG_BASE + 0x400) -#define NMI_INTR_REG_BASE (NMI_PERIPH_REG_BASE+0xa00) -#define NMI_PIN_MUX_0 (NMI_PERIPH_REG_BASE + 0x408) -#define NMI_INTR_ENABLE (NMI_INTR_REG_BASE) -#define GET_UINT32(X,Y) (X[0+Y] + ((uint32)X[1+Y]<<8) + ((uint32)X[2+Y]<<16) +((uint32)X[3+Y]<<24)) +#define NMI_GLB_RESET_0 (NMI_PERIPH_REG_BASE + 0x400) +#define NMI_INTR_REG_BASE (NMI_PERIPH_REG_BASE + 0xa00) +#define NMI_PIN_MUX_0 (NMI_PERIPH_REG_BASE + 0x408) +#define NMI_INTR_ENABLE (NMI_INTR_REG_BASE) +#define GET_UINT32(X,Y) (X[0+Y] + ((uint32)X[1+Y]<<8) + ((uint32)X[2+Y]<<16) +((uint32)X[3+Y]<<24)) -#define TIMEOUT (2000) -#define M2M_DISABLE_PS 0xD0UL +#define TIMEOUT (2000) +#define M2M_DISABLE_PS (0xd0ul) static uint32 clk_status_reg_adr = 0xf; /* Assume initially it is B0 chip */ @@ -135,9 +136,20 @@ sint8 nm_clkless_wake(void) /* wait 1ms, spi data read */ nm_bsp_sleep(1); ret = nm_read_reg_with_ret(clk_status_reg_adr, &clk_status_reg); - if(ret != M2M_SUCCESS) { - M2M_ERR("Bus error (2). Wake up failed\n"); - goto _WAKE_EXIT; + + /* Aelmeleh 24-08-2015*/ + /* Check for C3000 rev. D0 value */ + if( (ret != M2M_SUCCESS) || ((ret == M2M_SUCCESS) && (clk_status_reg == 0)) ) { + + clk_status_reg_adr = 0x13; + /* wait 1ms, spi data read */ + nm_bsp_sleep(1); + ret = nm_read_reg_with_ret(clk_status_reg_adr, &clk_status_reg); + + if(ret != M2M_SUCCESS) { + M2M_ERR("Bus error (2). Wake up failed\n"); + goto _WAKE_EXIT; + } } } @@ -263,7 +275,6 @@ uint32 nmi_get_chipid(void) static uint32 chipid = 0; if (chipid == 0) { - //uint32 revid; uint32 rfrevid; if((nm_read_reg_with_ret(0x1000, &chipid)) != M2M_SUCCESS) { @@ -290,7 +301,13 @@ uint32 nmi_get_chipid(void) } else /* if(rfrevid == 5) */ { /* 1002B2 */ chipid = 0x1002b2; } + } else if(chipid == 0x1000F0) { + if((nm_read_reg_with_ret(0x3B0000, &chipid)) != M2M_SUCCESS) { + chipid = 0; + return 0; + } } else { + } //#define PROBE_FLASH #ifdef PROBE_FLASH @@ -361,14 +378,21 @@ void nmi_set_sys_clk_src_to_xo(void) /* Do PLL update */ nmi_update_pll(); } +static uint8 check_3000_id(void) +{ + return ((nmi_get_chipid() & (0xf00000)) == 0x300000); +} + sint8 chip_wake(void) { sint8 ret = M2M_SUCCESS; - ret = nm_clkless_wake(); if(ret != M2M_SUCCESS) return ret; - - enable_rf_blocks(); + if(!check_3000_id()) + { + enable_rf_blocks(); + } + return ret; } @@ -381,29 +405,27 @@ sint8 chip_reset_and_cpu_halt(void) if(ret != M2M_SUCCESS) { return ret; } - chip_reset(); - ret = nm_read_reg_with_ret(0x1118, ®); - if (M2M_SUCCESS != ret) { - ret = M2M_ERR_BUS_FAIL; - M2M_ERR("[nmi start]: fail read reg 0x1118 ...\n"); - } - reg |= (1 << 0); - ret = nm_write_reg(0x1118, reg); - ret += nm_read_reg_with_ret(NMI_GLB_RESET_0, ®); - if ((reg & (1ul << 10)) == (1ul << 10)) { - reg &= ~(1ul << 10); - ret += nm_write_reg(NMI_GLB_RESET_0, reg); + if(!check_3000_id()) + { + chip_reset(); + ret = nm_read_reg_with_ret(0x1118, ®); + if (M2M_SUCCESS != ret) { + ret = M2M_ERR_BUS_FAIL; + M2M_ERR("[nmi start]: fail read reg 0x1118 ...\n"); + } + reg |= (1 << 0); + ret = nm_write_reg(0x1118, reg); ret += nm_read_reg_with_ret(NMI_GLB_RESET_0, ®); + if ((reg & (1ul << 10)) == (1ul << 10)) { + reg &= ~(1ul << 10); + ret += nm_write_reg(NMI_GLB_RESET_0, reg); + ret += nm_read_reg_with_ret(NMI_GLB_RESET_0, ®); + } + nm_write_reg(BOOTROM_REG,0); + nm_write_reg(NMI_STATE_REG,0); + nm_write_reg(NMI_REV_REG,0); + nm_write_reg(NMI_PIN_MUX_0, 0x11111000); } -#if 0 - reg |= (1ul << 10); - ret += nm_write_reg(NMI_GLB_RESET_0, reg); - ret += nm_read_reg_with_ret(NMI_GLB_RESET_0, ®); -#endif - nm_write_reg(BOOTROM_REG,0); - nm_write_reg(NMI_STATE_REG,0); - nm_write_reg(NMI_REV_REG,0); - nm_write_reg(NMI_PIN_MUX_0, 0x11111000); return ret; } sint8 chip_reset(void) @@ -424,6 +446,7 @@ sint8 wait_for_bootrom(uint8 arg) { sint8 ret = M2M_SUCCESS; uint32 reg = 0, cnt = 0; + uint32 u32GpReg1 = 0; reg = 0; while(1) { @@ -453,20 +476,26 @@ sint8 wait_for_bootrom(uint8 arg) } } } - - if(2 == arg) { + + if(M2M_WIFI_MODE_ATE_HIGH == arg) { nm_write_reg(NMI_REV_REG, M2M_ATE_FW_START_VALUE); + nm_write_reg(NMI_STATE_REG, NBIT20); + }else if(M2M_WIFI_MODE_ATE_LOW == arg) { + nm_write_reg(NMI_REV_REG, M2M_ATE_FW_START_VALUE); + nm_write_reg(NMI_STATE_REG, 0); + }else if(M2M_WIFI_MODE_ETHERNET == arg){ + u32GpReg1 = rHAVE_ETHERNET_MODE_BIT; } else { /*bypass this step*/ } if(REV(nmi_get_chipid()) == REV_3A0) { - chip_apply_conf(rHAVE_USE_PMU_BIT); + chip_apply_conf(u32GpReg1 | rHAVE_USE_PMU_BIT); } else { - chip_apply_conf(0); + chip_apply_conf(u32GpReg1); } nm_write_reg(BOOTROM_REG,M2M_START_FIRMWARE); @@ -483,22 +512,25 @@ sint8 wait_for_firmware_start(uint8 arg) { sint8 ret = M2M_SUCCESS; uint32 reg = 0, cnt = 0; + uint32 u32Timeout = TIMEOUT; volatile uint32 regAddress = NMI_STATE_REG; volatile uint32 checkValue = M2M_FINISH_INIT_STATE; - - if(2 == arg) { + + if((M2M_WIFI_MODE_ATE_HIGH == arg)||(M2M_WIFI_MODE_ATE_LOW == arg)) { regAddress = NMI_REV_REG; checkValue = M2M_ATE_FW_IS_UP_VALUE; } else { /*bypass this step*/ } - + + while (checkValue != reg) { + nm_bsp_sleep(2); /* TODO: Why bus error if this delay is not here. */ M2M_DBG("%x %x %x\n",(unsigned int)nm_read_reg(0x108c),(unsigned int)nm_read_reg(0x108c),(unsigned int)nm_read_reg(0x14A0)); reg = nm_read_reg(regAddress); - if(++cnt > TIMEOUT) + if(++cnt >= u32Timeout) { M2M_DBG("Time out for wait firmware Run\n"); ret = M2M_ERR_INIT; @@ -636,10 +668,15 @@ sint8 nmi_get_otp_mac_address(uint8 *pu8MacAddr, uint8 * pu8IsValid) sint8 ret; uint32 u32RegValue; uint8 mac[6]; + tstrGpRegs strgp = {0}; - ret = nm_read_reg_with_ret(rNMI_GP_REG_0, &u32RegValue); + ret = nm_read_reg_with_ret(rNMI_GP_REG_2, &u32RegValue); if(ret != M2M_SUCCESS) goto _EXIT_ERR; + ret = nm_read_block(u32RegValue|0x30000,(uint8*)&strgp,sizeof(tstrGpRegs)); + if(ret != M2M_SUCCESS) goto _EXIT_ERR; + u32RegValue = strgp.u32Mac_efuse_mib; + if(!EFUSED_MAC(u32RegValue)) { M2M_DBG("Default MAC\n"); m2m_memset(pu8MacAddr, 0, 6); @@ -648,7 +685,7 @@ sint8 nmi_get_otp_mac_address(uint8 *pu8MacAddr, uint8 * pu8IsValid) M2M_DBG("OTP MAC\n"); u32RegValue >>=16; - nm_read_block(u32RegValue|0x30000, mac, 6); + ret = nm_read_block(u32RegValue|0x30000, mac, 6); m2m_memcpy(pu8MacAddr,mac,6); if(pu8IsValid) *pu8IsValid = 1; return ret; @@ -663,12 +700,17 @@ sint8 nmi_get_mac_address(uint8 *pu8MacAddr) sint8 ret; uint32 u32RegValue; uint8 mac[6]; + tstrGpRegs strgp = {0}; - ret = nm_read_reg_with_ret(rNMI_GP_REG_0, &u32RegValue); + ret = nm_read_reg_with_ret(rNMI_GP_REG_2, &u32RegValue); if(ret != M2M_SUCCESS) goto _EXIT_ERR; + ret = nm_read_block(u32RegValue|0x30000,(uint8*)&strgp,sizeof(tstrGpRegs)); + if(ret != M2M_SUCCESS) goto _EXIT_ERR; + u32RegValue = strgp.u32Mac_efuse_mib; + u32RegValue &=0x0000ffff; - nm_read_block(u32RegValue|0x30000, mac, 6); + ret = nm_read_block(u32RegValue|0x30000, mac, 6); m2m_memcpy(pu8MacAddr, mac, 6); return ret; diff --git a/src/winc1500/src/nmdrv.c b/src/winc1500/src/nmdrv.c index 4f5d70d97..d65a16964 100644 --- a/src/winc1500/src/nmdrv.c +++ b/src/winc1500/src/nmdrv.c @@ -45,6 +45,7 @@ #include "driver/include/nmdrv.h" #include "driver/include/nmasic.h" #include "driver/include/m2m_types.h" +#include "spi_flash/include/spi_flash.h" #ifdef CONF_WINC_USE_SPI #include "driver/include/nmspi.h" @@ -55,9 +56,6 @@ * @brief Get Firmware version info * @param [out] M2mRev * pointer holds address of structure "tstrM2mRev" that contains the firmware version parameters - -* @author Ahmad.Mohammad.Yahya -* @date 27 MARCH 2013 * @version 1.0 */ sint8 nm_get_firmware_info(tstrM2mRev* M2mRev) @@ -67,7 +65,12 @@ sint8 nm_get_firmware_info(tstrM2mRev* M2mRev) sint8 ret = M2M_SUCCESS; ret = nm_read_reg_with_ret(NMI_REV_REG, ®); - + //In case the Firmware running is ATE fw + if(M2M_ATE_FW_IS_UP_VALUE == reg) + { + //Read FW info again from the register specified for ATE + ret = nm_read_reg_with_ret(NMI_REV_REG_ATE, ®); + } M2mRev->u8DriverMajor = M2M_GET_DRV_MAJOR(reg); M2mRev->u8DriverMinor = M2M_GET_DRV_MINOR(reg); M2mRev->u8DriverPatch = M2M_GET_DRV_PATCH(reg); @@ -90,7 +93,132 @@ sint8 nm_get_firmware_info(tstrM2mRev* M2mRev) } return ret; } +/** +* @fn nm_get_firmware_info(tstrM2mRev* M2mRev) +* @brief Get Firmware version info +* @param [out] M2mRev +* pointer holds address of structure "tstrM2mRev" that contains the firmware version parameters +* @version 1.0 +*/ +sint8 nm_get_firmware_full_info(tstrM2mRev* pstrRev) +{ + uint16 curr_drv_ver, min_req_drv_ver,curr_firm_ver; + uint32 reg = 0; + sint8 ret = M2M_SUCCESS; + tstrGpRegs strgp = {0}; + if (pstrRev != NULL) + { + m2m_memset((uint8*)pstrRev,0,sizeof(tstrM2mRev)); + ret = nm_read_reg_with_ret(rNMI_GP_REG_2, ®); + if(ret == M2M_SUCCESS) + { + if(reg != 0) + { + ret = nm_read_block(reg|0x30000,(uint8*)&strgp,sizeof(tstrGpRegs)); + if(ret == M2M_SUCCESS) + { + reg = strgp.u32Firmware_Ota_rev; + reg &= 0x0000ffff; + if(reg != 0) + { + ret = nm_read_block(reg|0x30000,(uint8*)pstrRev,sizeof(tstrM2mRev)); + if(ret == M2M_SUCCESS) + { + curr_firm_ver = M2M_MAKE_VERSION(pstrRev->u8FirmwareMajor, pstrRev->u8FirmwareMinor,pstrRev->u8FirmwarePatch); + curr_drv_ver = M2M_MAKE_VERSION(M2M_DRIVER_VERSION_MAJOR_NO, M2M_DRIVER_VERSION_MINOR_NO, M2M_DRIVER_VERSION_PATCH_NO); + min_req_drv_ver = M2M_MAKE_VERSION(pstrRev->u8DriverMajor, pstrRev->u8DriverMinor,pstrRev->u8DriverPatch); + if((curr_firm_ver == 0)||(min_req_drv_ver == 0)||(min_req_drv_ver == 0)){ + ret = M2M_ERR_FAIL; + goto EXIT; + } + if(curr_drv_ver < min_req_drv_ver) { + /*The current driver version should be larger or equal + than the min driver that the current firmware support */ + ret = M2M_ERR_FW_VER_MISMATCH; + goto EXIT; + } + if(curr_drv_ver > curr_firm_ver) { + /*The current driver should be equal or less than the firmware version*/ + ret = M2M_ERR_FW_VER_MISMATCH; + goto EXIT; + } + } + }else { + ret = M2M_ERR_FAIL; + } + } + }else{ + ret = M2M_ERR_FAIL; + } + } + } +EXIT: + return ret; +} +/** +* @fn nm_get_ota_firmware_info(tstrM2mRev* pstrRev) +* @brief Get Firmware version info +* @param [out] M2mRev +* pointer holds address of structure "tstrM2mRev" that contains the firmware version parameters + +* @version 1.0 +*/ +sint8 nm_get_ota_firmware_info(tstrM2mRev* pstrRev) +{ + uint16 curr_drv_ver, min_req_drv_ver,curr_firm_ver; + uint32 reg = 0; + sint8 ret; + tstrGpRegs strgp = {0}; + if (pstrRev != NULL) + { + m2m_memset((uint8*)pstrRev,0,sizeof(tstrM2mRev)); + ret = nm_read_reg_with_ret(rNMI_GP_REG_2, ®); + if(ret == M2M_SUCCESS) + { + if(reg != 0) + { + ret = nm_read_block(reg|0x30000,(uint8*)&strgp,sizeof(tstrGpRegs)); + if(ret == M2M_SUCCESS) + { + reg = strgp.u32Firmware_Ota_rev; + reg >>= 16; + if(reg != 0) + { + ret = nm_read_block(reg|0x30000,(uint8*)pstrRev,sizeof(tstrM2mRev)); + if(ret == M2M_SUCCESS) + { + curr_firm_ver = M2M_MAKE_VERSION(pstrRev->u8FirmwareMajor, pstrRev->u8FirmwareMinor,pstrRev->u8FirmwarePatch); + curr_drv_ver = M2M_MAKE_VERSION(M2M_DRIVER_VERSION_MAJOR_NO, M2M_DRIVER_VERSION_MINOR_NO, M2M_DRIVER_VERSION_PATCH_NO); + min_req_drv_ver = M2M_MAKE_VERSION(pstrRev->u8DriverMajor, pstrRev->u8DriverMinor,pstrRev->u8DriverPatch); + if((curr_firm_ver == 0)||(min_req_drv_ver == 0)||(min_req_drv_ver == 0)){ + ret = M2M_ERR_FAIL; + goto EXIT; + } + if(curr_drv_ver < min_req_drv_ver) { + /*The current driver version should be larger or equal + than the min driver that the current firmware support */ + ret = M2M_ERR_FW_VER_MISMATCH; + } + if(curr_drv_ver > curr_firm_ver) { + /*The current driver should be equal or less than the firmware version*/ + ret = M2M_ERR_FW_VER_MISMATCH; + } + } + }else{ + ret = M2M_ERR_FAIL; + } + } + }else{ + ret = M2M_ERR_FAIL; + } + } + } else { + ret = M2M_ERR_INVALID_ARG; + } +EXIT: + return ret; +} @@ -114,6 +242,12 @@ sint8 nm_drv_init_download_mode() goto ERR1; } + /** + reset the chip and halt the cpu in case of no wait efuse is set. + */ + chip_reset_and_cpu_halt(); + + #ifdef CONF_WINC_USE_SPI /* Must do this after global reset to set SPI data packet size. */ @@ -141,18 +275,16 @@ ERR1: */ sint8 nm_drv_init(void * arg) { - tstrM2mRev strtmp; sint8 ret = M2M_SUCCESS; - uint8 u8Mode = M2M_WIFI_MODE_NORMAL; + uint8 u8Mode; if(NULL != arg) { - if(M2M_WIFI_MODE_CONFIG == *((uint8 *)arg)) { - u8Mode = M2M_WIFI_MODE_CONFIG; - } else { - /*continue running*/ + u8Mode = *((uint8 *)arg); + if((u8Mode < M2M_WIFI_MODE_NORMAL)||(u8Mode >= M2M_WIFI_MODE_MAX)) { + u8Mode = M2M_WIFI_MODE_NORMAL; } } else { - /*continue running*/ + u8Mode = M2M_WIFI_MODE_NORMAL; } ret = nm_bus_iface_init(NULL); @@ -205,7 +337,7 @@ sint8 nm_drv_init(void * arg) goto ERR2; } - if(M2M_WIFI_MODE_CONFIG == u8Mode) { + if((M2M_WIFI_MODE_ATE_HIGH == u8Mode)||(M2M_WIFI_MODE_ATE_LOW == u8Mode)) { goto ERR1; } else { /*continue running*/ @@ -217,18 +349,6 @@ sint8 nm_drv_init(void * arg) goto ERR2; } - ret = nm_get_firmware_info(&strtmp); - - M2M_INFO("Firmware ver : %u.%u.%u\n", strtmp.u8FirmwareMajor, strtmp.u8FirmwareMinor, strtmp.u8FirmwarePatch); - M2M_INFO("Min driver ver : %u.%u.%u\n", strtmp.u8DriverMajor, strtmp.u8DriverMinor, strtmp.u8DriverPatch); - M2M_INFO("Curr driver ver: %u.%u.%u\n", M2M_DRIVER_VERSION_MAJOR_NO, M2M_DRIVER_VERSION_MINOR_NO, M2M_DRIVER_VERSION_PATCH_NO); - - if(strtmp.u8FirmwareMajor != M2M_DRIVER_VERSION_MAJOR_NO - || strtmp.u8FirmwareMinor != M2M_DRIVER_VERSION_MINOR_NO) - { - ret = M2M_ERR_FW_VER_MISMATCH; - M2M_ERR("Firmware version mismatch!\n"); - } return ret; ERR2: nm_bus_iface_deinit(); @@ -252,6 +372,13 @@ sint8 nm_drv_deinit(void * arg) M2M_ERR("[nmi stop]: chip_deinit fail\n"); goto ERR1; } + + /* Disable SPI flash to save power when the chip is off */ + ret = spi_flash_enable(0); + if (M2M_SUCCESS != ret) { + M2M_ERR("[nmi stop]: SPI flash disable fail\n"); + goto ERR1; + } ret = nm_bus_iface_deinit(); if (M2M_SUCCESS != ret) { diff --git a/src/winc1500/src/nmspi.c b/src/winc1500/src/nmspi.c index f29e6f08f..8beda7841 100644 --- a/src/winc1500/src/nmspi.c +++ b/src/winc1500/src/nmspi.c @@ -84,17 +84,12 @@ #define N_RESET -1 #define N_RETRY -2 - #define DATA_PKT_SZ_256 256 #define DATA_PKT_SZ_512 512 #define DATA_PKT_SZ_1K 1024 #define DATA_PKT_SZ_4K (4 * 1024) #define DATA_PKT_SZ_8K (8 * 1024) -#ifdef SAMG55 -#define DATA_PKT_SZ DATA_PKT_SZ_1K -#else #define DATA_PKT_SZ DATA_PKT_SZ_8K -#endif static uint8 gu8Crc_off = 0; @@ -176,25 +171,6 @@ static uint8 crc7(uint8 crc, const uint8 *buffer, uint32 len) ********************************************/ -#define CMD_DMA_WRITE 0xc1 -#define CMD_DMA_READ 0xc2 -#define CMD_INTERNAL_WRITE 0xc3 -#define CMD_INTERNAL_READ 0xc4 -#define CMD_TERMINATE 0xc5 -#define CMD_REPEAT 0xc6 -#define CMD_DMA_EXT_WRITE 0xc7 -#define CMD_DMA_EXT_READ 0xc8 -#define CMD_SINGLE_WRITE 0xc9 -#define CMD_SINGLE_READ 0xca -#define CMD_RESET 0xcf - -#define DATA_PKT_SZ_256 256 -#define DATA_PKT_SZ_512 512 -#define DATA_PKT_SZ_1K 1024 -#define DATA_PKT_SZ_4K (4 * 1024) -#define DATA_PKT_SZ_8K (8 * 1024) -#define DATA_PKT_SZ DATA_PKT_SZ_8K - static sint8 spi_cmd(uint8 cmd, uint32 adr, uint32 u32data, uint32 sz,uint8 clockless) { uint8 bc[9]; diff --git a/src/winc1500/src/socket.c b/src/winc1500/src/socket.c index 277fa1857..212a144ff 100644 --- a/src/winc1500/src/socket.c +++ b/src/winc1500/src/socket.c @@ -47,6 +47,7 @@ INCLUDES #include "socket/include/socket.h" #include "driver/include/m2m_hif.h" #include "socket/include/socket_internal.h" +#include "driver/include/m2m_types.h" /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* MACROS @@ -66,11 +67,15 @@ MACROS #define SSL_TX_PACKET_OFFSET (TCP_TX_PACKET_OFFSET + TLS_RECORD_HEADER_LENGTH) #define SOCKET_REQUEST(reqID, reqArgs, reqSize, reqPayload, reqPayloadSize, reqPayloadOffset) \ - hif_send(M2M_REQ_GRP_IP, reqID, reqArgs, reqSize, reqPayload, reqPayloadSize, reqPayloadOffset) + hif_send(M2M_REQ_GROUP_IP, reqID, reqArgs, reqSize, reqPayload, reqPayloadSize, reqPayloadOffset) -#define SSL_FLAGS_ACTIVE 0x01 -#define SSL_FLAGS_BYPASS_X509 0x02 +#define SSL_FLAGS_ACTIVE NBIT0 +#define SSL_FLAGS_BYPASS_X509 NBIT1 +#define SSL_FLAGS_2_RESERVD NBIT2 +#define SSL_FLAGS_3_RESERVD NBIT3 +#define SSL_FLAGS_CACHE_SESSION NBIT4 +#define SSL_FLAGS_NO_TX_COPY NBIT5 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* PRIVATE DATA TYPES @@ -93,10 +98,11 @@ typedef struct{ typedef struct{ uint8 *pu8UserBuffer; uint16 u16UserBufferSize; + uint16 u16SessionID; + uint16 u16DataOffset; uint8 bIsUsed; uint8 u8SSLFlags; uint8 bIsRecvPending; - uint16 u16SessionID; }tstrSocket; /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* @@ -113,6 +119,7 @@ volatile tpfAppSocketCb gpfAppSocketCb; volatile tpfAppResolveCb gpfAppResolveCb; volatile uint8 gbSocketInit = 0; volatile tpfPingCb gfpPingCb; + /********************************************************************* Function Socket_ReadSocketData @@ -255,6 +262,10 @@ static void m2m_ip_cb(uint8 u8OpCode, uint16 u16BufferSize,uint32 u32Address) { strConnMsg.sock = strConnectReply.sock; strConnMsg.s8Error = strConnectReply.s8Error; + if(strConnectReply.s8Error == SOCK_ERR_NO_ERROR) + { + gastrSockets[strConnectReply.sock].u16DataOffset = strConnectReply.u16AppDataOffset - M2M_HIF_HDR_OFFSET; + } if(gpfAppSocketCb) gpfAppSocketCb(strConnectReply.sock,SOCKET_MSG_CONNECT, &strConnMsg); } @@ -400,12 +411,11 @@ void socketInit(void) if(gbSocketInit==0) { m2m_memset((uint8*)gastrSockets, 0, MAX_SOCKET * sizeof(tstrSocket)); - hif_register_cb(M2M_REQ_GRP_IP,m2m_ip_cb); + hif_register_cb(M2M_REQ_GROUP_IP,m2m_ip_cb); gbSocketInit=1; gu16SessionID = 0; } } - /********************************************************************* Function socketDeinit @@ -427,13 +437,11 @@ Date void socketDeinit(void) { m2m_memset((uint8*)gastrSockets, 0, MAX_SOCKET * sizeof(tstrSocket)); - hif_register_cb(M2M_REQ_GRP_IP, NULL); + hif_register_cb(M2M_REQ_GROUP_IP, NULL); gpfAppSocketCb = NULL; gpfAppResolveCb = NULL; gbSocketInit = 0; } - - /********************************************************************* Function registerSocketCallback @@ -480,9 +488,10 @@ Date *********************************************************************/ SOCKET WINC1500_EXPORT(socket)(uint16 u16Domain, uint8 u8Type, uint8 u8Flags) { - SOCKET sock = -1; - uint8 u8Count,u8SocketCount = MAX_SOCKET; - + SOCKET sock = -1; + uint8 u8Count,u8SocketCount = MAX_SOCKET; + volatile tstrSocket *pstrSock; + /* The only supported family is the AF_INET for UDP and TCP transport layer protocols. */ if(u16Domain == AF_INET) { @@ -502,17 +511,20 @@ SOCKET WINC1500_EXPORT(socket)(uint16 u16Domain, uint8 u8Type, uint8 u8Flags) for(;u8Count < u8SocketCount; u8Count ++) { - if(gastrSockets[u8Count].bIsUsed == 0) + pstrSock = &gastrSockets[u8Count]; + if(pstrSock->bIsUsed == 0) { - gastrSockets[u8Count].bIsUsed = 1; - + m2m_memset((uint8*)pstrSock, 0, sizeof(tstrSocket)); + + pstrSock->bIsUsed = 1; + /* The session ID is used to distinguish different socket connections by comparing the assigned session ID to the one reported by the firmware*/ ++gu16SessionID; if(gu16SessionID == 0) ++gu16SessionID; - gastrSockets[u8Count].u16SessionID = gu16SessionID; + pstrSock->u16SessionID = gu16SessionID; M2M_DBG("1 Socket %d session ID = %d\r\n",u8Count, gu16SessionID ); sock = (SOCKET)u8Count; @@ -520,7 +532,7 @@ SOCKET WINC1500_EXPORT(socket)(uint16 u16Domain, uint8 u8Type, uint8 u8Flags) { tstrSSLSocketCreateCmd strSSLCreate; strSSLCreate.sslSock = sock; - gastrSockets[u8Count].u8SSLFlags = SSL_FLAGS_ACTIVE; + pstrSock->u8SSLFlags = SSL_FLAGS_ACTIVE | SSL_FLAGS_NO_TX_COPY; SOCKET_REQUEST(SOCKET_CMD_SSL_CREATE, (uint8*)&strSSLCreate, sizeof(tstrSSLSocketCreateCmd), 0, 0, 0); } break; @@ -558,7 +570,6 @@ sint8 WINC1500_EXPORT(bind)(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8Addr /* Build the bind request. */ strBind.sock = sock; m2m_memcpy((uint8 *)&strBind.strAddr, (uint8 *)pstrAddr, sizeof(tstrSockAddr)); - //strBind.strAddr = *((tstrSockAddr*)pstrAddr); strBind.strAddr.u16Family = strBind.strAddr.u16Family; strBind.strAddr.u16Port = strBind.strAddr.u16Port; @@ -675,9 +686,6 @@ sint8 WINC1500_EXPORT(connect)(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8A strConnect.sock = sock; m2m_memcpy((uint8 *)&strConnect.strAddr, (uint8 *)pstrAddr, sizeof(tstrSockAddr)); - strConnect.strAddr.u16Family = strConnect.strAddr.u16Family; - strConnect.strAddr.u16Port = strConnect.strAddr.u16Port; - strConnect.strAddr.u32IPAddr = strConnect.strAddr.u32IPAddr; strConnect.u16SessionID = gastrSockets[sock].u16SessionID; s8Ret = SOCKET_REQUEST(u8Cmd, (uint8*)&strConnect,sizeof(tstrConnectCmd), NULL, 0, 0); if(s8Ret != SOCK_ERR_NO_ERROR) @@ -717,9 +725,9 @@ sint16 WINC1500_EXPORT(send)(SOCKET sock, void *pvSendBuffer, uint16 u16SendLeng u8Cmd = SOCKET_CMD_SEND; u16DataOffset = TCP_TX_PACKET_OFFSET; - strSend.sock = sock; - strSend.u16DataSize = NM_BSP_B_L_16(u16SendLength); - strSend.u16SessionID = gastrSockets[sock].u16SessionID; + strSend.sock = sock; + strSend.u16DataSize = NM_BSP_B_L_16(u16SendLength); + strSend.u16SessionID = gastrSockets[sock].u16SessionID; if(sock >= TCP_SOCK_MAX) { @@ -728,7 +736,7 @@ sint16 WINC1500_EXPORT(send)(SOCKET sock, void *pvSendBuffer, uint16 u16SendLeng if(gastrSockets[sock].u8SSLFlags & SSL_FLAGS_ACTIVE) { u8Cmd = SOCKET_CMD_SSL_SEND; - u16DataOffset = SSL_TX_PACKET_OFFSET; + u16DataOffset = gastrSockets[sock].u16DataOffset; } s16Ret = SOCKET_REQUEST(u8Cmd|M2M_REQ_DATA_PKT, (uint8*)&strSend, sizeof(tstrSendCmd), pvSendBuffer, u16SendLength, u16DataOffset); @@ -770,7 +778,7 @@ sint16 WINC1500_EXPORT(sendto)(SOCKET sock, void *pvSendBuffer, uint16 u16SendLe strSendTo.sock = sock; strSendTo.u16DataSize = NM_BSP_B_L_16(u16SendLength); - strSendTo.u16SessionID = gastrSockets[sock].u16SessionID; + strSendTo.u16SessionID = gastrSockets[sock].u16SessionID; if(pstrDestAddr != NULL) { @@ -1060,7 +1068,7 @@ Version Date 9 September 2014 *********************************************************************/ -sint8 sslSetSockOpt(SOCKET sock, uint8 u8Opt, const void *pvOptVal, uint16 u16OptLen) +static sint8 sslSetSockOpt(SOCKET sock, uint8 u8Opt, const void *pvOptVal, uint16 u16OptLen) { sint8 s8Ret = SOCK_ERR_INVALID_ARG; if(sock < TCP_SOCK_MAX) @@ -1080,6 +1088,19 @@ sint8 sslSetSockOpt(SOCKET sock, uint8 u8Opt, const void *pvOptVal, uint16 u16O } s8Ret = SOCK_ERR_NO_ERROR; } + else if(u8Opt == SO_SSL_ENABLE_SESSION_CACHING) + { + int optVal = *((int*)pvOptVal); + if(optVal) + { + gastrSockets[sock].u8SSLFlags |= SSL_FLAGS_CACHE_SESSION; + } + else + { + gastrSockets[sock].u8SSLFlags &= ~SSL_FLAGS_CACHE_SESSION; + } + s8Ret = SOCK_ERR_NO_ERROR; + } else if(u8Opt == SO_SSL_SNI) { if(u16OptLen < HOSTNAME_MAX_SIZE) @@ -1222,3 +1243,33 @@ sint8 m2m_ping_req(uint32 u32DstIP, uint8 u8TTL, tpfPingCb fpPingCb) } return s8Ret; } +/********************************************************************* +Function + sslSetActiveCipherSuites + +Description + Send Ping request. + +Return + +Author + Ahmed Ezzat + +Version + 1.0 + +Date + 4 June 2015 +*********************************************************************/ +sint8 sslSetActiveCipherSuites(uint32 u32SslCsBMP) +{ + sint8 s8Ret = SOCK_ERR_INVALID_ARG; + if(u32SslCsBMP != 0) + { + tstrSslSetActiveCsList strCsList; + + strCsList.u32CsBMP = u32SslCsBMP; + s8Ret = SOCKET_REQUEST(SOCKET_CMD_SSL_SET_CS_LIST, (uint8*)&strCsList, sizeof(tstrSslSetActiveCsList), NULL, 0, 0); + } + return s8Ret; +}