Updated to use external spawn.

Fork of simplelink_V2 by David Fletcher

Committer:
dflet
Date:
Sat Jun 06 13:48:29 2015 +0000
Revision:
1:9b68e650b3f6
Parent:
0:1a07906111ec
Oppps

Who changed what in which revision?

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