Update revision to use TI's mqtt and Freertos.

Dependencies:   mbed client server

Fork of cc3100_Test_mqtt_CM3 by David Fletcher

Committer:
dflet
Date:
Thu Sep 03 14:02:37 2015 +0000
Revision:
3:a8c249046181
SPI Mode change 1 to 0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dflet 3:a8c249046181 1 /*
dflet 3:a8c249046181 2 * wlan.c - CC31xx/CC32xx Host Driver Implementation
dflet 3:a8c249046181 3 *
dflet 3:a8c249046181 4 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
dflet 3:a8c249046181 5 *
dflet 3:a8c249046181 6 *
dflet 3:a8c249046181 7 * Redistribution and use in source and binary forms, with or without
dflet 3:a8c249046181 8 * modification, are permitted provided that the following conditions
dflet 3:a8c249046181 9 * are met:
dflet 3:a8c249046181 10 *
dflet 3:a8c249046181 11 * Redistributions of source code must retain the above copyright
dflet 3:a8c249046181 12 * notice, this list of conditions and the following disclaimer.
dflet 3:a8c249046181 13 *
dflet 3:a8c249046181 14 * Redistributions in binary form must reproduce the above copyright
dflet 3:a8c249046181 15 * notice, this list of conditions and the following disclaimer in the
dflet 3:a8c249046181 16 * documentation and/or other materials provided with the
dflet 3:a8c249046181 17 * distribution.
dflet 3:a8c249046181 18 *
dflet 3:a8c249046181 19 * Neither the name of Texas Instruments Incorporated nor the names of
dflet 3:a8c249046181 20 * its contributors may be used to endorse or promote products derived
dflet 3:a8c249046181 21 * from this software without specific prior written permission.
dflet 3:a8c249046181 22 *
dflet 3:a8c249046181 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
dflet 3:a8c249046181 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
dflet 3:a8c249046181 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
dflet 3:a8c249046181 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
dflet 3:a8c249046181 27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
dflet 3:a8c249046181 28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
dflet 3:a8c249046181 29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
dflet 3:a8c249046181 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
dflet 3:a8c249046181 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
dflet 3:a8c249046181 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
dflet 3:a8c249046181 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dflet 3:a8c249046181 34 *
dflet 3:a8c249046181 35 */
dflet 3:a8c249046181 36
dflet 3:a8c249046181 37
dflet 3:a8c249046181 38
dflet 3:a8c249046181 39 /*****************************************************************************/
dflet 3:a8c249046181 40 /* Include files */
dflet 3:a8c249046181 41 /*****************************************************************************/
dflet 3:a8c249046181 42 #include "cc3100_simplelink.h"
dflet 3:a8c249046181 43 #include "cc3100_protocol.h"
dflet 3:a8c249046181 44 #include "cc3100_driver.h"
dflet 3:a8c249046181 45
dflet 3:a8c249046181 46 #include "cc3100_wlan.h"
dflet 3:a8c249046181 47 #include "cc3100_wlan_rx_filters.h"
dflet 3:a8c249046181 48
dflet 3:a8c249046181 49 /*****************************************************************************/
dflet 3:a8c249046181 50 /* Macro declarations */
dflet 3:a8c249046181 51 /*****************************************************************************/
dflet 3:a8c249046181 52 #define MAX_SSID_LEN (32)
dflet 3:a8c249046181 53 #define MAX_KEY_LEN (63)
dflet 3:a8c249046181 54 #define MAX_USER_LEN (32)
dflet 3:a8c249046181 55 #define MAX_ANON_USER_LEN (32)
dflet 3:a8c249046181 56 #define MAX_SMART_CONFIG_KEY (16)
dflet 3:a8c249046181 57
dflet 3:a8c249046181 58 namespace mbed_cc3100 {
dflet 3:a8c249046181 59
dflet 3:a8c249046181 60 cc3100_wlan::cc3100_wlan(cc3100_driver &driver, cc3100_wlan_rx_filters &wlan_filters)
dflet 3:a8c249046181 61 : _driver(driver), _wlan_filters(wlan_filters)
dflet 3:a8c249046181 62 {
dflet 3:a8c249046181 63
dflet 3:a8c249046181 64 }
dflet 3:a8c249046181 65
dflet 3:a8c249046181 66 cc3100_wlan::~cc3100_wlan()
dflet 3:a8c249046181 67 {
dflet 3:a8c249046181 68
dflet 3:a8c249046181 69 }
dflet 3:a8c249046181 70
dflet 3:a8c249046181 71 /*****************************************************************************
dflet 3:a8c249046181 72 sl_WlanConnect
dflet 3:a8c249046181 73 *****************************************************************************/
dflet 3:a8c249046181 74 typedef struct {
dflet 3:a8c249046181 75 _WlanConnectEapCommand_t Args;
dflet 3:a8c249046181 76 int8_t Strings[MAX_SSID_LEN + MAX_KEY_LEN + MAX_USER_LEN + MAX_ANON_USER_LEN];
dflet 3:a8c249046181 77 } _WlanConnectCmd_t;
dflet 3:a8c249046181 78
dflet 3:a8c249046181 79 typedef union {
dflet 3:a8c249046181 80 _WlanConnectCmd_t Cmd;
dflet 3:a8c249046181 81 _BasicResponse_t Rsp;
dflet 3:a8c249046181 82 } _SlWlanConnectMsg_u;
dflet 3:a8c249046181 83
dflet 3:a8c249046181 84
dflet 3:a8c249046181 85 #if _SL_INCLUDE_FUNC(sl_WlanConnect)
dflet 3:a8c249046181 86 int16_t cc3100_wlan::sl_WlanConnect(const signed char* pName, const int16_t NameLen, const uint8_t *pMacAddr, const SlSecParams_t* pSecParams , const SlSecParamsExt_t* pSecExtParams)
dflet 3:a8c249046181 87 {
dflet 3:a8c249046181 88 _SlWlanConnectMsg_u Msg = {0};
dflet 3:a8c249046181 89 _SlCmdCtrl_t CmdCtrl = {0};
dflet 3:a8c249046181 90
dflet 3:a8c249046181 91 CmdCtrl.TxDescLen = 0;/* init */
dflet 3:a8c249046181 92 CmdCtrl.RxDescLen = sizeof(_BasicResponse_t);
dflet 3:a8c249046181 93
dflet 3:a8c249046181 94 /* verify SSID length */
dflet 3:a8c249046181 95 VERIFY_PROTOCOL(NameLen <= MAX_SSID_LEN);
dflet 3:a8c249046181 96 /* verify SSID is not NULL */
dflet 3:a8c249046181 97 if( NULL == pName )
dflet 3:a8c249046181 98 {
dflet 3:a8c249046181 99 return SL_INVALPARAM;
dflet 3:a8c249046181 100 }
dflet 3:a8c249046181 101
dflet 3:a8c249046181 102 /* update SSID length */
dflet 3:a8c249046181 103 Msg.Cmd.Args.Common.SsidLen = (uint8_t)NameLen;
dflet 3:a8c249046181 104 /* Profile with no security */
dflet 3:a8c249046181 105 /* Enterprise security profile */
dflet 3:a8c249046181 106 if (NULL != pSecExtParams) {
dflet 3:a8c249046181 107 /* Update command opcode */
dflet 3:a8c249046181 108 CmdCtrl.Opcode = SL_OPCODE_WLAN_WLANCONNECTEAPCOMMAND;
dflet 3:a8c249046181 109 CmdCtrl.TxDescLen += sizeof(_WlanConnectEapCommand_t);
dflet 3:a8c249046181 110 /* copy SSID */
dflet 3:a8c249046181 111 memcpy(EAP_SSID_STRING(&Msg), pName, NameLen);
dflet 3:a8c249046181 112 CmdCtrl.TxDescLen += NameLen;
dflet 3:a8c249046181 113 /* Copy password if supplied */
dflet 3:a8c249046181 114 if ((NULL != pSecParams) && (pSecParams->KeyLen > 0)) {
dflet 3:a8c249046181 115 /* update security type */
dflet 3:a8c249046181 116 Msg.Cmd.Args.Common.SecType = pSecParams->Type;
dflet 3:a8c249046181 117 /* verify key length */
dflet 3:a8c249046181 118 if (pSecParams->KeyLen > MAX_KEY_LEN) {
dflet 3:a8c249046181 119 return SL_INVALPARAM;
dflet 3:a8c249046181 120 }
dflet 3:a8c249046181 121 /* update key length */
dflet 3:a8c249046181 122 Msg.Cmd.Args.Common.PasswordLen = pSecParams->KeyLen;
dflet 3:a8c249046181 123 ARG_CHECK_PTR(pSecParams->Key);
dflet 3:a8c249046181 124 /* copy key */
dflet 3:a8c249046181 125 memcpy(EAP_PASSWORD_STRING(&Msg), pSecParams->Key, pSecParams->KeyLen);
dflet 3:a8c249046181 126 CmdCtrl.TxDescLen += pSecParams->KeyLen;
dflet 3:a8c249046181 127 } else {
dflet 3:a8c249046181 128 Msg.Cmd.Args.Common.PasswordLen = 0;
dflet 3:a8c249046181 129 }
dflet 3:a8c249046181 130 ARG_CHECK_PTR(pSecExtParams);
dflet 3:a8c249046181 131 /* Update Eap bitmask */
dflet 3:a8c249046181 132 Msg.Cmd.Args.EapBitmask = pSecExtParams->EapMethod;
dflet 3:a8c249046181 133 /* Update Certificate file ID index - currently not supported */
dflet 3:a8c249046181 134 Msg.Cmd.Args.CertIndex = pSecExtParams->CertIndex;
dflet 3:a8c249046181 135 /* verify user length */
dflet 3:a8c249046181 136 if (pSecExtParams->UserLen > MAX_USER_LEN) {
dflet 3:a8c249046181 137 return SL_INVALPARAM;
dflet 3:a8c249046181 138 }
dflet 3:a8c249046181 139 Msg.Cmd.Args.UserLen = pSecExtParams->UserLen;
dflet 3:a8c249046181 140 /* copy user name (identity) */
dflet 3:a8c249046181 141 if(pSecExtParams->UserLen > 0) {
dflet 3:a8c249046181 142 memcpy(EAP_USER_STRING(&Msg), pSecExtParams->User, pSecExtParams->UserLen);
dflet 3:a8c249046181 143 CmdCtrl.TxDescLen += pSecExtParams->UserLen;
dflet 3:a8c249046181 144 }
dflet 3:a8c249046181 145 /* verify Anonymous user length */
dflet 3:a8c249046181 146 if (pSecExtParams->AnonUserLen > MAX_ANON_USER_LEN) {
dflet 3:a8c249046181 147 return SL_INVALPARAM;
dflet 3:a8c249046181 148 }
dflet 3:a8c249046181 149 Msg.Cmd.Args.AnonUserLen = pSecExtParams->AnonUserLen;
dflet 3:a8c249046181 150 /* copy Anonymous user */
dflet 3:a8c249046181 151 if(pSecExtParams->AnonUserLen > 0) {
dflet 3:a8c249046181 152 memcpy(EAP_ANON_USER_STRING(&Msg), pSecExtParams->AnonUser, pSecExtParams->AnonUserLen);
dflet 3:a8c249046181 153 CmdCtrl.TxDescLen += pSecExtParams->AnonUserLen;
dflet 3:a8c249046181 154 }
dflet 3:a8c249046181 155
dflet 3:a8c249046181 156 }
dflet 3:a8c249046181 157
dflet 3:a8c249046181 158 /* Regular or open security profile */
dflet 3:a8c249046181 159 else {
dflet 3:a8c249046181 160 /* Update command opcode */
dflet 3:a8c249046181 161 CmdCtrl.Opcode = SL_OPCODE_WLAN_WLANCONNECTCOMMAND;
dflet 3:a8c249046181 162 CmdCtrl.TxDescLen += sizeof(_WlanConnectCommon_t);
dflet 3:a8c249046181 163 /* copy SSID */
dflet 3:a8c249046181 164 memcpy(SSID_STRING(&Msg), pName, NameLen);
dflet 3:a8c249046181 165 CmdCtrl.TxDescLen += NameLen;
dflet 3:a8c249046181 166 /* Copy password if supplied */
dflet 3:a8c249046181 167 if( NULL != pSecParams ) {
dflet 3:a8c249046181 168 /* update security type */
dflet 3:a8c249046181 169 Msg.Cmd.Args.Common.SecType = pSecParams->Type;
dflet 3:a8c249046181 170 /* verify key length is valid */
dflet 3:a8c249046181 171 if (pSecParams->KeyLen > MAX_KEY_LEN) {
dflet 3:a8c249046181 172 return SL_INVALPARAM;
dflet 3:a8c249046181 173 }
dflet 3:a8c249046181 174 /* update key length */
dflet 3:a8c249046181 175 Msg.Cmd.Args.Common.PasswordLen = pSecParams->KeyLen;
dflet 3:a8c249046181 176 CmdCtrl.TxDescLen += pSecParams->KeyLen;
dflet 3:a8c249046181 177 /* copy key (could be no key in case of WPS pin) */
dflet 3:a8c249046181 178 if( NULL != pSecParams->Key ) {
dflet 3:a8c249046181 179 memcpy(PASSWORD_STRING(&Msg), pSecParams->Key, pSecParams->KeyLen);
dflet 3:a8c249046181 180 }
dflet 3:a8c249046181 181 }
dflet 3:a8c249046181 182 /* Profile with no security */
dflet 3:a8c249046181 183 else {
dflet 3:a8c249046181 184 Msg.Cmd.Args.Common.PasswordLen = 0;
dflet 3:a8c249046181 185 Msg.Cmd.Args.Common.SecType = SL_SEC_TYPE_OPEN;
dflet 3:a8c249046181 186 }
dflet 3:a8c249046181 187 }
dflet 3:a8c249046181 188 /* If BSSID is not null, copy to buffer, otherwise set to 0 */
dflet 3:a8c249046181 189 if(NULL != pMacAddr) {
dflet 3:a8c249046181 190 memcpy(Msg.Cmd.Args.Common.Bssid, pMacAddr, sizeof(Msg.Cmd.Args.Common.Bssid));
dflet 3:a8c249046181 191 } else {
dflet 3:a8c249046181 192 _driver._SlDrvMemZero(Msg.Cmd.Args.Common.Bssid, sizeof(Msg.Cmd.Args.Common.Bssid));
dflet 3:a8c249046181 193 }
dflet 3:a8c249046181 194
dflet 3:a8c249046181 195 VERIFY_RET_OK ( _driver._SlDrvCmdOp(&CmdCtrl, &Msg, NULL));
dflet 3:a8c249046181 196 return (int16_t)Msg.Rsp.status;
dflet 3:a8c249046181 197 }
dflet 3:a8c249046181 198 #endif
dflet 3:a8c249046181 199
dflet 3:a8c249046181 200 /*******************************************************************************/
dflet 3:a8c249046181 201 /* sl_Disconnect */
dflet 3:a8c249046181 202 /* ******************************************************************************/
dflet 3:a8c249046181 203 #if _SL_INCLUDE_FUNC(sl_WlanDisconnect)
dflet 3:a8c249046181 204 int16_t cc3100_wlan::sl_WlanDisconnect(void)
dflet 3:a8c249046181 205 {
dflet 3:a8c249046181 206 return _driver._SlDrvBasicCmd(SL_OPCODE_WLAN_WLANDISCONNECTCOMMAND);
dflet 3:a8c249046181 207 }
dflet 3:a8c249046181 208 #endif
dflet 3:a8c249046181 209
dflet 3:a8c249046181 210 /******************************************************************************/
dflet 3:a8c249046181 211 /* sl_PolicySet */
dflet 3:a8c249046181 212 /******************************************************************************/
dflet 3:a8c249046181 213 typedef union {
dflet 3:a8c249046181 214 _WlanPoliciySetGet_t Cmd;
dflet 3:a8c249046181 215 _BasicResponse_t Rsp;
dflet 3:a8c249046181 216 } _SlPolicyMsg_u;
dflet 3:a8c249046181 217
dflet 3:a8c249046181 218 #if _SL_INCLUDE_FUNC(sl_WlanPolicySet)
dflet 3:a8c249046181 219 const _SlCmdCtrl_t _SlPolicySetCmdCtrl = {
dflet 3:a8c249046181 220 SL_OPCODE_WLAN_POLICYSETCOMMAND,
dflet 3:a8c249046181 221 sizeof(_WlanPoliciySetGet_t),
dflet 3:a8c249046181 222 sizeof(_BasicResponse_t)
dflet 3:a8c249046181 223 };
dflet 3:a8c249046181 224
dflet 3:a8c249046181 225 int16_t cc3100_wlan::sl_WlanPolicySet(const uint8_t Type , const uint8_t Policy, uint8_t *pVal, const uint8_t ValLen)
dflet 3:a8c249046181 226 {
dflet 3:a8c249046181 227
dflet 3:a8c249046181 228 _SlPolicyMsg_u Msg;
dflet 3:a8c249046181 229 _SlCmdExt_t CmdExt;
dflet 3:a8c249046181 230
dflet 3:a8c249046181 231 _driver._SlDrvResetCmdExt(&CmdExt);
dflet 3:a8c249046181 232 CmdExt.TxPayloadLen = ValLen;
dflet 3:a8c249046181 233 CmdExt.pTxPayload = (uint8_t *)pVal;
dflet 3:a8c249046181 234
dflet 3:a8c249046181 235 Msg.Cmd.PolicyType = Type;
dflet 3:a8c249046181 236 Msg.Cmd.PolicyOption = Policy;
dflet 3:a8c249046181 237 Msg.Cmd.PolicyOptionLen = ValLen;
dflet 3:a8c249046181 238
dflet 3:a8c249046181 239 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlPolicySetCmdCtrl, &Msg, &CmdExt));
dflet 3:a8c249046181 240
dflet 3:a8c249046181 241 return (int16_t)Msg.Rsp.status;
dflet 3:a8c249046181 242 }
dflet 3:a8c249046181 243 #endif
dflet 3:a8c249046181 244
dflet 3:a8c249046181 245
dflet 3:a8c249046181 246 /******************************************************************************/
dflet 3:a8c249046181 247 /* sl_PolicyGet */
dflet 3:a8c249046181 248 /******************************************************************************/
dflet 3:a8c249046181 249 typedef union {
dflet 3:a8c249046181 250 _WlanPoliciySetGet_t Cmd;
dflet 3:a8c249046181 251 _WlanPoliciySetGet_t Rsp;
dflet 3:a8c249046181 252 } _SlPolicyGetMsg_u;
dflet 3:a8c249046181 253
dflet 3:a8c249046181 254 #if _SL_INCLUDE_FUNC(sl_WlanPolicyGet)
dflet 3:a8c249046181 255 const _SlCmdCtrl_t _SlPolicyGetCmdCtrl = {
dflet 3:a8c249046181 256 SL_OPCODE_WLAN_POLICYGETCOMMAND,
dflet 3:a8c249046181 257 sizeof(_WlanPoliciySetGet_t),
dflet 3:a8c249046181 258 sizeof(_WlanPoliciySetGet_t)
dflet 3:a8c249046181 259 };
dflet 3:a8c249046181 260
dflet 3:a8c249046181 261 int16_t cc3100_wlan::sl_WlanPolicyGet(const uint8_t Type , uint8_t Policy,uint8_t *pVal,uint8_t *pValLen)
dflet 3:a8c249046181 262 {
dflet 3:a8c249046181 263 _SlPolicyGetMsg_u Msg;
dflet 3:a8c249046181 264 _SlCmdExt_t CmdExt;
dflet 3:a8c249046181 265
dflet 3:a8c249046181 266 if (*pValLen == 0) {
dflet 3:a8c249046181 267 return SL_EZEROLEN;
dflet 3:a8c249046181 268 }
dflet 3:a8c249046181 269 _driver._SlDrvResetCmdExt(&CmdExt);
dflet 3:a8c249046181 270 CmdExt.RxPayloadLen = *pValLen;
dflet 3:a8c249046181 271 CmdExt.pRxPayload = pVal;
dflet 3:a8c249046181 272
dflet 3:a8c249046181 273 Msg.Cmd.PolicyType = Type;
dflet 3:a8c249046181 274 Msg.Cmd.PolicyOption = Policy;
dflet 3:a8c249046181 275 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlPolicyGetCmdCtrl, &Msg, &CmdExt));
dflet 3:a8c249046181 276
dflet 3:a8c249046181 277
dflet 3:a8c249046181 278 if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen) {
dflet 3:a8c249046181 279 *pValLen = Msg.Rsp.PolicyOptionLen;
dflet 3:a8c249046181 280 return SL_ESMALLBUF;
dflet 3:a8c249046181 281 } else {
dflet 3:a8c249046181 282 /* no pointer valus, fill the results into int8_t */
dflet 3:a8c249046181 283 *pValLen = (uint8_t)CmdExt.ActualRxPayloadLen;
dflet 3:a8c249046181 284 if( 0 == CmdExt.ActualRxPayloadLen ) {
dflet 3:a8c249046181 285 *pValLen = 1;
dflet 3:a8c249046181 286 pVal[0] = Msg.Rsp.PolicyOption;
dflet 3:a8c249046181 287 }
dflet 3:a8c249046181 288 }
dflet 3:a8c249046181 289 return (int16_t)SL_OS_RET_CODE_OK;
dflet 3:a8c249046181 290 }
dflet 3:a8c249046181 291 #endif
dflet 3:a8c249046181 292
dflet 3:a8c249046181 293
dflet 3:a8c249046181 294 /*******************************************************************************/
dflet 3:a8c249046181 295 /* sl_ProfileAdd */
dflet 3:a8c249046181 296 /*******************************************************************************/
dflet 3:a8c249046181 297 typedef struct {
dflet 3:a8c249046181 298 _WlanAddGetEapProfile_t Args;
dflet 3:a8c249046181 299 int8_t Strings[MAX_SSID_LEN + MAX_KEY_LEN + MAX_USER_LEN + MAX_ANON_USER_LEN];
dflet 3:a8c249046181 300 } _SlProfileParams_t;
dflet 3:a8c249046181 301
dflet 3:a8c249046181 302 typedef union {
dflet 3:a8c249046181 303 _SlProfileParams_t Cmd;
dflet 3:a8c249046181 304 _BasicResponse_t Rsp;
dflet 3:a8c249046181 305 } _SlProfileAddMsg_u;
dflet 3:a8c249046181 306
dflet 3:a8c249046181 307
dflet 3:a8c249046181 308
dflet 3:a8c249046181 309 #if _SL_INCLUDE_FUNC(sl_WlanProfileAdd)
dflet 3:a8c249046181 310 int16_t cc3100_wlan::sl_WlanProfileAdd(const int8_t* pName,
dflet 3:a8c249046181 311 const int16_t NameLen,
dflet 3:a8c249046181 312 const uint8_t *pMacAddr,
dflet 3:a8c249046181 313 const SlSecParams_t* pSecParams ,
dflet 3:a8c249046181 314 const SlSecParamsExt_t* pSecExtParams,
dflet 3:a8c249046181 315 const uint32_t Priority,
dflet 3:a8c249046181 316 const uint32_t Options)
dflet 3:a8c249046181 317 {
dflet 3:a8c249046181 318 _SlProfileAddMsg_u Msg;
dflet 3:a8c249046181 319 _SlCmdCtrl_t CmdCtrl = {0};
dflet 3:a8c249046181 320 CmdCtrl.TxDescLen = 0;/* init */
dflet 3:a8c249046181 321 CmdCtrl.RxDescLen = sizeof(_BasicResponse_t);
dflet 3:a8c249046181 322
dflet 3:a8c249046181 323 /* update priority */
dflet 3:a8c249046181 324 Msg.Cmd.Args.Common.Priority = (uint8_t)Priority;
dflet 3:a8c249046181 325 /* verify SSID is not NULL */
dflet 3:a8c249046181 326 if( NULL == pName )
dflet 3:a8c249046181 327 {
dflet 3:a8c249046181 328 return SL_INVALPARAM;
dflet 3:a8c249046181 329 }
dflet 3:a8c249046181 330
dflet 3:a8c249046181 331 /* verify SSID length */
dflet 3:a8c249046181 332 VERIFY_PROTOCOL(NameLen <= MAX_SSID_LEN);
dflet 3:a8c249046181 333 /* update SSID length */
dflet 3:a8c249046181 334 Msg.Cmd.Args.Common.SsidLen = (uint8_t)NameLen;
dflet 3:a8c249046181 335
dflet 3:a8c249046181 336
dflet 3:a8c249046181 337 /* Enterprise security profile */
dflet 3:a8c249046181 338 if (NULL != pSecExtParams) {
dflet 3:a8c249046181 339 /* Update command opcode */
dflet 3:a8c249046181 340 CmdCtrl.Opcode = SL_OPCODE_WLAN_EAP_PROFILEADDCOMMAND;
dflet 3:a8c249046181 341 CmdCtrl.TxDescLen += sizeof(_WlanAddGetEapProfile_t);
dflet 3:a8c249046181 342
dflet 3:a8c249046181 343 /* copy SSID */
dflet 3:a8c249046181 344 memcpy(EAP_PROFILE_SSID_STRING(&Msg), pName, NameLen);
dflet 3:a8c249046181 345 CmdCtrl.TxDescLen += NameLen;
dflet 3:a8c249046181 346
dflet 3:a8c249046181 347 /* Copy password if supplied */
dflet 3:a8c249046181 348 if ((NULL != pSecParams) && (pSecParams->KeyLen > 0)) {
dflet 3:a8c249046181 349 /* update security type */
dflet 3:a8c249046181 350 Msg.Cmd.Args.Common.SecType = pSecParams->Type;
dflet 3:a8c249046181 351
dflet 3:a8c249046181 352 if( SL_SEC_TYPE_WEP == Msg.Cmd.Args.Common.SecType ) {
dflet 3:a8c249046181 353 Msg.Cmd.Args.Common.WepKeyId = 0;
dflet 3:a8c249046181 354 }
dflet 3:a8c249046181 355
dflet 3:a8c249046181 356 /* verify key length */
dflet 3:a8c249046181 357 if (pSecParams->KeyLen > MAX_KEY_LEN) {
dflet 3:a8c249046181 358 return SL_INVALPARAM;
dflet 3:a8c249046181 359 }
dflet 3:a8c249046181 360 VERIFY_PROTOCOL(pSecParams->KeyLen <= MAX_KEY_LEN);
dflet 3:a8c249046181 361 /* update key length */
dflet 3:a8c249046181 362 Msg.Cmd.Args.Common.PasswordLen = pSecParams->KeyLen;
dflet 3:a8c249046181 363 CmdCtrl.TxDescLen += pSecParams->KeyLen;
dflet 3:a8c249046181 364 ARG_CHECK_PTR(pSecParams->Key);
dflet 3:a8c249046181 365 /* copy key */
dflet 3:a8c249046181 366 memcpy(EAP_PROFILE_PASSWORD_STRING(&Msg), pSecParams->Key, pSecParams->KeyLen);
dflet 3:a8c249046181 367 } else {
dflet 3:a8c249046181 368 Msg.Cmd.Args.Common.PasswordLen = 0;
dflet 3:a8c249046181 369 }
dflet 3:a8c249046181 370
dflet 3:a8c249046181 371 ARG_CHECK_PTR(pSecExtParams);
dflet 3:a8c249046181 372 /* Update Eap bitmask */
dflet 3:a8c249046181 373 Msg.Cmd.Args.EapBitmask = pSecExtParams->EapMethod;
dflet 3:a8c249046181 374 /* Update Certificate file ID index - currently not supported */
dflet 3:a8c249046181 375 Msg.Cmd.Args.CertIndex = pSecExtParams->CertIndex;
dflet 3:a8c249046181 376 /* verify user length */
dflet 3:a8c249046181 377 if (pSecExtParams->UserLen > MAX_USER_LEN) {
dflet 3:a8c249046181 378 return SL_INVALPARAM;
dflet 3:a8c249046181 379 }
dflet 3:a8c249046181 380 Msg.Cmd.Args.UserLen = pSecExtParams->UserLen;
dflet 3:a8c249046181 381 /* copy user name (identity) */
dflet 3:a8c249046181 382 if(pSecExtParams->UserLen > 0) {
dflet 3:a8c249046181 383 memcpy(EAP_PROFILE_USER_STRING(&Msg), pSecExtParams->User, pSecExtParams->UserLen);
dflet 3:a8c249046181 384 CmdCtrl.TxDescLen += pSecExtParams->UserLen;
dflet 3:a8c249046181 385 }
dflet 3:a8c249046181 386
dflet 3:a8c249046181 387 /* verify Anonymous user length (for tunneled) */
dflet 3:a8c249046181 388 if (pSecExtParams->AnonUserLen > MAX_ANON_USER_LEN) {
dflet 3:a8c249046181 389 return SL_INVALPARAM;
dflet 3:a8c249046181 390 }
dflet 3:a8c249046181 391 Msg.Cmd.Args.AnonUserLen = pSecExtParams->AnonUserLen;
dflet 3:a8c249046181 392
dflet 3:a8c249046181 393 /* copy Anonymous user */
dflet 3:a8c249046181 394 if(pSecExtParams->AnonUserLen > 0) {
dflet 3:a8c249046181 395 memcpy(EAP_PROFILE_ANON_USER_STRING(&Msg), pSecExtParams->AnonUser, pSecExtParams->AnonUserLen);
dflet 3:a8c249046181 396 CmdCtrl.TxDescLen += pSecExtParams->AnonUserLen;
dflet 3:a8c249046181 397 }
dflet 3:a8c249046181 398
dflet 3:a8c249046181 399 }
dflet 3:a8c249046181 400 /* Regular or open security profile */
dflet 3:a8c249046181 401 else {
dflet 3:a8c249046181 402 /* Update command opcode */
dflet 3:a8c249046181 403 CmdCtrl.Opcode = SL_OPCODE_WLAN_PROFILEADDCOMMAND;
dflet 3:a8c249046181 404 /* update commnad length */
dflet 3:a8c249046181 405 CmdCtrl.TxDescLen += sizeof(_WlanAddGetProfile_t);
dflet 3:a8c249046181 406
dflet 3:a8c249046181 407 if (NULL != pName) {
dflet 3:a8c249046181 408 /* copy SSID */
dflet 3:a8c249046181 409 memcpy(PROFILE_SSID_STRING(&Msg), pName, NameLen);
dflet 3:a8c249046181 410 CmdCtrl.TxDescLen += NameLen;
dflet 3:a8c249046181 411 }
dflet 3:a8c249046181 412
dflet 3:a8c249046181 413 /* Copy password if supplied */
dflet 3:a8c249046181 414 if( NULL != pSecParams ) {
dflet 3:a8c249046181 415 /* update security type */
dflet 3:a8c249046181 416 Msg.Cmd.Args.Common.SecType = pSecParams->Type;
dflet 3:a8c249046181 417
dflet 3:a8c249046181 418 if( SL_SEC_TYPE_WEP == Msg.Cmd.Args.Common.SecType ) {
dflet 3:a8c249046181 419 Msg.Cmd.Args.Common.WepKeyId = 0;
dflet 3:a8c249046181 420 }
dflet 3:a8c249046181 421
dflet 3:a8c249046181 422 /* verify key length */
dflet 3:a8c249046181 423 if (pSecParams->KeyLen > MAX_KEY_LEN) {
dflet 3:a8c249046181 424 return SL_INVALPARAM;
dflet 3:a8c249046181 425 }
dflet 3:a8c249046181 426 /* update key length */
dflet 3:a8c249046181 427 Msg.Cmd.Args.Common.PasswordLen = pSecParams->KeyLen;
dflet 3:a8c249046181 428 CmdCtrl.TxDescLen += pSecParams->KeyLen;
dflet 3:a8c249046181 429 /* copy key (could be no key in case of WPS pin) */
dflet 3:a8c249046181 430 if( NULL != pSecParams->Key ) {
dflet 3:a8c249046181 431 memcpy(PROFILE_PASSWORD_STRING(&Msg), pSecParams->Key, pSecParams->KeyLen);
dflet 3:a8c249046181 432 }
dflet 3:a8c249046181 433 } else {
dflet 3:a8c249046181 434 Msg.Cmd.Args.Common.SecType = SL_SEC_TYPE_OPEN;
dflet 3:a8c249046181 435 Msg.Cmd.Args.Common.PasswordLen = 0;
dflet 3:a8c249046181 436 }
dflet 3:a8c249046181 437
dflet 3:a8c249046181 438 }
dflet 3:a8c249046181 439
dflet 3:a8c249046181 440
dflet 3:a8c249046181 441 /* If BSSID is not null, copy to buffer, otherwise set to 0 */
dflet 3:a8c249046181 442 if(NULL != pMacAddr) {
dflet 3:a8c249046181 443 memcpy(Msg.Cmd.Args.Common.Bssid, pMacAddr, sizeof(Msg.Cmd.Args.Common.Bssid));
dflet 3:a8c249046181 444 } else {
dflet 3:a8c249046181 445 _driver._SlDrvMemZero(Msg.Cmd.Args.Common.Bssid, sizeof(Msg.Cmd.Args.Common.Bssid));
dflet 3:a8c249046181 446 }
dflet 3:a8c249046181 447
dflet 3:a8c249046181 448 VERIFY_RET_OK(_driver._SlDrvCmdOp(&CmdCtrl, &Msg, NULL));
dflet 3:a8c249046181 449
dflet 3:a8c249046181 450 return (int16_t)Msg.Rsp.status;
dflet 3:a8c249046181 451 }
dflet 3:a8c249046181 452 #endif
dflet 3:a8c249046181 453
dflet 3:a8c249046181 454 /*******************************************************************************/
dflet 3:a8c249046181 455 /* sl_ProfileGet */
dflet 3:a8c249046181 456 /*******************************************************************************/
dflet 3:a8c249046181 457 typedef union {
dflet 3:a8c249046181 458 _WlanProfileDelGetCommand_t Cmd;
dflet 3:a8c249046181 459 _SlProfileParams_t Rsp;
dflet 3:a8c249046181 460 } _SlProfileGetMsg_u;
dflet 3:a8c249046181 461
dflet 3:a8c249046181 462 #if _SL_INCLUDE_FUNC(sl_WlanProfileGet)
dflet 3:a8c249046181 463 const _SlCmdCtrl_t _SlProfileGetCmdCtrl = {
dflet 3:a8c249046181 464 SL_OPCODE_WLAN_PROFILEGETCOMMAND,
dflet 3:a8c249046181 465 sizeof(_WlanProfileDelGetCommand_t),
dflet 3:a8c249046181 466 sizeof(_SlProfileParams_t)
dflet 3:a8c249046181 467 };
dflet 3:a8c249046181 468
dflet 3:a8c249046181 469 int16_t cc3100_wlan::sl_WlanProfileGet(const int16_t Index,int8_t* pName, int16_t *pNameLen, uint8_t *pMacAddr, SlSecParams_t* pSecParams, SlGetSecParamsExt_t* pEntParams, uint32_t *pPriority)
dflet 3:a8c249046181 470 {
dflet 3:a8c249046181 471 _SlProfileGetMsg_u Msg;
dflet 3:a8c249046181 472 Msg.Cmd.index = (uint8_t)Index;
dflet 3:a8c249046181 473
dflet 3:a8c249046181 474 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlProfileGetCmdCtrl, &Msg, NULL));
dflet 3:a8c249046181 475
dflet 3:a8c249046181 476 pSecParams->Type = Msg.Rsp.Args.Common.SecType;
dflet 3:a8c249046181 477 /* since password is not transferred in getprofile, password length should always be zero */
dflet 3:a8c249046181 478 pSecParams->KeyLen = Msg.Rsp.Args.Common.PasswordLen;
dflet 3:a8c249046181 479 if (NULL != pEntParams) {
dflet 3:a8c249046181 480 pEntParams->UserLen = Msg.Rsp.Args.UserLen;
dflet 3:a8c249046181 481 /* copy user name */
dflet 3:a8c249046181 482 if (pEntParams->UserLen > 0) {
dflet 3:a8c249046181 483 memcpy(pEntParams->User, EAP_PROFILE_USER_STRING(&Msg), pEntParams->UserLen);
dflet 3:a8c249046181 484 }
dflet 3:a8c249046181 485 pEntParams->AnonUserLen = Msg.Rsp.Args.AnonUserLen;
dflet 3:a8c249046181 486 /* copy anonymous user name */
dflet 3:a8c249046181 487 if (pEntParams->AnonUserLen > 0) {
dflet 3:a8c249046181 488 memcpy(pEntParams->AnonUser, EAP_PROFILE_ANON_USER_STRING(&Msg), pEntParams->AnonUserLen);
dflet 3:a8c249046181 489 }
dflet 3:a8c249046181 490 }
dflet 3:a8c249046181 491
dflet 3:a8c249046181 492 *pNameLen = Msg.Rsp.Args.Common.SsidLen;
dflet 3:a8c249046181 493 *pPriority = Msg.Rsp.Args.Common.Priority;
dflet 3:a8c249046181 494
dflet 3:a8c249046181 495 if (NULL != Msg.Rsp.Args.Common.Bssid) {
dflet 3:a8c249046181 496 memcpy(pMacAddr, Msg.Rsp.Args.Common.Bssid, sizeof(Msg.Rsp.Args.Common.Bssid));
dflet 3:a8c249046181 497 }
dflet 3:a8c249046181 498
dflet 3:a8c249046181 499 memcpy(pName, EAP_PROFILE_SSID_STRING(&Msg), *pNameLen);
dflet 3:a8c249046181 500
dflet 3:a8c249046181 501 return (int16_t)Msg.Rsp.Args.Common.SecType;
dflet 3:a8c249046181 502
dflet 3:a8c249046181 503 }
dflet 3:a8c249046181 504 #endif
dflet 3:a8c249046181 505
dflet 3:a8c249046181 506 /*******************************************************************************/
dflet 3:a8c249046181 507 /* sl_ProfileDel */
dflet 3:a8c249046181 508 /*******************************************************************************/
dflet 3:a8c249046181 509 typedef union {
dflet 3:a8c249046181 510 _WlanProfileDelGetCommand_t Cmd;
dflet 3:a8c249046181 511 _BasicResponse_t Rsp;
dflet 3:a8c249046181 512 } _SlProfileDelMsg_u;
dflet 3:a8c249046181 513
dflet 3:a8c249046181 514 #if _SL_INCLUDE_FUNC(sl_WlanProfileDel)
dflet 3:a8c249046181 515 const _SlCmdCtrl_t _SlProfileDelCmdCtrl = {
dflet 3:a8c249046181 516 SL_OPCODE_WLAN_PROFILEDELCOMMAND,
dflet 3:a8c249046181 517 sizeof(_WlanProfileDelGetCommand_t),
dflet 3:a8c249046181 518 sizeof(_BasicResponse_t)
dflet 3:a8c249046181 519 };
dflet 3:a8c249046181 520
dflet 3:a8c249046181 521 int16_t cc3100_wlan::sl_WlanProfileDel(const int16_t Index)
dflet 3:a8c249046181 522 {
dflet 3:a8c249046181 523 _SlProfileDelMsg_u Msg;
dflet 3:a8c249046181 524
dflet 3:a8c249046181 525 Msg.Cmd.index = (uint8_t)Index;
dflet 3:a8c249046181 526
dflet 3:a8c249046181 527 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlProfileDelCmdCtrl, &Msg, NULL));
dflet 3:a8c249046181 528
dflet 3:a8c249046181 529 return (int16_t)Msg.Rsp.status;
dflet 3:a8c249046181 530 }
dflet 3:a8c249046181 531 #endif
dflet 3:a8c249046181 532
dflet 3:a8c249046181 533 /******************************************************************************/
dflet 3:a8c249046181 534 /* sl_WlanGetNetworkList */
dflet 3:a8c249046181 535 /******************************************************************************/
dflet 3:a8c249046181 536 typedef union {
dflet 3:a8c249046181 537 _WlanGetNetworkListCommand_t Cmd;
dflet 3:a8c249046181 538 _WlanGetNetworkListResponse_t Rsp;
dflet 3:a8c249046181 539 } _SlWlanGetNetworkListMsg_u;
dflet 3:a8c249046181 540
dflet 3:a8c249046181 541 #if _SL_INCLUDE_FUNC(sl_WlanGetNetworkList)
dflet 3:a8c249046181 542 const _SlCmdCtrl_t _SlWlanGetNetworkListCtrl = {
dflet 3:a8c249046181 543 SL_OPCODE_WLAN_SCANRESULTSGETCOMMAND,
dflet 3:a8c249046181 544 sizeof(_WlanGetNetworkListCommand_t),
dflet 3:a8c249046181 545 sizeof(_WlanGetNetworkListResponse_t)
dflet 3:a8c249046181 546 };
dflet 3:a8c249046181 547
dflet 3:a8c249046181 548 int16_t cc3100_wlan::sl_WlanGetNetworkList(const uint8_t Index, const uint8_t Count, Sl_WlanNetworkEntry_t *pEntries)
dflet 3:a8c249046181 549 {
dflet 3:a8c249046181 550 int16_t retVal = 0;
dflet 3:a8c249046181 551 _SlWlanGetNetworkListMsg_u Msg;
dflet 3:a8c249046181 552 _SlCmdExt_t CmdExt;
dflet 3:a8c249046181 553
dflet 3:a8c249046181 554 if (Count == 0) {
dflet 3:a8c249046181 555 return SL_EZEROLEN;
dflet 3:a8c249046181 556 }
dflet 3:a8c249046181 557
dflet 3:a8c249046181 558 _driver._SlDrvResetCmdExt(&CmdExt);
dflet 3:a8c249046181 559 CmdExt.RxPayloadLen = sizeof(Sl_WlanNetworkEntry_t)*(Count);
dflet 3:a8c249046181 560 CmdExt.pRxPayload = (uint8_t *)pEntries;
dflet 3:a8c249046181 561
dflet 3:a8c249046181 562 Msg.Cmd.index = Index;
dflet 3:a8c249046181 563 Msg.Cmd.count = Count;
dflet 3:a8c249046181 564
dflet 3:a8c249046181 565 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlWlanGetNetworkListCtrl, &Msg, &CmdExt));
dflet 3:a8c249046181 566 retVal = Msg.Rsp.status;
dflet 3:a8c249046181 567
dflet 3:a8c249046181 568 return (int16_t)retVal;
dflet 3:a8c249046181 569 }
dflet 3:a8c249046181 570 #endif
dflet 3:a8c249046181 571
dflet 3:a8c249046181 572 /*******************************************************************************/
dflet 3:a8c249046181 573 /* sl_WlanRxStatStart */
dflet 3:a8c249046181 574 /*******************************************************************************/
dflet 3:a8c249046181 575 #if _SL_INCLUDE_FUNC(sl_WlanRxStatStart)
dflet 3:a8c249046181 576 int16_t cc3100_wlan::sl_WlanRxStatStart(void)
dflet 3:a8c249046181 577 {
dflet 3:a8c249046181 578 return _driver._SlDrvBasicCmd(SL_OPCODE_WLAN_STARTRXSTATCOMMAND);
dflet 3:a8c249046181 579 }
dflet 3:a8c249046181 580 #endif
dflet 3:a8c249046181 581
dflet 3:a8c249046181 582 #if _SL_INCLUDE_FUNC(sl_WlanRxStatStop)
dflet 3:a8c249046181 583 int16_t cc3100_wlan::sl_WlanRxStatStop(void)
dflet 3:a8c249046181 584 {
dflet 3:a8c249046181 585 return _driver._SlDrvBasicCmd(SL_OPCODE_WLAN_STOPRXSTATCOMMAND);
dflet 3:a8c249046181 586 }
dflet 3:a8c249046181 587 #endif
dflet 3:a8c249046181 588
dflet 3:a8c249046181 589 #if _SL_INCLUDE_FUNC(sl_WlanRxStatGet)
dflet 3:a8c249046181 590 int16_t cc3100_wlan::sl_WlanRxStatGet(SlGetRxStatResponse_t *pRxStat, const uint32_t Flags)
dflet 3:a8c249046181 591 {
dflet 3:a8c249046181 592 _SlCmdCtrl_t CmdCtrl = {SL_OPCODE_WLAN_GETRXSTATCOMMAND, 0, sizeof(SlGetRxStatResponse_t)};
dflet 3:a8c249046181 593 _driver._SlDrvMemZero(pRxStat, sizeof(SlGetRxStatResponse_t));
dflet 3:a8c249046181 594 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&CmdCtrl, pRxStat, NULL));
dflet 3:a8c249046181 595
dflet 3:a8c249046181 596 return 0;
dflet 3:a8c249046181 597 }
dflet 3:a8c249046181 598 #endif
dflet 3:a8c249046181 599
dflet 3:a8c249046181 600
dflet 3:a8c249046181 601
dflet 3:a8c249046181 602 /******************************************************************************/
dflet 3:a8c249046181 603 /* sl_WlanSmartConfigStop */
dflet 3:a8c249046181 604 /******************************************************************************/
dflet 3:a8c249046181 605 #if _SL_INCLUDE_FUNC(sl_WlanSmartConfigStop)
dflet 3:a8c249046181 606 int16_t cc3100_wlan::sl_WlanSmartConfigStop(void)
dflet 3:a8c249046181 607 {
dflet 3:a8c249046181 608 return _driver._SlDrvBasicCmd(SL_OPCODE_WLAN_SMART_CONFIG_STOP_COMMAND);
dflet 3:a8c249046181 609 }
dflet 3:a8c249046181 610 #endif
dflet 3:a8c249046181 611
dflet 3:a8c249046181 612
dflet 3:a8c249046181 613 /******************************************************************************/
dflet 3:a8c249046181 614 /* sl_WlanSmartConfigStart */
dflet 3:a8c249046181 615 /******************************************************************************/
dflet 3:a8c249046181 616
dflet 3:a8c249046181 617
dflet 3:a8c249046181 618 typedef struct {
dflet 3:a8c249046181 619 _WlanSmartConfigStartCommand_t Args;
dflet 3:a8c249046181 620 int8_t Strings[3 * MAX_SMART_CONFIG_KEY]; /* public key + groupId1 key + groupId2 key */
dflet 3:a8c249046181 621 } _SlSmartConfigStart_t;
dflet 3:a8c249046181 622
dflet 3:a8c249046181 623 typedef union {
dflet 3:a8c249046181 624 _SlSmartConfigStart_t Cmd;
dflet 3:a8c249046181 625 _BasicResponse_t Rsp;
dflet 3:a8c249046181 626 } _SlSmartConfigStartMsg_u;
dflet 3:a8c249046181 627
dflet 3:a8c249046181 628 const _SlCmdCtrl_t _SlSmartConfigStartCmdCtrl = {
dflet 3:a8c249046181 629 SL_OPCODE_WLAN_SMART_CONFIG_START_COMMAND,
dflet 3:a8c249046181 630 sizeof(_SlSmartConfigStart_t),
dflet 3:a8c249046181 631 sizeof(_BasicResponse_t)
dflet 3:a8c249046181 632 };
dflet 3:a8c249046181 633
dflet 3:a8c249046181 634 #if _SL_INCLUDE_FUNC(sl_WlanSmartConfigStart)
dflet 3:a8c249046181 635 int16_t cc3100_wlan::sl_WlanSmartConfigStart( const uint32_t groupIdBitmask,
dflet 3:a8c249046181 636 const uint8_t cipher,
dflet 3:a8c249046181 637 const uint8_t publicKeyLen,
dflet 3:a8c249046181 638 const uint8_t group1KeyLen,
dflet 3:a8c249046181 639 const uint8_t group2KeyLen,
dflet 3:a8c249046181 640 const uint8_t* pPublicKey,
dflet 3:a8c249046181 641 const uint8_t* pGroup1Key,
dflet 3:a8c249046181 642 const uint8_t* pGroup2Key)
dflet 3:a8c249046181 643 {
dflet 3:a8c249046181 644 _SlSmartConfigStartMsg_u Msg;
dflet 3:a8c249046181 645
dflet 3:a8c249046181 646 Msg.Cmd.Args.groupIdBitmask = (uint8_t)groupIdBitmask;
dflet 3:a8c249046181 647 Msg.Cmd.Args.cipher = (uint8_t)cipher;
dflet 3:a8c249046181 648 Msg.Cmd.Args.publicKeyLen = (uint8_t)publicKeyLen;
dflet 3:a8c249046181 649 Msg.Cmd.Args.group1KeyLen = (uint8_t)group1KeyLen;
dflet 3:a8c249046181 650 Msg.Cmd.Args.group2KeyLen = (uint8_t)group2KeyLen;
dflet 3:a8c249046181 651
dflet 3:a8c249046181 652 /* copy keys (if exist) after command (one after another) */
dflet 3:a8c249046181 653 memcpy(SMART_CONFIG_START_PUBLIC_KEY_STRING(&Msg), pPublicKey, publicKeyLen);
dflet 3:a8c249046181 654 memcpy(SMART_CONFIG_START_GROUP1_KEY_STRING(&Msg), pGroup1Key, group1KeyLen);
dflet 3:a8c249046181 655 memcpy(SMART_CONFIG_START_GROUP2_KEY_STRING(&Msg), pGroup2Key, group2KeyLen);
dflet 3:a8c249046181 656
dflet 3:a8c249046181 657 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlSmartConfigStartCmdCtrl , &Msg, NULL));
dflet 3:a8c249046181 658
dflet 3:a8c249046181 659 return (int16_t)Msg.Rsp.status;
dflet 3:a8c249046181 660
dflet 3:a8c249046181 661
dflet 3:a8c249046181 662 }
dflet 3:a8c249046181 663 #endif
dflet 3:a8c249046181 664
dflet 3:a8c249046181 665 /*******************************************************************************/
dflet 3:a8c249046181 666 /* sl_WlanSetMode */
dflet 3:a8c249046181 667 /*******************************************************************************/
dflet 3:a8c249046181 668 typedef union {
dflet 3:a8c249046181 669 _WlanSetMode_t Cmd;
dflet 3:a8c249046181 670 _BasicResponse_t Rsp;
dflet 3:a8c249046181 671 } _SlwlanSetModeMsg_u;
dflet 3:a8c249046181 672
dflet 3:a8c249046181 673 const _SlCmdCtrl_t _SlWlanSetModeCmdCtrl = {
dflet 3:a8c249046181 674 SL_OPCODE_WLAN_SET_MODE,
dflet 3:a8c249046181 675 sizeof(_WlanSetMode_t),
dflet 3:a8c249046181 676 sizeof(_BasicResponse_t)
dflet 3:a8c249046181 677 };
dflet 3:a8c249046181 678
dflet 3:a8c249046181 679 /* possible values are:
dflet 3:a8c249046181 680 WLAN_SET_STA_MODE = 1
dflet 3:a8c249046181 681 WLAN_SET_AP_MODE = 2
dflet 3:a8c249046181 682 WLAN_SET_P2P_MODE = 3 */
dflet 3:a8c249046181 683
dflet 3:a8c249046181 684 #if _SL_INCLUDE_FUNC(sl_WlanSetMode)
dflet 3:a8c249046181 685 int16_t cc3100_wlan::sl_WlanSetMode(const uint8_t mode)
dflet 3:a8c249046181 686 {
dflet 3:a8c249046181 687 _SlwlanSetModeMsg_u Msg;
dflet 3:a8c249046181 688
dflet 3:a8c249046181 689 Msg.Cmd.mode = mode;
dflet 3:a8c249046181 690
dflet 3:a8c249046181 691 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlWlanSetModeCmdCtrl , &Msg, NULL));
dflet 3:a8c249046181 692
dflet 3:a8c249046181 693 return (int16_t)Msg.Rsp.status;
dflet 3:a8c249046181 694
dflet 3:a8c249046181 695 }
dflet 3:a8c249046181 696 #endif
dflet 3:a8c249046181 697
dflet 3:a8c249046181 698 /*******************************************************************************/
dflet 3:a8c249046181 699 /* sl_WlanSet */
dflet 3:a8c249046181 700 /* ******************************************************************************/
dflet 3:a8c249046181 701 typedef union {
dflet 3:a8c249046181 702 _WlanCfgSetGet_t Cmd;
dflet 3:a8c249046181 703 _BasicResponse_t Rsp;
dflet 3:a8c249046181 704 } _SlWlanCfgSetMsg_u;
dflet 3:a8c249046181 705
dflet 3:a8c249046181 706 #if _SL_INCLUDE_FUNC(sl_WlanSet)
dflet 3:a8c249046181 707 const _SlCmdCtrl_t _SlWlanCfgSetCmdCtrl = {
dflet 3:a8c249046181 708 SL_OPCODE_WLAN_CFG_SET,
dflet 3:a8c249046181 709 sizeof(_WlanCfgSetGet_t),
dflet 3:a8c249046181 710 sizeof(_BasicResponse_t)
dflet 3:a8c249046181 711 };
dflet 3:a8c249046181 712
dflet 3:a8c249046181 713 int16_t cc3100_wlan::sl_WlanSet(const uint16_t ConfigId, const uint16_t ConfigOpt, const uint16_t ConfigLen, const uint8_t *pValues)
dflet 3:a8c249046181 714 {
dflet 3:a8c249046181 715 _SlWlanCfgSetMsg_u Msg;
dflet 3:a8c249046181 716 _SlCmdExt_t CmdExt;
dflet 3:a8c249046181 717
dflet 3:a8c249046181 718 _driver._SlDrvResetCmdExt(&CmdExt);
dflet 3:a8c249046181 719 CmdExt.TxPayloadLen = (ConfigLen+3) & (~3);
dflet 3:a8c249046181 720 CmdExt.pTxPayload = (uint8_t *)pValues;
dflet 3:a8c249046181 721
dflet 3:a8c249046181 722
dflet 3:a8c249046181 723 Msg.Cmd.ConfigId = ConfigId;
dflet 3:a8c249046181 724 Msg.Cmd.ConfigLen = ConfigLen;
dflet 3:a8c249046181 725 Msg.Cmd.ConfigOpt = ConfigOpt;
dflet 3:a8c249046181 726
dflet 3:a8c249046181 727 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlWlanCfgSetCmdCtrl, &Msg, &CmdExt));
dflet 3:a8c249046181 728
dflet 3:a8c249046181 729 return (int16_t)Msg.Rsp.status;
dflet 3:a8c249046181 730 }
dflet 3:a8c249046181 731 #endif
dflet 3:a8c249046181 732
dflet 3:a8c249046181 733
dflet 3:a8c249046181 734 /******************************************************************************/
dflet 3:a8c249046181 735 /* sl_WlanGet */
dflet 3:a8c249046181 736 /******************************************************************************/
dflet 3:a8c249046181 737 typedef union {
dflet 3:a8c249046181 738 _WlanCfgSetGet_t Cmd;
dflet 3:a8c249046181 739 _WlanCfgSetGet_t Rsp;
dflet 3:a8c249046181 740 } _SlWlanCfgMsgGet_u;
dflet 3:a8c249046181 741
dflet 3:a8c249046181 742 #if _SL_INCLUDE_FUNC(sl_WlanGet)
dflet 3:a8c249046181 743 const _SlCmdCtrl_t _SlWlanCfgGetCmdCtrl = {
dflet 3:a8c249046181 744 SL_OPCODE_WLAN_CFG_GET,
dflet 3:a8c249046181 745 sizeof(_WlanCfgSetGet_t),
dflet 3:a8c249046181 746 sizeof(_WlanCfgSetGet_t)
dflet 3:a8c249046181 747 };
dflet 3:a8c249046181 748
dflet 3:a8c249046181 749 int16_t cc3100_wlan::sl_WlanGet(const uint16_t ConfigId, uint16_t *pConfigOpt,uint16_t *pConfigLen, uint8_t *pValues)
dflet 3:a8c249046181 750 {
dflet 3:a8c249046181 751 _SlWlanCfgMsgGet_u Msg;
dflet 3:a8c249046181 752 _SlCmdExt_t CmdExt;
dflet 3:a8c249046181 753
dflet 3:a8c249046181 754 if (*pConfigLen == 0) {
dflet 3:a8c249046181 755 return SL_EZEROLEN;
dflet 3:a8c249046181 756 }
dflet 3:a8c249046181 757
dflet 3:a8c249046181 758 _driver._SlDrvResetCmdExt(&CmdExt);
dflet 3:a8c249046181 759 CmdExt.RxPayloadLen = *pConfigLen;
dflet 3:a8c249046181 760 CmdExt.pRxPayload = (uint8_t *)pValues;
dflet 3:a8c249046181 761
dflet 3:a8c249046181 762 Msg.Cmd.ConfigId = ConfigId;
dflet 3:a8c249046181 763 if( pConfigOpt ) {
dflet 3:a8c249046181 764 Msg.Cmd.ConfigOpt = (uint16_t)*pConfigOpt;
dflet 3:a8c249046181 765 }
dflet 3:a8c249046181 766 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlWlanCfgGetCmdCtrl, &Msg, &CmdExt));
dflet 3:a8c249046181 767
dflet 3:a8c249046181 768 if( pConfigOpt ) {
dflet 3:a8c249046181 769 *pConfigOpt = (uint8_t)Msg.Rsp.ConfigOpt;
dflet 3:a8c249046181 770 }
dflet 3:a8c249046181 771 if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen) {
dflet 3:a8c249046181 772 *pConfigLen = (uint8_t)CmdExt.RxPayloadLen;
dflet 3:a8c249046181 773 return SL_ESMALLBUF;
dflet 3:a8c249046181 774 } else {
dflet 3:a8c249046181 775 *pConfigLen = (uint8_t)CmdExt.ActualRxPayloadLen;
dflet 3:a8c249046181 776 }
dflet 3:a8c249046181 777
dflet 3:a8c249046181 778
dflet 3:a8c249046181 779 return (int16_t)Msg.Rsp.Status;
dflet 3:a8c249046181 780 }
dflet 3:a8c249046181 781 #endif
dflet 3:a8c249046181 782
dflet 3:a8c249046181 783 cc3100_wlan_rx_filters::cc3100_wlan_rx_filters(cc3100_driver &driver)
dflet 3:a8c249046181 784 : _driver(driver)
dflet 3:a8c249046181 785 {
dflet 3:a8c249046181 786
dflet 3:a8c249046181 787 }
dflet 3:a8c249046181 788
dflet 3:a8c249046181 789 cc3100_wlan_rx_filters::~cc3100_wlan_rx_filters()
dflet 3:a8c249046181 790 {
dflet 3:a8c249046181 791
dflet 3:a8c249046181 792 }
dflet 3:a8c249046181 793
dflet 3:a8c249046181 794 /******************************************************************************/
dflet 3:a8c249046181 795 /* RX filters message command response structures */
dflet 3:a8c249046181 796 /******************************************************************************/
dflet 3:a8c249046181 797
dflet 3:a8c249046181 798 /* Set command */
dflet 3:a8c249046181 799 typedef union {
dflet 3:a8c249046181 800 _WlanRxFilterAddCommand_t Cmd;
dflet 3:a8c249046181 801 _WlanRxFilterAddCommandReponse_t Rsp;
dflet 3:a8c249046181 802 } _SlrxFilterAddMsg_u;
dflet 3:a8c249046181 803
dflet 3:a8c249046181 804 /* Set command */
dflet 3:a8c249046181 805 typedef union _SlRxFilterSetMsg_u {
dflet 3:a8c249046181 806 _WlanRxFilterSetCommand_t Cmd;
dflet 3:a8c249046181 807 _WlanRxFilterSetCommandReponse_t Rsp;
dflet 3:a8c249046181 808 } _SlRxFilterSetMsg_u;
dflet 3:a8c249046181 809
dflet 3:a8c249046181 810 /* Get command */
dflet 3:a8c249046181 811 typedef union _SlRxFilterGetMsg_u {
dflet 3:a8c249046181 812 _WlanRxFilterGetCommand_t Cmd;
dflet 3:a8c249046181 813 _WlanRxFilterGetCommandReponse_t Rsp;
dflet 3:a8c249046181 814 } _SlRxFilterGetMsg_u;
dflet 3:a8c249046181 815
dflet 3:a8c249046181 816
dflet 3:a8c249046181 817 #if _SL_INCLUDE_FUNC(sl_WlanRxFilterAdd)
dflet 3:a8c249046181 818
dflet 3:a8c249046181 819 const _SlCmdCtrl_t _SlRxFilterAddtCmdCtrl =
dflet 3:a8c249046181 820 {
dflet 3:a8c249046181 821 SL_OPCODE_WLAN_WLANRXFILTERADDCOMMAND,
dflet 3:a8c249046181 822 sizeof(_WlanRxFilterAddCommand_t),
dflet 3:a8c249046181 823 sizeof(_WlanRxFilterAddCommandReponse_t)
dflet 3:a8c249046181 824 };
dflet 3:a8c249046181 825
dflet 3:a8c249046181 826
dflet 3:a8c249046181 827 /*******************************************************************************/
dflet 3:a8c249046181 828 /* RX filters */
dflet 3:a8c249046181 829 /*******************************************************************************/
dflet 3:a8c249046181 830 SlrxFilterID_t cc3100_wlan_rx_filters::sl_WlanRxFilterAdd( SlrxFilterRuleType_t RuleType,
dflet 3:a8c249046181 831 SlrxFilterFlags_t FilterFlags,
dflet 3:a8c249046181 832 const SlrxFilterRule_t* const Rule,
dflet 3:a8c249046181 833 const SlrxFilterTrigger_t* const Trigger,
dflet 3:a8c249046181 834 const SlrxFilterAction_t* const Action,
dflet 3:a8c249046181 835 SlrxFilterID_t* pFilterId)
dflet 3:a8c249046181 836 {
dflet 3:a8c249046181 837
dflet 3:a8c249046181 838
dflet 3:a8c249046181 839 _SlrxFilterAddMsg_u Msg;
dflet 3:a8c249046181 840 Msg.Cmd.RuleType = RuleType;
dflet 3:a8c249046181 841 /* filterId is zero */
dflet 3:a8c249046181 842 Msg.Cmd.FilterId = 0;
dflet 3:a8c249046181 843 Msg.Cmd.FilterFlags = FilterFlags;
dflet 3:a8c249046181 844 memcpy( &(Msg.Cmd.Rule), Rule, sizeof(SlrxFilterRule_t) );
dflet 3:a8c249046181 845 memcpy( &(Msg.Cmd.Trigger), Trigger, sizeof(SlrxFilterTrigger_t) );
dflet 3:a8c249046181 846 memcpy( &(Msg.Cmd.Action), Action, sizeof(SlrxFilterAction_t) );
dflet 3:a8c249046181 847 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlRxFilterAddtCmdCtrl, &Msg, NULL) );
dflet 3:a8c249046181 848 *pFilterId = Msg.Rsp.FilterId;
dflet 3:a8c249046181 849 return (int16_t)Msg.Rsp.Status;
dflet 3:a8c249046181 850
dflet 3:a8c249046181 851 }
dflet 3:a8c249046181 852 #endif
dflet 3:a8c249046181 853
dflet 3:a8c249046181 854
dflet 3:a8c249046181 855
dflet 3:a8c249046181 856 /*******************************************************************************/
dflet 3:a8c249046181 857 /* RX filters */
dflet 3:a8c249046181 858 /*******************************************************************************/
dflet 3:a8c249046181 859 #if _SL_INCLUDE_FUNC(sl_WlanRxFilterSet)
dflet 3:a8c249046181 860 const _SlCmdCtrl_t _SlRxFilterSetCmdCtrl =
dflet 3:a8c249046181 861 {
dflet 3:a8c249046181 862 SL_OPCODE_WLAN_WLANRXFILTERSETCOMMAND,
dflet 3:a8c249046181 863 sizeof(_WlanRxFilterSetCommand_t),
dflet 3:a8c249046181 864 sizeof(_WlanRxFilterSetCommandReponse_t)
dflet 3:a8c249046181 865 };
dflet 3:a8c249046181 866
dflet 3:a8c249046181 867 int16_t cc3100_wlan_rx_filters::sl_WlanRxFilterSet(const SLrxFilterOperation_t RxFilterOperation,
dflet 3:a8c249046181 868 const uint8_t* const pInputBuffer,
dflet 3:a8c249046181 869 uint16_t InputbufferLength)
dflet 3:a8c249046181 870 {
dflet 3:a8c249046181 871 _SlRxFilterSetMsg_u Msg;
dflet 3:a8c249046181 872 _SlCmdExt_t CmdExt;
dflet 3:a8c249046181 873
dflet 3:a8c249046181 874 _driver._SlDrvResetCmdExt(&CmdExt);
dflet 3:a8c249046181 875 CmdExt.TxPayloadLen = InputbufferLength;
dflet 3:a8c249046181 876 CmdExt.pTxPayload = (uint8_t *)pInputBuffer;
dflet 3:a8c249046181 877
dflet 3:a8c249046181 878 Msg.Cmd.RxFilterOperation = RxFilterOperation;
dflet 3:a8c249046181 879 Msg.Cmd.InputBufferLength = InputbufferLength;
dflet 3:a8c249046181 880
dflet 3:a8c249046181 881
dflet 3:a8c249046181 882 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlRxFilterSetCmdCtrl, &Msg, &CmdExt) );
dflet 3:a8c249046181 883
dflet 3:a8c249046181 884
dflet 3:a8c249046181 885 return (int16_t)Msg.Rsp.Status;
dflet 3:a8c249046181 886 }
dflet 3:a8c249046181 887 #endif
dflet 3:a8c249046181 888
dflet 3:a8c249046181 889 /******************************************************************************/
dflet 3:a8c249046181 890 /* RX filters */
dflet 3:a8c249046181 891 /******************************************************************************/
dflet 3:a8c249046181 892 #if _SL_INCLUDE_FUNC(sl_WlanRxFilterGet)
dflet 3:a8c249046181 893 const _SlCmdCtrl_t _SlRxFilterGetCmdCtrl =
dflet 3:a8c249046181 894 {
dflet 3:a8c249046181 895 SL_OPCODE_WLAN_WLANRXFILTERGETCOMMAND,
dflet 3:a8c249046181 896 sizeof(_WlanRxFilterGetCommand_t),
dflet 3:a8c249046181 897 sizeof(_WlanRxFilterGetCommandReponse_t)
dflet 3:a8c249046181 898 };
dflet 3:a8c249046181 899
dflet 3:a8c249046181 900 int16_t cc3100_wlan_rx_filters::sl_WlanRxFilterGet(const SLrxFilterOperation_t RxFilterOperation,
dflet 3:a8c249046181 901 uint8_t* pOutputBuffer,
dflet 3:a8c249046181 902 uint16_t OutputbufferLength)
dflet 3:a8c249046181 903 {
dflet 3:a8c249046181 904 _SlRxFilterGetMsg_u Msg;
dflet 3:a8c249046181 905 _SlCmdExt_t CmdExt;
dflet 3:a8c249046181 906
dflet 3:a8c249046181 907 if (OutputbufferLength == 0) {
dflet 3:a8c249046181 908 return SL_EZEROLEN;
dflet 3:a8c249046181 909 }
dflet 3:a8c249046181 910
dflet 3:a8c249046181 911 _driver._SlDrvResetCmdExt(&CmdExt);
dflet 3:a8c249046181 912 CmdExt.RxPayloadLen = OutputbufferLength;
dflet 3:a8c249046181 913 CmdExt.pRxPayload = (uint8_t *)pOutputBuffer;
dflet 3:a8c249046181 914
dflet 3:a8c249046181 915 Msg.Cmd.RxFilterOperation = RxFilterOperation;
dflet 3:a8c249046181 916 Msg.Cmd.OutputBufferLength = OutputbufferLength;
dflet 3:a8c249046181 917
dflet 3:a8c249046181 918
dflet 3:a8c249046181 919 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlRxFilterGetCmdCtrl, &Msg, &CmdExt) );
dflet 3:a8c249046181 920
dflet 3:a8c249046181 921 if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen) {
dflet 3:a8c249046181 922 return SL_ESMALLBUF;
dflet 3:a8c249046181 923 }
dflet 3:a8c249046181 924
dflet 3:a8c249046181 925 return (int16_t)Msg.Rsp.Status;
dflet 3:a8c249046181 926 }
dflet 3:a8c249046181 927 #endif
dflet 3:a8c249046181 928
dflet 3:a8c249046181 929 }//namespace mbed_cc3100
dflet 3:a8c249046181 930
dflet 3:a8c249046181 931