Simple LED control project using CC3100 as Access Point and socket

Dependencies:   mbed

Fork of cc3100_Test_Demo by David Fletcher

Committer:
dflet
Date:
Thu Mar 19 15:39:08 2015 +0000
Revision:
6:778b081f6a13
Updated to CC3100SDK1.1.0

Who changed what in which revision?

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