cc3100_Socket_Wifi_Server with Ethernet Interface not working
Dependencies: EthernetInterface mbed-rtos mbed
Fork of cc3100_Test_Demo by
simplelink/cc3100_netcfg.cpp@6:778b081f6a13, 2015-03-19 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
dflet | 6:778b081f6a13 | 1 | /* |
dflet | 6:778b081f6a13 | 2 | * netcfg.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_netcfg.h" |
dflet | 6:778b081f6a13 | 47 | |
dflet | 6:778b081f6a13 | 48 | namespace mbed_cc3100 { |
dflet | 6:778b081f6a13 | 49 | |
dflet | 6:778b081f6a13 | 50 | cc3100_netcfg::cc3100_netcfg(cc3100_driver &driver) |
dflet | 6:778b081f6a13 | 51 | : _driver(driver) |
dflet | 6:778b081f6a13 | 52 | { |
dflet | 6:778b081f6a13 | 53 | |
dflet | 6:778b081f6a13 | 54 | } |
dflet | 6:778b081f6a13 | 55 | |
dflet | 6:778b081f6a13 | 56 | cc3100_netcfg::~cc3100_netcfg() |
dflet | 6:778b081f6a13 | 57 | { |
dflet | 6:778b081f6a13 | 58 | |
dflet | 6:778b081f6a13 | 59 | } |
dflet | 6:778b081f6a13 | 60 | |
dflet | 6:778b081f6a13 | 61 | /*****************************************************************************/ |
dflet | 6:778b081f6a13 | 62 | /* sl_NetCfgSet */ |
dflet | 6:778b081f6a13 | 63 | /*****************************************************************************/ |
dflet | 6:778b081f6a13 | 64 | typedef union { |
dflet | 6:778b081f6a13 | 65 | _NetCfgSetGet_t Cmd; |
dflet | 6:778b081f6a13 | 66 | _BasicResponse_t Rsp; |
dflet | 6:778b081f6a13 | 67 | } _SlNetCfgMsgSet_u; |
dflet | 6:778b081f6a13 | 68 | |
dflet | 6:778b081f6a13 | 69 | #if _SL_INCLUDE_FUNC(sl_NetCfgSet) |
dflet | 6:778b081f6a13 | 70 | const _SlCmdCtrl_t _SlNetCfgSetCmdCtrl = { |
dflet | 6:778b081f6a13 | 71 | SL_OPCODE_DEVICE_NETCFG_SET_COMMAND, |
dflet | 6:778b081f6a13 | 72 | sizeof(_NetCfgSetGet_t), |
dflet | 6:778b081f6a13 | 73 | sizeof(_BasicResponse_t) |
dflet | 6:778b081f6a13 | 74 | }; |
dflet | 6:778b081f6a13 | 75 | |
dflet | 6:778b081f6a13 | 76 | int32_t cc3100_netcfg::sl_NetCfgSet(const uint8_t ConfigId, const uint8_t ConfigOpt, const uint8_t ConfigLen, const uint8_t *pValues) |
dflet | 6:778b081f6a13 | 77 | { |
dflet | 6:778b081f6a13 | 78 | _SlNetCfgMsgSet_u Msg; |
dflet | 6:778b081f6a13 | 79 | _SlCmdExt_t CmdExt; |
dflet | 6:778b081f6a13 | 80 | |
dflet | 6:778b081f6a13 | 81 | _driver._SlDrvResetCmdExt(&CmdExt); |
dflet | 6:778b081f6a13 | 82 | CmdExt.TxPayloadLen = (ConfigLen+3) & (~3); |
dflet | 6:778b081f6a13 | 83 | CmdExt.pTxPayload = (uint8_t *)pValues; |
dflet | 6:778b081f6a13 | 84 | |
dflet | 6:778b081f6a13 | 85 | Msg.Cmd.ConfigId = ConfigId; |
dflet | 6:778b081f6a13 | 86 | Msg.Cmd.ConfigLen = ConfigLen; |
dflet | 6:778b081f6a13 | 87 | Msg.Cmd.ConfigOpt = ConfigOpt; |
dflet | 6:778b081f6a13 | 88 | |
dflet | 6:778b081f6a13 | 89 | VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetCfgSetCmdCtrl, &Msg, &CmdExt)); |
dflet | 6:778b081f6a13 | 90 | |
dflet | 6:778b081f6a13 | 91 | return (int16_t)Msg.Rsp.status; |
dflet | 6:778b081f6a13 | 92 | } |
dflet | 6:778b081f6a13 | 93 | #endif |
dflet | 6:778b081f6a13 | 94 | |
dflet | 6:778b081f6a13 | 95 | uint32_t cc3100_netcfg::SL_IPV4_VAL(uint8_t add_3,uint8_t add_2,uint8_t add_1,uint8_t add_0){ |
dflet | 6:778b081f6a13 | 96 | |
dflet | 6:778b081f6a13 | 97 | return((((uint32_t)add_3 << 24) & 0xFF000000) | (((uint32_t)add_2 << 16) & 0xFF0000) | (((uint32_t)add_1 << 8) & 0xFF00) | ((uint32_t)add_0 & 0xFF) ); |
dflet | 6:778b081f6a13 | 98 | } |
dflet | 6:778b081f6a13 | 99 | |
dflet | 6:778b081f6a13 | 100 | uint8_t cc3100_netcfg::SL_IPV4_BYTE(uint32_t val,uint8_t index){ |
dflet | 6:778b081f6a13 | 101 | |
dflet | 6:778b081f6a13 | 102 | return( (val >>= (index*8)) & 0xFF ); |
dflet | 6:778b081f6a13 | 103 | } |
dflet | 6:778b081f6a13 | 104 | |
dflet | 6:778b081f6a13 | 105 | /*****************************************************************************/ |
dflet | 6:778b081f6a13 | 106 | /* sl_NetCfgGet */ |
dflet | 6:778b081f6a13 | 107 | /*****************************************************************************/ |
dflet | 6:778b081f6a13 | 108 | typedef union { |
dflet | 6:778b081f6a13 | 109 | _NetCfgSetGet_t Cmd; |
dflet | 6:778b081f6a13 | 110 | _NetCfgSetGet_t Rsp; |
dflet | 6:778b081f6a13 | 111 | } _SlNetCfgMsgGet_u; |
dflet | 6:778b081f6a13 | 112 | |
dflet | 6:778b081f6a13 | 113 | #if _SL_INCLUDE_FUNC(sl_NetCfgGet) |
dflet | 6:778b081f6a13 | 114 | const _SlCmdCtrl_t _SlNetCfgGetCmdCtrl = { |
dflet | 6:778b081f6a13 | 115 | SL_OPCODE_DEVICE_NETCFG_GET_COMMAND, |
dflet | 6:778b081f6a13 | 116 | sizeof(_NetCfgSetGet_t), |
dflet | 6:778b081f6a13 | 117 | sizeof(_NetCfgSetGet_t) |
dflet | 6:778b081f6a13 | 118 | }; |
dflet | 6:778b081f6a13 | 119 | |
dflet | 6:778b081f6a13 | 120 | int32_t cc3100_netcfg::sl_NetCfgGet(const uint8_t ConfigId, uint8_t *pConfigOpt,uint8_t *pConfigLen, uint8_t *pValues) |
dflet | 6:778b081f6a13 | 121 | { |
dflet | 6:778b081f6a13 | 122 | _SlNetCfgMsgGet_u Msg; |
dflet | 6:778b081f6a13 | 123 | _SlCmdExt_t CmdExt; |
dflet | 6:778b081f6a13 | 124 | |
dflet | 6:778b081f6a13 | 125 | if (*pConfigLen == 0) { |
dflet | 6:778b081f6a13 | 126 | return SL_EZEROLEN; |
dflet | 6:778b081f6a13 | 127 | } |
dflet | 6:778b081f6a13 | 128 | |
dflet | 6:778b081f6a13 | 129 | _driver._SlDrvResetCmdExt(&CmdExt); |
dflet | 6:778b081f6a13 | 130 | CmdExt.RxPayloadLen = *pConfigLen; |
dflet | 6:778b081f6a13 | 131 | CmdExt.pRxPayload = (uint8_t *)pValues; |
dflet | 6:778b081f6a13 | 132 | |
dflet | 6:778b081f6a13 | 133 | Msg.Cmd.ConfigLen = *pConfigLen; |
dflet | 6:778b081f6a13 | 134 | Msg.Cmd.ConfigId = ConfigId; |
dflet | 6:778b081f6a13 | 135 | |
dflet | 6:778b081f6a13 | 136 | if( pConfigOpt ) { |
dflet | 6:778b081f6a13 | 137 | Msg.Cmd.ConfigOpt = (uint16_t)*pConfigOpt; |
dflet | 6:778b081f6a13 | 138 | } |
dflet | 6:778b081f6a13 | 139 | VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetCfgGetCmdCtrl, &Msg, &CmdExt)); |
dflet | 6:778b081f6a13 | 140 | |
dflet | 6:778b081f6a13 | 141 | if( pConfigOpt ) { |
dflet | 6:778b081f6a13 | 142 | *pConfigOpt = (uint8_t)Msg.Rsp.ConfigOpt; |
dflet | 6:778b081f6a13 | 143 | } |
dflet | 6:778b081f6a13 | 144 | if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen) { |
dflet | 6:778b081f6a13 | 145 | *pConfigLen = (uint8_t)CmdExt.RxPayloadLen; |
dflet | 6:778b081f6a13 | 146 | if( SL_MAC_ADDRESS_GET == ConfigId ) |
dflet | 6:778b081f6a13 | 147 | { |
dflet | 6:778b081f6a13 | 148 | return SL_RET_CODE_OK; /* sp fix */ |
dflet | 6:778b081f6a13 | 149 | } |
dflet | 6:778b081f6a13 | 150 | else |
dflet | 6:778b081f6a13 | 151 | { |
dflet | 6:778b081f6a13 | 152 | return SL_ESMALLBUF; |
dflet | 6:778b081f6a13 | 153 | } |
dflet | 6:778b081f6a13 | 154 | } |
dflet | 6:778b081f6a13 | 155 | else |
dflet | 6:778b081f6a13 | 156 | { |
dflet | 6:778b081f6a13 | 157 | *pConfigLen = (uint8_t)CmdExt.ActualRxPayloadLen; |
dflet | 6:778b081f6a13 | 158 | } |
dflet | 6:778b081f6a13 | 159 | |
dflet | 6:778b081f6a13 | 160 | return (int16_t)Msg.Rsp.Status; |
dflet | 6:778b081f6a13 | 161 | } |
dflet | 6:778b081f6a13 | 162 | #endif |
dflet | 6:778b081f6a13 | 163 | |
dflet | 6:778b081f6a13 | 164 | }//namespace mbed_cc3100 |