Murata Type YD Wi-Fi driver
Dependents: easy-connect-type-yd
SNICInterface/SNIC_WifiInterface.cpp@0:35a2186cf186, 2017-07-12 (annotated)
- Committer:
- MACRUM
- Date:
- Wed Jul 12 10:49:10 2017 +0000
- Revision:
- 0:35a2186cf186
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MACRUM | 0:35a2186cf186 | 1 | /* Copyright (C) 2014 Murata Manufacturing Co.,Ltd., MIT License |
MACRUM | 0:35a2186cf186 | 2 | * muRata, SWITCH SCIENCE Wi-FI module TypeYD-SNIC UART. |
MACRUM | 0:35a2186cf186 | 3 | * |
MACRUM | 0:35a2186cf186 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
MACRUM | 0:35a2186cf186 | 5 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
MACRUM | 0:35a2186cf186 | 6 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
MACRUM | 0:35a2186cf186 | 7 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
MACRUM | 0:35a2186cf186 | 8 | * furnished to do so, subject to the following conditions: |
MACRUM | 0:35a2186cf186 | 9 | * |
MACRUM | 0:35a2186cf186 | 10 | * The above copyright notice and this permission notice shall be included in all copies or |
MACRUM | 0:35a2186cf186 | 11 | * substantial portions of the Software. |
MACRUM | 0:35a2186cf186 | 12 | * |
MACRUM | 0:35a2186cf186 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
MACRUM | 0:35a2186cf186 | 14 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
MACRUM | 0:35a2186cf186 | 15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
MACRUM | 0:35a2186cf186 | 16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
MACRUM | 0:35a2186cf186 | 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
MACRUM | 0:35a2186cf186 | 18 | */ |
MACRUM | 0:35a2186cf186 | 19 | #include "SNICInterface/SNIC_WifiInterface.h" |
MACRUM | 0:35a2186cf186 | 20 | #include "SNICInterface/SNIC/SNIC_UartMsgUtil.h" |
MACRUM | 0:35a2186cf186 | 21 | |
MACRUM | 0:35a2186cf186 | 22 | #define UART_CONNECT_BUF_SIZE 512 |
MACRUM | 0:35a2186cf186 | 23 | unsigned char gCONNECT_BUF[UART_CONNECT_BUF_SIZE]; |
MACRUM | 0:35a2186cf186 | 24 | static char ip_addr[17] = "\0"; |
MACRUM | 0:35a2186cf186 | 25 | static char gateway_addr[17] = "\0"; |
MACRUM | 0:35a2186cf186 | 26 | static char subnet_addr[17] = "\0"; |
MACRUM | 0:35a2186cf186 | 27 | |
MACRUM | 0:35a2186cf186 | 28 | C_SNIC_WifiInterface::C_SNIC_WifiInterface( PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm, int baud) |
MACRUM | 0:35a2186cf186 | 29 | { |
MACRUM | 0:35a2186cf186 | 30 | mUART_tx = tx; |
MACRUM | 0:35a2186cf186 | 31 | mUART_rx = rx; |
MACRUM | 0:35a2186cf186 | 32 | mUART_cts = cts; |
MACRUM | 0:35a2186cf186 | 33 | mUART_rts = rts;; |
MACRUM | 0:35a2186cf186 | 34 | mUART_baud = baud; |
MACRUM | 0:35a2186cf186 | 35 | mModuleReset = reset; |
MACRUM | 0:35a2186cf186 | 36 | } |
MACRUM | 0:35a2186cf186 | 37 | |
MACRUM | 0:35a2186cf186 | 38 | void C_SNIC_WifiInterface::create( PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm, int baud) |
MACRUM | 0:35a2186cf186 | 39 | { |
MACRUM | 0:35a2186cf186 | 40 | mUART_tx = tx; |
MACRUM | 0:35a2186cf186 | 41 | mUART_rx = rx; |
MACRUM | 0:35a2186cf186 | 42 | mUART_cts = cts; |
MACRUM | 0:35a2186cf186 | 43 | mUART_rts = rts;; |
MACRUM | 0:35a2186cf186 | 44 | mUART_baud = baud; |
MACRUM | 0:35a2186cf186 | 45 | mModuleReset = reset; |
MACRUM | 0:35a2186cf186 | 46 | } |
MACRUM | 0:35a2186cf186 | 47 | |
MACRUM | 0:35a2186cf186 | 48 | C_SNIC_WifiInterface::~C_SNIC_WifiInterface() |
MACRUM | 0:35a2186cf186 | 49 | { |
MACRUM | 0:35a2186cf186 | 50 | } |
MACRUM | 0:35a2186cf186 | 51 | |
MACRUM | 0:35a2186cf186 | 52 | int C_SNIC_WifiInterface::init() |
MACRUM | 0:35a2186cf186 | 53 | { |
MACRUM | 0:35a2186cf186 | 54 | C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance(); |
MACRUM | 0:35a2186cf186 | 55 | C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand(); |
MACRUM | 0:35a2186cf186 | 56 | |
MACRUM | 0:35a2186cf186 | 57 | /* Initialize UART */ |
MACRUM | 0:35a2186cf186 | 58 | snic_core_p->initUart( mUART_tx, mUART_rx, mUART_baud ); |
MACRUM | 0:35a2186cf186 | 59 | |
MACRUM | 0:35a2186cf186 | 60 | /* Module reset */ |
MACRUM | 0:35a2186cf186 | 61 | snic_core_p->resetModule( mModuleReset ); |
MACRUM | 0:35a2186cf186 | 62 | |
MACRUM | 0:35a2186cf186 | 63 | wait(1); |
MACRUM | 0:35a2186cf186 | 64 | /* Initialize SNIC API */ |
MACRUM | 0:35a2186cf186 | 65 | // Get buffer for response payload from MemoryPool |
MACRUM | 0:35a2186cf186 | 66 | tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf(); |
MACRUM | 0:35a2186cf186 | 67 | if( payload_buf_p == NULL ) |
MACRUM | 0:35a2186cf186 | 68 | { |
MACRUM | 0:35a2186cf186 | 69 | DEBUG_PRINT("snic_init payload_buf_p NULL\r\n"); |
MACRUM | 0:35a2186cf186 | 70 | return -1; |
MACRUM | 0:35a2186cf186 | 71 | } |
MACRUM | 0:35a2186cf186 | 72 | |
MACRUM | 0:35a2186cf186 | 73 | C_SNIC_Core::tagSNIC_INIT_REQ_T req; |
MACRUM | 0:35a2186cf186 | 74 | // Make request |
MACRUM | 0:35a2186cf186 | 75 | req.cmd_sid = UART_CMD_SID_SNIC_INIT_REQ; |
MACRUM | 0:35a2186cf186 | 76 | req.seq = mUartRequestSeq++; |
MACRUM | 0:35a2186cf186 | 77 | req.buf_size[0] = 0x08; |
MACRUM | 0:35a2186cf186 | 78 | req.buf_size[1] = 0x00; |
MACRUM | 0:35a2186cf186 | 79 | |
MACRUM | 0:35a2186cf186 | 80 | unsigned char *command_array_p = snic_core_p->getCommandBuf(); |
MACRUM | 0:35a2186cf186 | 81 | unsigned int command_len; |
MACRUM | 0:35a2186cf186 | 82 | // Preparation of command |
MACRUM | 0:35a2186cf186 | 83 | command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req |
MACRUM | 0:35a2186cf186 | 84 | , sizeof(C_SNIC_Core::tagSNIC_INIT_REQ_T), payload_buf_p->buf, command_array_p ); |
MACRUM | 0:35a2186cf186 | 85 | |
MACRUM | 0:35a2186cf186 | 86 | // Send uart command request |
MACRUM | 0:35a2186cf186 | 87 | snic_core_p->sendUart( command_len, command_array_p ); |
MACRUM | 0:35a2186cf186 | 88 | |
MACRUM | 0:35a2186cf186 | 89 | int ret; |
MACRUM | 0:35a2186cf186 | 90 | // Wait UART response |
MACRUM | 0:35a2186cf186 | 91 | ret = uartCmdMgr_p->wait(); |
MACRUM | 0:35a2186cf186 | 92 | if( ret != 0 ) |
MACRUM | 0:35a2186cf186 | 93 | { |
MACRUM | 0:35a2186cf186 | 94 | DEBUG_PRINT( "snic_init failed\r\n" ); |
MACRUM | 0:35a2186cf186 | 95 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 96 | return -1; |
MACRUM | 0:35a2186cf186 | 97 | } |
MACRUM | 0:35a2186cf186 | 98 | |
MACRUM | 0:35a2186cf186 | 99 | if( uartCmdMgr_p->getCommandStatus() != 0 ) |
MACRUM | 0:35a2186cf186 | 100 | { |
MACRUM | 0:35a2186cf186 | 101 | DEBUG_PRINT("snic_init status:%02x\r\n", uartCmdMgr_p->getCommandStatus()); |
MACRUM | 0:35a2186cf186 | 102 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 103 | return -1; |
MACRUM | 0:35a2186cf186 | 104 | } |
MACRUM | 0:35a2186cf186 | 105 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 106 | |
MACRUM | 0:35a2186cf186 | 107 | return ret; |
MACRUM | 0:35a2186cf186 | 108 | } |
MACRUM | 0:35a2186cf186 | 109 | |
MACRUM | 0:35a2186cf186 | 110 | int C_SNIC_WifiInterface::getFWVersion( unsigned char *version_p, int *length_p ) |
MACRUM | 0:35a2186cf186 | 111 | { |
MACRUM | 0:35a2186cf186 | 112 | C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance(); |
MACRUM | 0:35a2186cf186 | 113 | C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand(); |
MACRUM | 0:35a2186cf186 | 114 | |
MACRUM | 0:35a2186cf186 | 115 | if ((version_p == NULL) || (length_p == NULL)) { |
MACRUM | 0:35a2186cf186 | 116 | return -1; |
MACRUM | 0:35a2186cf186 | 117 | } |
MACRUM | 0:35a2186cf186 | 118 | |
MACRUM | 0:35a2186cf186 | 119 | // Get buffer for response payload from MemoryPool |
MACRUM | 0:35a2186cf186 | 120 | tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf(); |
MACRUM | 0:35a2186cf186 | 121 | if( payload_buf_p == NULL ) |
MACRUM | 0:35a2186cf186 | 122 | { |
MACRUM | 0:35a2186cf186 | 123 | DEBUG_PRINT("getFWVersion payload_buf_p NULL\r\n"); |
MACRUM | 0:35a2186cf186 | 124 | return -1; |
MACRUM | 0:35a2186cf186 | 125 | } |
MACRUM | 0:35a2186cf186 | 126 | |
MACRUM | 0:35a2186cf186 | 127 | C_SNIC_Core::tagGEN_FW_VER_GET_REQ_T req; |
MACRUM | 0:35a2186cf186 | 128 | // Make request |
MACRUM | 0:35a2186cf186 | 129 | req.cmd_sid = UART_CMD_SID_GEN_FW_VER_GET_REQ; |
MACRUM | 0:35a2186cf186 | 130 | req.seq = mUartRequestSeq++; |
MACRUM | 0:35a2186cf186 | 131 | |
MACRUM | 0:35a2186cf186 | 132 | unsigned char *command_array_p = snic_core_p->getCommandBuf(); |
MACRUM | 0:35a2186cf186 | 133 | unsigned int command_len; |
MACRUM | 0:35a2186cf186 | 134 | // Preparation of command |
MACRUM | 0:35a2186cf186 | 135 | command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_GEN, req.cmd_sid, (unsigned char *)&req |
MACRUM | 0:35a2186cf186 | 136 | , sizeof(C_SNIC_Core::tagGEN_FW_VER_GET_REQ_T), payload_buf_p->buf, command_array_p ); |
MACRUM | 0:35a2186cf186 | 137 | |
MACRUM | 0:35a2186cf186 | 138 | int ret; |
MACRUM | 0:35a2186cf186 | 139 | |
MACRUM | 0:35a2186cf186 | 140 | // Send uart command request |
MACRUM | 0:35a2186cf186 | 141 | snic_core_p->sendUart( command_len, command_array_p ); |
MACRUM | 0:35a2186cf186 | 142 | |
MACRUM | 0:35a2186cf186 | 143 | // Wait UART response |
MACRUM | 0:35a2186cf186 | 144 | ret = uartCmdMgr_p->wait(); |
MACRUM | 0:35a2186cf186 | 145 | if( ret != 0 ) |
MACRUM | 0:35a2186cf186 | 146 | { |
MACRUM | 0:35a2186cf186 | 147 | DEBUG_PRINT( "getFWversion failed\r\n" ); |
MACRUM | 0:35a2186cf186 | 148 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 149 | return -1; |
MACRUM | 0:35a2186cf186 | 150 | } |
MACRUM | 0:35a2186cf186 | 151 | |
MACRUM | 0:35a2186cf186 | 152 | if( uartCmdMgr_p->getCommandStatus() == 0 ) |
MACRUM | 0:35a2186cf186 | 153 | { |
MACRUM | 0:35a2186cf186 | 154 | unsigned char version_len = payload_buf_p->buf[3]; |
MACRUM | 0:35a2186cf186 | 155 | if (*length_p <= (int)version_len) { |
MACRUM | 0:35a2186cf186 | 156 | DEBUG_PRINT( "getFWversion verion_p is not enough memory\r\n" ); |
MACRUM | 0:35a2186cf186 | 157 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 158 | return -1; |
MACRUM | 0:35a2186cf186 | 159 | } |
MACRUM | 0:35a2186cf186 | 160 | memcpy( version_p, &payload_buf_p->buf[4], version_len ); |
MACRUM | 0:35a2186cf186 | 161 | version_p[version_len] = 0; |
MACRUM | 0:35a2186cf186 | 162 | } |
MACRUM | 0:35a2186cf186 | 163 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 164 | return 0; |
MACRUM | 0:35a2186cf186 | 165 | } |
MACRUM | 0:35a2186cf186 | 166 | |
MACRUM | 0:35a2186cf186 | 167 | int C_SNIC_WifiInterface::connect(const char *ssid_p, unsigned char ssid_len, E_SECURITY sec_type |
MACRUM | 0:35a2186cf186 | 168 | , const char *sec_key_p, unsigned char sec_key_len) |
MACRUM | 0:35a2186cf186 | 169 | { |
MACRUM | 0:35a2186cf186 | 170 | C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance(); |
MACRUM | 0:35a2186cf186 | 171 | C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand(); |
MACRUM | 0:35a2186cf186 | 172 | |
MACRUM | 0:35a2186cf186 | 173 | // Parameter check(SSID) |
MACRUM | 0:35a2186cf186 | 174 | if( (ssid_p == NULL) || (ssid_len == 0) ) |
MACRUM | 0:35a2186cf186 | 175 | { |
MACRUM | 0:35a2186cf186 | 176 | DEBUG_PRINT( "connect failed [ parameter NG:SSID ]\r\n" ); |
MACRUM | 0:35a2186cf186 | 177 | return -1; |
MACRUM | 0:35a2186cf186 | 178 | } |
MACRUM | 0:35a2186cf186 | 179 | |
MACRUM | 0:35a2186cf186 | 180 | // Parameter check(Security key) |
MACRUM | 0:35a2186cf186 | 181 | if( (sec_type != e_SEC_OPEN) && ( (sec_key_len == 0) || (sec_key_p == NULL) ) ) |
MACRUM | 0:35a2186cf186 | 182 | { |
MACRUM | 0:35a2186cf186 | 183 | DEBUG_PRINT( "connect failed [ parameter NG:Security key ]\r\n" ); |
MACRUM | 0:35a2186cf186 | 184 | return -1; |
MACRUM | 0:35a2186cf186 | 185 | } |
MACRUM | 0:35a2186cf186 | 186 | |
MACRUM | 0:35a2186cf186 | 187 | // Get buffer for response payload from MemoryPool |
MACRUM | 0:35a2186cf186 | 188 | tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf(); |
MACRUM | 0:35a2186cf186 | 189 | if( payload_buf_p == NULL ) |
MACRUM | 0:35a2186cf186 | 190 | { |
MACRUM | 0:35a2186cf186 | 191 | DEBUG_PRINT("connect payload_buf_p NULL\r\n"); |
MACRUM | 0:35a2186cf186 | 192 | return -1; |
MACRUM | 0:35a2186cf186 | 193 | } |
MACRUM | 0:35a2186cf186 | 194 | |
MACRUM | 0:35a2186cf186 | 195 | unsigned char *buf = &gCONNECT_BUF[0]; |
MACRUM | 0:35a2186cf186 | 196 | unsigned int buf_len = 0; |
MACRUM | 0:35a2186cf186 | 197 | unsigned int command_len; |
MACRUM | 0:35a2186cf186 | 198 | |
MACRUM | 0:35a2186cf186 | 199 | memset( buf, 0, UART_CONNECT_BUF_SIZE ); |
MACRUM | 0:35a2186cf186 | 200 | // Make request |
MACRUM | 0:35a2186cf186 | 201 | buf[0] = UART_CMD_SID_WIFI_JOIN_REQ; |
MACRUM | 0:35a2186cf186 | 202 | buf_len++; |
MACRUM | 0:35a2186cf186 | 203 | buf[1] = mUartRequestSeq++; |
MACRUM | 0:35a2186cf186 | 204 | buf_len++; |
MACRUM | 0:35a2186cf186 | 205 | // SSID |
MACRUM | 0:35a2186cf186 | 206 | memcpy( &buf[2], ssid_p, ssid_len ); |
MACRUM | 0:35a2186cf186 | 207 | buf_len += ssid_len; |
MACRUM | 0:35a2186cf186 | 208 | buf_len++; |
MACRUM | 0:35a2186cf186 | 209 | |
MACRUM | 0:35a2186cf186 | 210 | // Security mode |
MACRUM | 0:35a2186cf186 | 211 | buf[ buf_len ] = (unsigned char)sec_type; |
MACRUM | 0:35a2186cf186 | 212 | buf_len++; |
MACRUM | 0:35a2186cf186 | 213 | |
MACRUM | 0:35a2186cf186 | 214 | // Security key |
MACRUM | 0:35a2186cf186 | 215 | if( sec_type != e_SEC_OPEN ) |
MACRUM | 0:35a2186cf186 | 216 | { |
MACRUM | 0:35a2186cf186 | 217 | buf[ buf_len ] = sec_key_len; |
MACRUM | 0:35a2186cf186 | 218 | buf_len++; |
MACRUM | 0:35a2186cf186 | 219 | if( sec_key_len > 0 ) |
MACRUM | 0:35a2186cf186 | 220 | { |
MACRUM | 0:35a2186cf186 | 221 | memcpy( &buf[buf_len], sec_key_p, sec_key_len ); |
MACRUM | 0:35a2186cf186 | 222 | buf_len += sec_key_len; |
MACRUM | 0:35a2186cf186 | 223 | } |
MACRUM | 0:35a2186cf186 | 224 | } |
MACRUM | 0:35a2186cf186 | 225 | |
MACRUM | 0:35a2186cf186 | 226 | unsigned char *command_array_p = snic_core_p->getCommandBuf(); |
MACRUM | 0:35a2186cf186 | 227 | // Preparation of command |
MACRUM | 0:35a2186cf186 | 228 | command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, UART_CMD_SID_WIFI_JOIN_REQ, buf |
MACRUM | 0:35a2186cf186 | 229 | , buf_len, payload_buf_p->buf, command_array_p ); |
MACRUM | 0:35a2186cf186 | 230 | |
MACRUM | 0:35a2186cf186 | 231 | // Send uart command request |
MACRUM | 0:35a2186cf186 | 232 | snic_core_p->sendUart( command_len, command_array_p ); |
MACRUM | 0:35a2186cf186 | 233 | |
MACRUM | 0:35a2186cf186 | 234 | int ret; |
MACRUM | 0:35a2186cf186 | 235 | // Wait UART response |
MACRUM | 0:35a2186cf186 | 236 | ret = uartCmdMgr_p->wait(); |
MACRUM | 0:35a2186cf186 | 237 | if(uartCmdMgr_p->getCommandStatus() == UART_CMD_RES_WIFI_ERR_ALREADY_JOINED) |
MACRUM | 0:35a2186cf186 | 238 | { |
MACRUM | 0:35a2186cf186 | 239 | DEBUG_PRINT( "Already connected\r\n" ); |
MACRUM | 0:35a2186cf186 | 240 | } |
MACRUM | 0:35a2186cf186 | 241 | else |
MACRUM | 0:35a2186cf186 | 242 | { |
MACRUM | 0:35a2186cf186 | 243 | if( ret != 0 ) |
MACRUM | 0:35a2186cf186 | 244 | { |
MACRUM | 0:35a2186cf186 | 245 | DEBUG_PRINT( "join failed\r\n" ); |
MACRUM | 0:35a2186cf186 | 246 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 247 | return -1; |
MACRUM | 0:35a2186cf186 | 248 | } |
MACRUM | 0:35a2186cf186 | 249 | } |
MACRUM | 0:35a2186cf186 | 250 | |
MACRUM | 0:35a2186cf186 | 251 | if(uartCmdMgr_p->getCommandStatus() != 0) |
MACRUM | 0:35a2186cf186 | 252 | { |
MACRUM | 0:35a2186cf186 | 253 | DEBUG_PRINT("join status:%02x\r\n", uartCmdMgr_p->getCommandStatus()); |
MACRUM | 0:35a2186cf186 | 254 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 255 | return -1; |
MACRUM | 0:35a2186cf186 | 256 | } |
MACRUM | 0:35a2186cf186 | 257 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 258 | |
MACRUM | 0:35a2186cf186 | 259 | return ret; |
MACRUM | 0:35a2186cf186 | 260 | } |
MACRUM | 0:35a2186cf186 | 261 | |
MACRUM | 0:35a2186cf186 | 262 | int C_SNIC_WifiInterface::disconnect() |
MACRUM | 0:35a2186cf186 | 263 | { |
MACRUM | 0:35a2186cf186 | 264 | C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance(); |
MACRUM | 0:35a2186cf186 | 265 | C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand(); |
MACRUM | 0:35a2186cf186 | 266 | |
MACRUM | 0:35a2186cf186 | 267 | // Get buffer for response payload from MemoryPool |
MACRUM | 0:35a2186cf186 | 268 | tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf(); |
MACRUM | 0:35a2186cf186 | 269 | if( payload_buf_p == NULL ) |
MACRUM | 0:35a2186cf186 | 270 | { |
MACRUM | 0:35a2186cf186 | 271 | DEBUG_PRINT("disconnect payload_buf_p NULL\r\n"); |
MACRUM | 0:35a2186cf186 | 272 | return -1; |
MACRUM | 0:35a2186cf186 | 273 | } |
MACRUM | 0:35a2186cf186 | 274 | |
MACRUM | 0:35a2186cf186 | 275 | C_SNIC_Core::tagWIFI_DISCONNECT_REQ_T req; |
MACRUM | 0:35a2186cf186 | 276 | // Make request |
MACRUM | 0:35a2186cf186 | 277 | req.cmd_sid = UART_CMD_SID_WIFI_DISCONNECT_REQ; |
MACRUM | 0:35a2186cf186 | 278 | req.seq = mUartRequestSeq++; |
MACRUM | 0:35a2186cf186 | 279 | |
MACRUM | 0:35a2186cf186 | 280 | unsigned char *command_array_p = snic_core_p->getCommandBuf(); |
MACRUM | 0:35a2186cf186 | 281 | unsigned int command_len; |
MACRUM | 0:35a2186cf186 | 282 | // Preparation of command |
MACRUM | 0:35a2186cf186 | 283 | command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req |
MACRUM | 0:35a2186cf186 | 284 | , sizeof(C_SNIC_Core::tagWIFI_DISCONNECT_REQ_T), payload_buf_p->buf, command_array_p ); |
MACRUM | 0:35a2186cf186 | 285 | |
MACRUM | 0:35a2186cf186 | 286 | // Send uart command request |
MACRUM | 0:35a2186cf186 | 287 | snic_core_p->sendUart( command_len, command_array_p ); |
MACRUM | 0:35a2186cf186 | 288 | |
MACRUM | 0:35a2186cf186 | 289 | int ret; |
MACRUM | 0:35a2186cf186 | 290 | // Wait UART response |
MACRUM | 0:35a2186cf186 | 291 | ret = uartCmdMgr_p->wait(); |
MACRUM | 0:35a2186cf186 | 292 | if( ret != 0 ) |
MACRUM | 0:35a2186cf186 | 293 | { |
MACRUM | 0:35a2186cf186 | 294 | DEBUG_PRINT( "disconnect failed\r\n" ); |
MACRUM | 0:35a2186cf186 | 295 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 296 | return -1; |
MACRUM | 0:35a2186cf186 | 297 | } |
MACRUM | 0:35a2186cf186 | 298 | |
MACRUM | 0:35a2186cf186 | 299 | if( uartCmdMgr_p->getCommandStatus() != 0 ) |
MACRUM | 0:35a2186cf186 | 300 | { |
MACRUM | 0:35a2186cf186 | 301 | DEBUG_PRINT("disconnect status:%02x\r\n", uartCmdMgr_p->getCommandStatus()); |
MACRUM | 0:35a2186cf186 | 302 | ret = -1; |
MACRUM | 0:35a2186cf186 | 303 | } |
MACRUM | 0:35a2186cf186 | 304 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 305 | return ret; |
MACRUM | 0:35a2186cf186 | 306 | } |
MACRUM | 0:35a2186cf186 | 307 | |
MACRUM | 0:35a2186cf186 | 308 | int C_SNIC_WifiInterface::scan( const char *ssid_p, unsigned char *bssid_p |
MACRUM | 0:35a2186cf186 | 309 | , void (*result_handler_p)(tagSCAN_RESULT_T *scan_result) ) |
MACRUM | 0:35a2186cf186 | 310 | { |
MACRUM | 0:35a2186cf186 | 311 | C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance(); |
MACRUM | 0:35a2186cf186 | 312 | C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand(); |
MACRUM | 0:35a2186cf186 | 313 | |
MACRUM | 0:35a2186cf186 | 314 | // Get buffer for response payload from MemoryPool |
MACRUM | 0:35a2186cf186 | 315 | tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf(); |
MACRUM | 0:35a2186cf186 | 316 | if( payload_buf_p == NULL ) |
MACRUM | 0:35a2186cf186 | 317 | { |
MACRUM | 0:35a2186cf186 | 318 | DEBUG_PRINT("scan payload_buf_p NULL\r\n"); |
MACRUM | 0:35a2186cf186 | 319 | return -1; |
MACRUM | 0:35a2186cf186 | 320 | } |
MACRUM | 0:35a2186cf186 | 321 | |
MACRUM | 0:35a2186cf186 | 322 | C_SNIC_Core::tagWIFI_SCAN_REQ_T req; |
MACRUM | 0:35a2186cf186 | 323 | unsigned int buf_len = 0; |
MACRUM | 0:35a2186cf186 | 324 | |
MACRUM | 0:35a2186cf186 | 325 | memset( &req, 0, sizeof(C_SNIC_Core::tagWIFI_SCAN_REQ_T) ); |
MACRUM | 0:35a2186cf186 | 326 | // Make request |
MACRUM | 0:35a2186cf186 | 327 | req.cmd_sid = UART_CMD_SID_WIFI_SCAN_REQ; |
MACRUM | 0:35a2186cf186 | 328 | buf_len++; |
MACRUM | 0:35a2186cf186 | 329 | req.seq = mUartRequestSeq++; |
MACRUM | 0:35a2186cf186 | 330 | buf_len++; |
MACRUM | 0:35a2186cf186 | 331 | |
MACRUM | 0:35a2186cf186 | 332 | // Set scan type(Active scan) |
MACRUM | 0:35a2186cf186 | 333 | req.scan_type = 0; |
MACRUM | 0:35a2186cf186 | 334 | buf_len++; |
MACRUM | 0:35a2186cf186 | 335 | // Set bss type(any) |
MACRUM | 0:35a2186cf186 | 336 | req.bss_type = 2; |
MACRUM | 0:35a2186cf186 | 337 | buf_len++; |
MACRUM | 0:35a2186cf186 | 338 | // Set BSSID |
MACRUM | 0:35a2186cf186 | 339 | if( bssid_p != NULL ) |
MACRUM | 0:35a2186cf186 | 340 | { |
MACRUM | 0:35a2186cf186 | 341 | memcpy( req.bssid, bssid_p, BSSID_MAC_LENTH ); |
MACRUM | 0:35a2186cf186 | 342 | } |
MACRUM | 0:35a2186cf186 | 343 | buf_len += BSSID_MAC_LENTH; |
MACRUM | 0:35a2186cf186 | 344 | // Set channel list(0) |
MACRUM | 0:35a2186cf186 | 345 | req.chan_list = 0; |
MACRUM | 0:35a2186cf186 | 346 | buf_len++; |
MACRUM | 0:35a2186cf186 | 347 | //Set SSID |
MACRUM | 0:35a2186cf186 | 348 | if( ssid_p != NULL ) |
MACRUM | 0:35a2186cf186 | 349 | { |
MACRUM | 0:35a2186cf186 | 350 | strcpy( (char *)req.ssid, ssid_p ); |
MACRUM | 0:35a2186cf186 | 351 | buf_len += strlen(ssid_p); |
MACRUM | 0:35a2186cf186 | 352 | } |
MACRUM | 0:35a2186cf186 | 353 | buf_len++; |
MACRUM | 0:35a2186cf186 | 354 | |
MACRUM | 0:35a2186cf186 | 355 | unsigned char *command_array_p = snic_core_p->getCommandBuf(); |
MACRUM | 0:35a2186cf186 | 356 | unsigned int command_len; |
MACRUM | 0:35a2186cf186 | 357 | // Preparation of command |
MACRUM | 0:35a2186cf186 | 358 | command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req |
MACRUM | 0:35a2186cf186 | 359 | , buf_len, payload_buf_p->buf, command_array_p ); |
MACRUM | 0:35a2186cf186 | 360 | |
MACRUM | 0:35a2186cf186 | 361 | // Set scan result callback |
MACRUM | 0:35a2186cf186 | 362 | uartCmdMgr_p->setScanResultHandler( result_handler_p ); |
MACRUM | 0:35a2186cf186 | 363 | |
MACRUM | 0:35a2186cf186 | 364 | // Send uart command request |
MACRUM | 0:35a2186cf186 | 365 | snic_core_p->sendUart( command_len, command_array_p ); |
MACRUM | 0:35a2186cf186 | 366 | |
MACRUM | 0:35a2186cf186 | 367 | int ret; |
MACRUM | 0:35a2186cf186 | 368 | // Wait UART response |
MACRUM | 0:35a2186cf186 | 369 | ret = uartCmdMgr_p->wait(); |
MACRUM | 0:35a2186cf186 | 370 | DEBUG_PRINT( "scan wait:%d\r\n", ret ); |
MACRUM | 0:35a2186cf186 | 371 | if( ret != 0 ) |
MACRUM | 0:35a2186cf186 | 372 | { |
MACRUM | 0:35a2186cf186 | 373 | DEBUG_PRINT( "scan failed\r\n" ); |
MACRUM | 0:35a2186cf186 | 374 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 375 | return -1; |
MACRUM | 0:35a2186cf186 | 376 | } |
MACRUM | 0:35a2186cf186 | 377 | |
MACRUM | 0:35a2186cf186 | 378 | if( uartCmdMgr_p->getCommandStatus() != 0 ) |
MACRUM | 0:35a2186cf186 | 379 | { |
MACRUM | 0:35a2186cf186 | 380 | DEBUG_PRINT("scan status:%02x\r\n", uartCmdMgr_p->getCommandStatus()); |
MACRUM | 0:35a2186cf186 | 381 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 382 | return -1; |
MACRUM | 0:35a2186cf186 | 383 | } |
MACRUM | 0:35a2186cf186 | 384 | |
MACRUM | 0:35a2186cf186 | 385 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 386 | |
MACRUM | 0:35a2186cf186 | 387 | return ret; |
MACRUM | 0:35a2186cf186 | 388 | } |
MACRUM | 0:35a2186cf186 | 389 | |
MACRUM | 0:35a2186cf186 | 390 | int C_SNIC_WifiInterface::wifi_on( const char *country_p ) |
MACRUM | 0:35a2186cf186 | 391 | { |
MACRUM | 0:35a2186cf186 | 392 | C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance(); |
MACRUM | 0:35a2186cf186 | 393 | C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand(); |
MACRUM | 0:35a2186cf186 | 394 | |
MACRUM | 0:35a2186cf186 | 395 | // Parameter check |
MACRUM | 0:35a2186cf186 | 396 | if( country_p == NULL ) |
MACRUM | 0:35a2186cf186 | 397 | { |
MACRUM | 0:35a2186cf186 | 398 | DEBUG_PRINT("wifi_on parameter error\r\n"); |
MACRUM | 0:35a2186cf186 | 399 | return -1; |
MACRUM | 0:35a2186cf186 | 400 | } |
MACRUM | 0:35a2186cf186 | 401 | |
MACRUM | 0:35a2186cf186 | 402 | // Get buffer for response payload from MemoryPool |
MACRUM | 0:35a2186cf186 | 403 | tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf(); |
MACRUM | 0:35a2186cf186 | 404 | if( payload_buf_p == NULL ) |
MACRUM | 0:35a2186cf186 | 405 | { |
MACRUM | 0:35a2186cf186 | 406 | DEBUG_PRINT("wifi_on payload_buf_p NULL\r\n"); |
MACRUM | 0:35a2186cf186 | 407 | return -1; |
MACRUM | 0:35a2186cf186 | 408 | } |
MACRUM | 0:35a2186cf186 | 409 | |
MACRUM | 0:35a2186cf186 | 410 | C_SNIC_Core::tagWIFI_ON_REQ_T req; |
MACRUM | 0:35a2186cf186 | 411 | // Make request |
MACRUM | 0:35a2186cf186 | 412 | req.cmd_sid = UART_CMD_SID_WIFI_ON_REQ; |
MACRUM | 0:35a2186cf186 | 413 | req.seq = mUartRequestSeq++; |
MACRUM | 0:35a2186cf186 | 414 | memcpy( req.country, country_p, COUNTRYC_CODE_LENTH ); |
MACRUM | 0:35a2186cf186 | 415 | |
MACRUM | 0:35a2186cf186 | 416 | unsigned char *command_array_p = snic_core_p->getCommandBuf(); |
MACRUM | 0:35a2186cf186 | 417 | unsigned int command_len; |
MACRUM | 0:35a2186cf186 | 418 | // Preparation of command |
MACRUM | 0:35a2186cf186 | 419 | command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req |
MACRUM | 0:35a2186cf186 | 420 | , sizeof(C_SNIC_Core::tagWIFI_ON_REQ_T), payload_buf_p->buf, command_array_p ); |
MACRUM | 0:35a2186cf186 | 421 | |
MACRUM | 0:35a2186cf186 | 422 | // Send uart command request |
MACRUM | 0:35a2186cf186 | 423 | snic_core_p->sendUart( command_len, command_array_p ); |
MACRUM | 0:35a2186cf186 | 424 | |
MACRUM | 0:35a2186cf186 | 425 | int ret; |
MACRUM | 0:35a2186cf186 | 426 | // Wait UART response |
MACRUM | 0:35a2186cf186 | 427 | ret = uartCmdMgr_p->wait(); |
MACRUM | 0:35a2186cf186 | 428 | if( ret != 0 ) |
MACRUM | 0:35a2186cf186 | 429 | { |
MACRUM | 0:35a2186cf186 | 430 | DEBUG_PRINT( "wifi_on failed\r\n" ); |
MACRUM | 0:35a2186cf186 | 431 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 432 | return -1; |
MACRUM | 0:35a2186cf186 | 433 | } |
MACRUM | 0:35a2186cf186 | 434 | |
MACRUM | 0:35a2186cf186 | 435 | if( uartCmdMgr_p->getCommandStatus() != 0 ) |
MACRUM | 0:35a2186cf186 | 436 | { |
MACRUM | 0:35a2186cf186 | 437 | DEBUG_PRINT("wifi_on status:%02x\r\n", uartCmdMgr_p->getCommandStatus()); |
MACRUM | 0:35a2186cf186 | 438 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 439 | return -1; |
MACRUM | 0:35a2186cf186 | 440 | } |
MACRUM | 0:35a2186cf186 | 441 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 442 | |
MACRUM | 0:35a2186cf186 | 443 | return ret; |
MACRUM | 0:35a2186cf186 | 444 | } |
MACRUM | 0:35a2186cf186 | 445 | |
MACRUM | 0:35a2186cf186 | 446 | int C_SNIC_WifiInterface::wifi_off() |
MACRUM | 0:35a2186cf186 | 447 | { |
MACRUM | 0:35a2186cf186 | 448 | C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance(); |
MACRUM | 0:35a2186cf186 | 449 | C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand(); |
MACRUM | 0:35a2186cf186 | 450 | |
MACRUM | 0:35a2186cf186 | 451 | // Get buffer for response payload from MemoryPool |
MACRUM | 0:35a2186cf186 | 452 | tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf(); |
MACRUM | 0:35a2186cf186 | 453 | if( payload_buf_p == NULL ) |
MACRUM | 0:35a2186cf186 | 454 | { |
MACRUM | 0:35a2186cf186 | 455 | DEBUG_PRINT("wifi_off payload_buf_p NULL\r\n"); |
MACRUM | 0:35a2186cf186 | 456 | return -1; |
MACRUM | 0:35a2186cf186 | 457 | } |
MACRUM | 0:35a2186cf186 | 458 | |
MACRUM | 0:35a2186cf186 | 459 | C_SNIC_Core::tagWIFI_OFF_REQ_T req; |
MACRUM | 0:35a2186cf186 | 460 | // Make request |
MACRUM | 0:35a2186cf186 | 461 | req.cmd_sid = UART_CMD_SID_WIFI_OFF_REQ; |
MACRUM | 0:35a2186cf186 | 462 | req.seq = mUartRequestSeq++; |
MACRUM | 0:35a2186cf186 | 463 | |
MACRUM | 0:35a2186cf186 | 464 | unsigned char *command_array_p = snic_core_p->getCommandBuf(); |
MACRUM | 0:35a2186cf186 | 465 | unsigned int command_len; |
MACRUM | 0:35a2186cf186 | 466 | // Preparation of command |
MACRUM | 0:35a2186cf186 | 467 | command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req |
MACRUM | 0:35a2186cf186 | 468 | , sizeof(C_SNIC_Core::tagWIFI_OFF_REQ_T), payload_buf_p->buf, command_array_p ); |
MACRUM | 0:35a2186cf186 | 469 | |
MACRUM | 0:35a2186cf186 | 470 | // Send uart command request |
MACRUM | 0:35a2186cf186 | 471 | snic_core_p->sendUart( command_len, command_array_p ); |
MACRUM | 0:35a2186cf186 | 472 | |
MACRUM | 0:35a2186cf186 | 473 | int ret; |
MACRUM | 0:35a2186cf186 | 474 | // Wait UART response |
MACRUM | 0:35a2186cf186 | 475 | ret = uartCmdMgr_p->wait(); |
MACRUM | 0:35a2186cf186 | 476 | if( ret != 0 ) |
MACRUM | 0:35a2186cf186 | 477 | { |
MACRUM | 0:35a2186cf186 | 478 | DEBUG_PRINT( "wifi_off failed\r\n" ); |
MACRUM | 0:35a2186cf186 | 479 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 480 | return -1; |
MACRUM | 0:35a2186cf186 | 481 | } |
MACRUM | 0:35a2186cf186 | 482 | |
MACRUM | 0:35a2186cf186 | 483 | if( uartCmdMgr_p->getCommandStatus() != 0 ) |
MACRUM | 0:35a2186cf186 | 484 | { |
MACRUM | 0:35a2186cf186 | 485 | DEBUG_PRINT("wifi_off status:%02x\r\n", uartCmdMgr_p->getCommandStatus()); |
MACRUM | 0:35a2186cf186 | 486 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 487 | return -1; |
MACRUM | 0:35a2186cf186 | 488 | } |
MACRUM | 0:35a2186cf186 | 489 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 490 | |
MACRUM | 0:35a2186cf186 | 491 | return ret; |
MACRUM | 0:35a2186cf186 | 492 | } |
MACRUM | 0:35a2186cf186 | 493 | |
MACRUM | 0:35a2186cf186 | 494 | int C_SNIC_WifiInterface::wifi_softap_off() |
MACRUM | 0:35a2186cf186 | 495 | { |
MACRUM | 0:35a2186cf186 | 496 | C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance(); |
MACRUM | 0:35a2186cf186 | 497 | C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand(); |
MACRUM | 0:35a2186cf186 | 498 | |
MACRUM | 0:35a2186cf186 | 499 | // Get buffer for response payload from MemoryPool |
MACRUM | 0:35a2186cf186 | 500 | tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf(); |
MACRUM | 0:35a2186cf186 | 501 | if( payload_buf_p == NULL ) |
MACRUM | 0:35a2186cf186 | 502 | { |
MACRUM | 0:35a2186cf186 | 503 | DEBUG_PRINT("wifi_off payload_buf_p NULL\r\n"); |
MACRUM | 0:35a2186cf186 | 504 | return -1; |
MACRUM | 0:35a2186cf186 | 505 | } |
MACRUM | 0:35a2186cf186 | 506 | |
MACRUM | 0:35a2186cf186 | 507 | C_SNIC_Core::tagWIFI_AP_CTRL_REQ_T req; |
MACRUM | 0:35a2186cf186 | 508 | // Make request |
MACRUM | 0:35a2186cf186 | 509 | req.cmd_sid = UART_CMD_SID_WIFI_AP_CTRL_REQ; |
MACRUM | 0:35a2186cf186 | 510 | req.seq = mUartRequestSeq++; |
MACRUM | 0:35a2186cf186 | 511 | req.on_off = 0; |
MACRUM | 0:35a2186cf186 | 512 | req.persistency = 1; |
MACRUM | 0:35a2186cf186 | 513 | |
MACRUM | 0:35a2186cf186 | 514 | unsigned char *command_array_p = snic_core_p->getCommandBuf(); |
MACRUM | 0:35a2186cf186 | 515 | unsigned int command_len; |
MACRUM | 0:35a2186cf186 | 516 | // Preparation of command |
MACRUM | 0:35a2186cf186 | 517 | command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req |
MACRUM | 0:35a2186cf186 | 518 | , sizeof(C_SNIC_Core::tagWIFI_AP_CTRL_REQ_T), payload_buf_p->buf, command_array_p ); |
MACRUM | 0:35a2186cf186 | 519 | |
MACRUM | 0:35a2186cf186 | 520 | // Send uart command request |
MACRUM | 0:35a2186cf186 | 521 | snic_core_p->sendUart( command_len, command_array_p ); |
MACRUM | 0:35a2186cf186 | 522 | |
MACRUM | 0:35a2186cf186 | 523 | int ret; |
MACRUM | 0:35a2186cf186 | 524 | // Wait UART response |
MACRUM | 0:35a2186cf186 | 525 | ret = uartCmdMgr_p->wait(); |
MACRUM | 0:35a2186cf186 | 526 | if( ret != 0 ) |
MACRUM | 0:35a2186cf186 | 527 | { |
MACRUM | 0:35a2186cf186 | 528 | DEBUG_PRINT( "wifi_ap_crtl failed\r\n" ); |
MACRUM | 0:35a2186cf186 | 529 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 530 | return -1; |
MACRUM | 0:35a2186cf186 | 531 | } |
MACRUM | 0:35a2186cf186 | 532 | |
MACRUM | 0:35a2186cf186 | 533 | if( uartCmdMgr_p->getCommandStatus() != 0 ) |
MACRUM | 0:35a2186cf186 | 534 | { |
MACRUM | 0:35a2186cf186 | 535 | DEBUG_PRINT("wifi_ap_crtl status:%02x\r\n", uartCmdMgr_p->getCommandStatus()); |
MACRUM | 0:35a2186cf186 | 536 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 537 | return -1; |
MACRUM | 0:35a2186cf186 | 538 | } |
MACRUM | 0:35a2186cf186 | 539 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 540 | |
MACRUM | 0:35a2186cf186 | 541 | return ret; |
MACRUM | 0:35a2186cf186 | 542 | } |
MACRUM | 0:35a2186cf186 | 543 | |
MACRUM | 0:35a2186cf186 | 544 | int C_SNIC_WifiInterface::getRssi( signed char *rssi_p ) |
MACRUM | 0:35a2186cf186 | 545 | { |
MACRUM | 0:35a2186cf186 | 546 | C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance(); |
MACRUM | 0:35a2186cf186 | 547 | C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand(); |
MACRUM | 0:35a2186cf186 | 548 | if( rssi_p == NULL ) |
MACRUM | 0:35a2186cf186 | 549 | { |
MACRUM | 0:35a2186cf186 | 550 | DEBUG_PRINT("getRssi parameter error\r\n"); |
MACRUM | 0:35a2186cf186 | 551 | return -1; |
MACRUM | 0:35a2186cf186 | 552 | } |
MACRUM | 0:35a2186cf186 | 553 | |
MACRUM | 0:35a2186cf186 | 554 | // Get buffer for response payload from MemoryPool |
MACRUM | 0:35a2186cf186 | 555 | tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf(); |
MACRUM | 0:35a2186cf186 | 556 | if( payload_buf_p == NULL ) |
MACRUM | 0:35a2186cf186 | 557 | { |
MACRUM | 0:35a2186cf186 | 558 | DEBUG_PRINT("getRssi payload_buf_p NULL\r\n"); |
MACRUM | 0:35a2186cf186 | 559 | return -1; |
MACRUM | 0:35a2186cf186 | 560 | } |
MACRUM | 0:35a2186cf186 | 561 | |
MACRUM | 0:35a2186cf186 | 562 | C_SNIC_Core::tagWIFI_GET_STA_RSSI_REQ_T req; |
MACRUM | 0:35a2186cf186 | 563 | |
MACRUM | 0:35a2186cf186 | 564 | // Make request |
MACRUM | 0:35a2186cf186 | 565 | req.cmd_sid = UART_CMD_SID_WIFI_GET_STA_RSSI_REQ; |
MACRUM | 0:35a2186cf186 | 566 | req.seq = mUartRequestSeq++; |
MACRUM | 0:35a2186cf186 | 567 | |
MACRUM | 0:35a2186cf186 | 568 | unsigned char *command_array_p = snic_core_p->getCommandBuf(); |
MACRUM | 0:35a2186cf186 | 569 | unsigned int command_len; |
MACRUM | 0:35a2186cf186 | 570 | command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req |
MACRUM | 0:35a2186cf186 | 571 | , sizeof(C_SNIC_Core::tagWIFI_GET_STA_RSSI_REQ_T), payload_buf_p->buf, command_array_p ); |
MACRUM | 0:35a2186cf186 | 572 | |
MACRUM | 0:35a2186cf186 | 573 | int ret; |
MACRUM | 0:35a2186cf186 | 574 | // Send uart command request |
MACRUM | 0:35a2186cf186 | 575 | snic_core_p->sendUart( command_len, command_array_p ); |
MACRUM | 0:35a2186cf186 | 576 | |
MACRUM | 0:35a2186cf186 | 577 | // Wait UART response |
MACRUM | 0:35a2186cf186 | 578 | ret = uartCmdMgr_p->wait(); |
MACRUM | 0:35a2186cf186 | 579 | if( ret != 0 ) |
MACRUM | 0:35a2186cf186 | 580 | { |
MACRUM | 0:35a2186cf186 | 581 | DEBUG_PRINT( "getRssi failed\r\n" ); |
MACRUM | 0:35a2186cf186 | 582 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 583 | return -1; |
MACRUM | 0:35a2186cf186 | 584 | } |
MACRUM | 0:35a2186cf186 | 585 | |
MACRUM | 0:35a2186cf186 | 586 | *rssi_p = (signed char)payload_buf_p->buf[2]; |
MACRUM | 0:35a2186cf186 | 587 | |
MACRUM | 0:35a2186cf186 | 588 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 589 | return 0; |
MACRUM | 0:35a2186cf186 | 590 | } |
MACRUM | 0:35a2186cf186 | 591 | |
MACRUM | 0:35a2186cf186 | 592 | int C_SNIC_WifiInterface::getWifiStatus( tagWIFI_STATUS_T *status_p) |
MACRUM | 0:35a2186cf186 | 593 | { |
MACRUM | 0:35a2186cf186 | 594 | C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance(); |
MACRUM | 0:35a2186cf186 | 595 | C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand(); |
MACRUM | 0:35a2186cf186 | 596 | |
MACRUM | 0:35a2186cf186 | 597 | if( status_p == NULL ) |
MACRUM | 0:35a2186cf186 | 598 | { |
MACRUM | 0:35a2186cf186 | 599 | DEBUG_PRINT("getWifiStatus parameter error\r\n"); |
MACRUM | 0:35a2186cf186 | 600 | return -1; |
MACRUM | 0:35a2186cf186 | 601 | } |
MACRUM | 0:35a2186cf186 | 602 | |
MACRUM | 0:35a2186cf186 | 603 | // Get buffer for response payload from MemoryPool |
MACRUM | 0:35a2186cf186 | 604 | tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf(); |
MACRUM | 0:35a2186cf186 | 605 | if( payload_buf_p == NULL ) |
MACRUM | 0:35a2186cf186 | 606 | { |
MACRUM | 0:35a2186cf186 | 607 | DEBUG_PRINT("getWifiStatus payload_buf_p NULL\r\n"); |
MACRUM | 0:35a2186cf186 | 608 | return -1; |
MACRUM | 0:35a2186cf186 | 609 | } |
MACRUM | 0:35a2186cf186 | 610 | |
MACRUM | 0:35a2186cf186 | 611 | C_SNIC_Core::tagWIFI_GET_STATUS_REQ_T req; |
MACRUM | 0:35a2186cf186 | 612 | // Make request |
MACRUM | 0:35a2186cf186 | 613 | req.cmd_sid = UART_CMD_SID_WIFI_GET_STATUS_REQ; |
MACRUM | 0:35a2186cf186 | 614 | req.seq = mUartRequestSeq++; |
MACRUM | 0:35a2186cf186 | 615 | req.interface = 0; |
MACRUM | 0:35a2186cf186 | 616 | |
MACRUM | 0:35a2186cf186 | 617 | unsigned char *command_array_p = snic_core_p->getCommandBuf(); |
MACRUM | 0:35a2186cf186 | 618 | unsigned int command_len; |
MACRUM | 0:35a2186cf186 | 619 | command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req |
MACRUM | 0:35a2186cf186 | 620 | , sizeof(C_SNIC_Core::tagWIFI_GET_STATUS_REQ_T), payload_buf_p->buf, command_array_p ); |
MACRUM | 0:35a2186cf186 | 621 | |
MACRUM | 0:35a2186cf186 | 622 | // Send uart command request |
MACRUM | 0:35a2186cf186 | 623 | snic_core_p->sendUart( command_len, command_array_p ); |
MACRUM | 0:35a2186cf186 | 624 | |
MACRUM | 0:35a2186cf186 | 625 | int ret; |
MACRUM | 0:35a2186cf186 | 626 | // Wait UART response |
MACRUM | 0:35a2186cf186 | 627 | ret = uartCmdMgr_p->wait(); |
MACRUM | 0:35a2186cf186 | 628 | if( ret != 0 ) |
MACRUM | 0:35a2186cf186 | 629 | { |
MACRUM | 0:35a2186cf186 | 630 | DEBUG_PRINT( "getWifiStatus failed\r\n" ); |
MACRUM | 0:35a2186cf186 | 631 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 632 | return -1; |
MACRUM | 0:35a2186cf186 | 633 | } |
MACRUM | 0:35a2186cf186 | 634 | |
MACRUM | 0:35a2186cf186 | 635 | // set status |
MACRUM | 0:35a2186cf186 | 636 | status_p->status = (E_WIFI_STATUS)payload_buf_p->buf[2]; |
MACRUM | 0:35a2186cf186 | 637 | |
MACRUM | 0:35a2186cf186 | 638 | // set Mac address |
MACRUM | 0:35a2186cf186 | 639 | if( status_p->status != e_STATUS_OFF ) |
MACRUM | 0:35a2186cf186 | 640 | { |
MACRUM | 0:35a2186cf186 | 641 | memcpy( status_p->mac_address, &payload_buf_p->buf[3], BSSID_MAC_LENTH ); |
MACRUM | 0:35a2186cf186 | 642 | } |
MACRUM | 0:35a2186cf186 | 643 | |
MACRUM | 0:35a2186cf186 | 644 | // set SSID |
MACRUM | 0:35a2186cf186 | 645 | if( ( status_p->status == e_STA_JOINED ) || ( status_p->status == e_AP_STARTED ) ) |
MACRUM | 0:35a2186cf186 | 646 | { |
MACRUM | 0:35a2186cf186 | 647 | memcpy( status_p->ssid, &payload_buf_p->buf[9], strlen( (char *)&payload_buf_p->buf[9]) ); |
MACRUM | 0:35a2186cf186 | 648 | } |
MACRUM | 0:35a2186cf186 | 649 | |
MACRUM | 0:35a2186cf186 | 650 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 651 | return 0; |
MACRUM | 0:35a2186cf186 | 652 | } |
MACRUM | 0:35a2186cf186 | 653 | |
MACRUM | 0:35a2186cf186 | 654 | int C_SNIC_WifiInterface::setIPConfig( bool is_DHCP |
MACRUM | 0:35a2186cf186 | 655 | , const char *ip_p, const char *mask_p, const char *gateway_p ) |
MACRUM | 0:35a2186cf186 | 656 | { |
MACRUM | 0:35a2186cf186 | 657 | // Parameter check |
MACRUM | 0:35a2186cf186 | 658 | if( is_DHCP == false ) |
MACRUM | 0:35a2186cf186 | 659 | { |
MACRUM | 0:35a2186cf186 | 660 | if( (ip_p == NULL) || (mask_p == NULL) ||(gateway_p == NULL) ) |
MACRUM | 0:35a2186cf186 | 661 | { |
MACRUM | 0:35a2186cf186 | 662 | DEBUG_PRINT("setIPConfig parameter error\r\n"); |
MACRUM | 0:35a2186cf186 | 663 | return -1; |
MACRUM | 0:35a2186cf186 | 664 | } |
MACRUM | 0:35a2186cf186 | 665 | } |
MACRUM | 0:35a2186cf186 | 666 | |
MACRUM | 0:35a2186cf186 | 667 | C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance(); |
MACRUM | 0:35a2186cf186 | 668 | C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand(); |
MACRUM | 0:35a2186cf186 | 669 | |
MACRUM | 0:35a2186cf186 | 670 | // Get buffer for response payload from MemoryPool |
MACRUM | 0:35a2186cf186 | 671 | tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf(); |
MACRUM | 0:35a2186cf186 | 672 | if( payload_buf_p == NULL ) |
MACRUM | 0:35a2186cf186 | 673 | { |
MACRUM | 0:35a2186cf186 | 674 | DEBUG_PRINT("setIPConfig payload_buf_p NULL\r\n"); |
MACRUM | 0:35a2186cf186 | 675 | return -1; |
MACRUM | 0:35a2186cf186 | 676 | } |
MACRUM | 0:35a2186cf186 | 677 | |
MACRUM | 0:35a2186cf186 | 678 | unsigned char *command_array_p = snic_core_p->getCommandBuf(); |
MACRUM | 0:35a2186cf186 | 679 | unsigned int command_len; |
MACRUM | 0:35a2186cf186 | 680 | if( is_DHCP == true ) |
MACRUM | 0:35a2186cf186 | 681 | { |
MACRUM | 0:35a2186cf186 | 682 | C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_DHCP_T req; |
MACRUM | 0:35a2186cf186 | 683 | // Make request |
MACRUM | 0:35a2186cf186 | 684 | req.cmd_sid = UART_CMD_SID_SNIC_IP_CONFIG_REQ; |
MACRUM | 0:35a2186cf186 | 685 | req.seq = mUartRequestSeq++; |
MACRUM | 0:35a2186cf186 | 686 | req.interface = 0; |
MACRUM | 0:35a2186cf186 | 687 | req.dhcp = 1; |
MACRUM | 0:35a2186cf186 | 688 | |
MACRUM | 0:35a2186cf186 | 689 | // Preparation of command |
MACRUM | 0:35a2186cf186 | 690 | command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req |
MACRUM | 0:35a2186cf186 | 691 | , sizeof(C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_DHCP_T), payload_buf_p->buf, command_array_p ); |
MACRUM | 0:35a2186cf186 | 692 | } |
MACRUM | 0:35a2186cf186 | 693 | else |
MACRUM | 0:35a2186cf186 | 694 | { |
MACRUM | 0:35a2186cf186 | 695 | C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_STATIC_T req; |
MACRUM | 0:35a2186cf186 | 696 | // Make request |
MACRUM | 0:35a2186cf186 | 697 | req.cmd_sid = UART_CMD_SID_SNIC_IP_CONFIG_REQ; |
MACRUM | 0:35a2186cf186 | 698 | req.seq = mUartRequestSeq++; |
MACRUM | 0:35a2186cf186 | 699 | req.interface = 0; |
MACRUM | 0:35a2186cf186 | 700 | req.dhcp = 0; |
MACRUM | 0:35a2186cf186 | 701 | |
MACRUM | 0:35a2186cf186 | 702 | // Set paramter of address |
MACRUM | 0:35a2186cf186 | 703 | int addr_temp; |
MACRUM | 0:35a2186cf186 | 704 | addr_temp = C_SNIC_UartMsgUtil::addrToInteger( ip_p ); |
MACRUM | 0:35a2186cf186 | 705 | C_SNIC_UartMsgUtil::convertIntToByteAdday( addr_temp, (char *)req.ip_addr ); |
MACRUM | 0:35a2186cf186 | 706 | addr_temp = C_SNIC_UartMsgUtil::addrToInteger( mask_p ); |
MACRUM | 0:35a2186cf186 | 707 | C_SNIC_UartMsgUtil::convertIntToByteAdday( addr_temp, (char *)req.netmask ); |
MACRUM | 0:35a2186cf186 | 708 | addr_temp = C_SNIC_UartMsgUtil::addrToInteger( gateway_p ); |
MACRUM | 0:35a2186cf186 | 709 | C_SNIC_UartMsgUtil::convertIntToByteAdday( addr_temp, (char *)req.gateway ); |
MACRUM | 0:35a2186cf186 | 710 | |
MACRUM | 0:35a2186cf186 | 711 | // Preparation of command |
MACRUM | 0:35a2186cf186 | 712 | command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req |
MACRUM | 0:35a2186cf186 | 713 | , sizeof(C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_STATIC_T), payload_buf_p->buf, command_array_p ); |
MACRUM | 0:35a2186cf186 | 714 | } |
MACRUM | 0:35a2186cf186 | 715 | // Send uart command request |
MACRUM | 0:35a2186cf186 | 716 | snic_core_p->sendUart( command_len, command_array_p ); |
MACRUM | 0:35a2186cf186 | 717 | |
MACRUM | 0:35a2186cf186 | 718 | int ret; |
MACRUM | 0:35a2186cf186 | 719 | // Wait UART response |
MACRUM | 0:35a2186cf186 | 720 | ret = uartCmdMgr_p->wait(); |
MACRUM | 0:35a2186cf186 | 721 | if( ret != 0 ) |
MACRUM | 0:35a2186cf186 | 722 | { |
MACRUM | 0:35a2186cf186 | 723 | DEBUG_PRINT( "setIPConfig failed\r\n" ); |
MACRUM | 0:35a2186cf186 | 724 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 725 | return -1; |
MACRUM | 0:35a2186cf186 | 726 | } |
MACRUM | 0:35a2186cf186 | 727 | |
MACRUM | 0:35a2186cf186 | 728 | if( uartCmdMgr_p->getCommandStatus() != 0 ) |
MACRUM | 0:35a2186cf186 | 729 | { |
MACRUM | 0:35a2186cf186 | 730 | DEBUG_PRINT("setIPConfig status:%02x\r\n", uartCmdMgr_p->getCommandStatus()); |
MACRUM | 0:35a2186cf186 | 731 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 732 | return -1; |
MACRUM | 0:35a2186cf186 | 733 | } |
MACRUM | 0:35a2186cf186 | 734 | |
MACRUM | 0:35a2186cf186 | 735 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 736 | return ret; |
MACRUM | 0:35a2186cf186 | 737 | } |
MACRUM | 0:35a2186cf186 | 738 | |
MACRUM | 0:35a2186cf186 | 739 | char* C_SNIC_WifiInterface::getIPAddress() { |
MACRUM | 0:35a2186cf186 | 740 | C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance(); |
MACRUM | 0:35a2186cf186 | 741 | C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand(); |
MACRUM | 0:35a2186cf186 | 742 | |
MACRUM | 0:35a2186cf186 | 743 | snic_core_p->lockAPI(); |
MACRUM | 0:35a2186cf186 | 744 | // Get local ip address. |
MACRUM | 0:35a2186cf186 | 745 | // Get buffer for response payload from MemoryPool |
MACRUM | 0:35a2186cf186 | 746 | tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf(); |
MACRUM | 0:35a2186cf186 | 747 | if( payload_buf_p == NULL ) |
MACRUM | 0:35a2186cf186 | 748 | { |
MACRUM | 0:35a2186cf186 | 749 | DEBUG_PRINT("getIPAddress payload_buf_p NULL\r\n"); |
MACRUM | 0:35a2186cf186 | 750 | snic_core_p->unlockAPI(); |
MACRUM | 0:35a2186cf186 | 751 | return 0; |
MACRUM | 0:35a2186cf186 | 752 | } |
MACRUM | 0:35a2186cf186 | 753 | |
MACRUM | 0:35a2186cf186 | 754 | C_SNIC_Core::tagSNIC_GET_DHCP_INFO_REQ_T req; |
MACRUM | 0:35a2186cf186 | 755 | // Make request |
MACRUM | 0:35a2186cf186 | 756 | req.cmd_sid = UART_CMD_SID_SNIC_GET_DHCP_INFO_REQ; |
MACRUM | 0:35a2186cf186 | 757 | req.seq = mUartRequestSeq++; |
MACRUM | 0:35a2186cf186 | 758 | req.interface = 0; |
MACRUM | 0:35a2186cf186 | 759 | |
MACRUM | 0:35a2186cf186 | 760 | unsigned char *command_array_p = snic_core_p->getCommandBuf(); |
MACRUM | 0:35a2186cf186 | 761 | unsigned int command_len; |
MACRUM | 0:35a2186cf186 | 762 | // Preparation of command |
MACRUM | 0:35a2186cf186 | 763 | command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req |
MACRUM | 0:35a2186cf186 | 764 | , sizeof(C_SNIC_Core::tagSNIC_GET_DHCP_INFO_REQ_T), payload_buf_p->buf, command_array_p ); |
MACRUM | 0:35a2186cf186 | 765 | // Send uart command request |
MACRUM | 0:35a2186cf186 | 766 | snic_core_p->sendUart( command_len, command_array_p ); |
MACRUM | 0:35a2186cf186 | 767 | // Wait UART response |
MACRUM | 0:35a2186cf186 | 768 | int ret = uartCmdMgr_p->wait(); |
MACRUM | 0:35a2186cf186 | 769 | if( ret != 0 ) |
MACRUM | 0:35a2186cf186 | 770 | { |
MACRUM | 0:35a2186cf186 | 771 | DEBUG_PRINT( "getIPAddress failed\r\n" ); |
MACRUM | 0:35a2186cf186 | 772 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 773 | snic_core_p->unlockAPI(); |
MACRUM | 0:35a2186cf186 | 774 | return 0; |
MACRUM | 0:35a2186cf186 | 775 | } |
MACRUM | 0:35a2186cf186 | 776 | |
MACRUM | 0:35a2186cf186 | 777 | if( uartCmdMgr_p->getCommandStatus() != UART_CMD_RES_SNIC_SUCCESS ) |
MACRUM | 0:35a2186cf186 | 778 | { |
MACRUM | 0:35a2186cf186 | 779 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 780 | snic_core_p->unlockAPI(); |
MACRUM | 0:35a2186cf186 | 781 | return 0; |
MACRUM | 0:35a2186cf186 | 782 | } |
MACRUM | 0:35a2186cf186 | 783 | |
MACRUM | 0:35a2186cf186 | 784 | sprintf(ip_addr, "%d.%d.%d.%d\0", payload_buf_p->buf[9], payload_buf_p->buf[10], payload_buf_p->buf[11], payload_buf_p->buf[12]); |
MACRUM | 0:35a2186cf186 | 785 | |
MACRUM | 0:35a2186cf186 | 786 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 787 | snic_core_p->unlockAPI(); |
MACRUM | 0:35a2186cf186 | 788 | |
MACRUM | 0:35a2186cf186 | 789 | return ip_addr; |
MACRUM | 0:35a2186cf186 | 790 | } |
MACRUM | 0:35a2186cf186 | 791 | |
MACRUM | 0:35a2186cf186 | 792 | char* C_SNIC_WifiInterface::getSubnetAddress() { |
MACRUM | 0:35a2186cf186 | 793 | C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance(); |
MACRUM | 0:35a2186cf186 | 794 | C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand(); |
MACRUM | 0:35a2186cf186 | 795 | |
MACRUM | 0:35a2186cf186 | 796 | snic_core_p->lockAPI(); |
MACRUM | 0:35a2186cf186 | 797 | // Get local ip address. |
MACRUM | 0:35a2186cf186 | 798 | // Get buffer for response payload from MemoryPool |
MACRUM | 0:35a2186cf186 | 799 | tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf(); |
MACRUM | 0:35a2186cf186 | 800 | if( payload_buf_p == NULL ) |
MACRUM | 0:35a2186cf186 | 801 | { |
MACRUM | 0:35a2186cf186 | 802 | DEBUG_PRINT("getIPAddress payload_buf_p NULL\r\n"); |
MACRUM | 0:35a2186cf186 | 803 | snic_core_p->unlockAPI(); |
MACRUM | 0:35a2186cf186 | 804 | return 0; |
MACRUM | 0:35a2186cf186 | 805 | } |
MACRUM | 0:35a2186cf186 | 806 | |
MACRUM | 0:35a2186cf186 | 807 | C_SNIC_Core::tagSNIC_GET_DHCP_INFO_REQ_T req; |
MACRUM | 0:35a2186cf186 | 808 | // Make request |
MACRUM | 0:35a2186cf186 | 809 | req.cmd_sid = UART_CMD_SID_SNIC_GET_DHCP_INFO_REQ; |
MACRUM | 0:35a2186cf186 | 810 | req.seq = mUartRequestSeq++; |
MACRUM | 0:35a2186cf186 | 811 | req.interface = 0; |
MACRUM | 0:35a2186cf186 | 812 | |
MACRUM | 0:35a2186cf186 | 813 | unsigned char *command_array_p = snic_core_p->getCommandBuf(); |
MACRUM | 0:35a2186cf186 | 814 | unsigned int command_len; |
MACRUM | 0:35a2186cf186 | 815 | // Preparation of command |
MACRUM | 0:35a2186cf186 | 816 | command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req |
MACRUM | 0:35a2186cf186 | 817 | , sizeof(C_SNIC_Core::tagSNIC_GET_DHCP_INFO_REQ_T), payload_buf_p->buf, command_array_p ); |
MACRUM | 0:35a2186cf186 | 818 | // Send uart command request |
MACRUM | 0:35a2186cf186 | 819 | snic_core_p->sendUart( command_len, command_array_p ); |
MACRUM | 0:35a2186cf186 | 820 | // Wait UART response |
MACRUM | 0:35a2186cf186 | 821 | int ret = uartCmdMgr_p->wait(); |
MACRUM | 0:35a2186cf186 | 822 | if( ret != 0 ) |
MACRUM | 0:35a2186cf186 | 823 | { |
MACRUM | 0:35a2186cf186 | 824 | DEBUG_PRINT( "getIPAddress failed\r\n" ); |
MACRUM | 0:35a2186cf186 | 825 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 826 | snic_core_p->unlockAPI(); |
MACRUM | 0:35a2186cf186 | 827 | return 0; |
MACRUM | 0:35a2186cf186 | 828 | } |
MACRUM | 0:35a2186cf186 | 829 | |
MACRUM | 0:35a2186cf186 | 830 | if( uartCmdMgr_p->getCommandStatus() != UART_CMD_RES_SNIC_SUCCESS ) |
MACRUM | 0:35a2186cf186 | 831 | { |
MACRUM | 0:35a2186cf186 | 832 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 833 | snic_core_p->unlockAPI(); |
MACRUM | 0:35a2186cf186 | 834 | return 0; |
MACRUM | 0:35a2186cf186 | 835 | } |
MACRUM | 0:35a2186cf186 | 836 | |
MACRUM | 0:35a2186cf186 | 837 | sprintf(subnet_addr, "%d.%d.%d.%d\0", payload_buf_p->buf[17], payload_buf_p->buf[18], payload_buf_p->buf[19], payload_buf_p->buf[20]); |
MACRUM | 0:35a2186cf186 | 838 | |
MACRUM | 0:35a2186cf186 | 839 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 840 | snic_core_p->unlockAPI(); |
MACRUM | 0:35a2186cf186 | 841 | |
MACRUM | 0:35a2186cf186 | 842 | return subnet_addr; |
MACRUM | 0:35a2186cf186 | 843 | } |
MACRUM | 0:35a2186cf186 | 844 | |
MACRUM | 0:35a2186cf186 | 845 | char* C_SNIC_WifiInterface::getGatewayAddress() { |
MACRUM | 0:35a2186cf186 | 846 | C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance(); |
MACRUM | 0:35a2186cf186 | 847 | C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand(); |
MACRUM | 0:35a2186cf186 | 848 | |
MACRUM | 0:35a2186cf186 | 849 | snic_core_p->lockAPI(); |
MACRUM | 0:35a2186cf186 | 850 | // Get local ip address. |
MACRUM | 0:35a2186cf186 | 851 | // Get buffer for response payload from MemoryPool |
MACRUM | 0:35a2186cf186 | 852 | tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf(); |
MACRUM | 0:35a2186cf186 | 853 | if( payload_buf_p == NULL ) |
MACRUM | 0:35a2186cf186 | 854 | { |
MACRUM | 0:35a2186cf186 | 855 | DEBUG_PRINT("getIPAddress payload_buf_p NULL\r\n"); |
MACRUM | 0:35a2186cf186 | 856 | snic_core_p->unlockAPI(); |
MACRUM | 0:35a2186cf186 | 857 | return 0; |
MACRUM | 0:35a2186cf186 | 858 | } |
MACRUM | 0:35a2186cf186 | 859 | |
MACRUM | 0:35a2186cf186 | 860 | C_SNIC_Core::tagSNIC_GET_DHCP_INFO_REQ_T req; |
MACRUM | 0:35a2186cf186 | 861 | // Make request |
MACRUM | 0:35a2186cf186 | 862 | req.cmd_sid = UART_CMD_SID_SNIC_GET_DHCP_INFO_REQ; |
MACRUM | 0:35a2186cf186 | 863 | req.seq = mUartRequestSeq++; |
MACRUM | 0:35a2186cf186 | 864 | req.interface = 0; |
MACRUM | 0:35a2186cf186 | 865 | |
MACRUM | 0:35a2186cf186 | 866 | unsigned char *command_array_p = snic_core_p->getCommandBuf(); |
MACRUM | 0:35a2186cf186 | 867 | unsigned int command_len; |
MACRUM | 0:35a2186cf186 | 868 | // Preparation of command |
MACRUM | 0:35a2186cf186 | 869 | command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req |
MACRUM | 0:35a2186cf186 | 870 | , sizeof(C_SNIC_Core::tagSNIC_GET_DHCP_INFO_REQ_T), payload_buf_p->buf, command_array_p ); |
MACRUM | 0:35a2186cf186 | 871 | // Send uart command request |
MACRUM | 0:35a2186cf186 | 872 | snic_core_p->sendUart( command_len, command_array_p ); |
MACRUM | 0:35a2186cf186 | 873 | // Wait UART response |
MACRUM | 0:35a2186cf186 | 874 | int ret = uartCmdMgr_p->wait(); |
MACRUM | 0:35a2186cf186 | 875 | if( ret != 0 ) |
MACRUM | 0:35a2186cf186 | 876 | { |
MACRUM | 0:35a2186cf186 | 877 | DEBUG_PRINT( "getIPAddress failed\r\n" ); |
MACRUM | 0:35a2186cf186 | 878 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 879 | snic_core_p->unlockAPI(); |
MACRUM | 0:35a2186cf186 | 880 | return 0; |
MACRUM | 0:35a2186cf186 | 881 | } |
MACRUM | 0:35a2186cf186 | 882 | |
MACRUM | 0:35a2186cf186 | 883 | if( uartCmdMgr_p->getCommandStatus() != UART_CMD_RES_SNIC_SUCCESS ) |
MACRUM | 0:35a2186cf186 | 884 | { |
MACRUM | 0:35a2186cf186 | 885 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 886 | snic_core_p->unlockAPI(); |
MACRUM | 0:35a2186cf186 | 887 | return 0; |
MACRUM | 0:35a2186cf186 | 888 | } |
MACRUM | 0:35a2186cf186 | 889 | |
MACRUM | 0:35a2186cf186 | 890 | sprintf(gateway_addr, "%d.%d.%d.%d\0", payload_buf_p->buf[13], payload_buf_p->buf[14], payload_buf_p->buf[15], payload_buf_p->buf[16]); |
MACRUM | 0:35a2186cf186 | 891 | |
MACRUM | 0:35a2186cf186 | 892 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 893 | snic_core_p->unlockAPI(); |
MACRUM | 0:35a2186cf186 | 894 | |
MACRUM | 0:35a2186cf186 | 895 | return gateway_addr; |
MACRUM | 0:35a2186cf186 | 896 | } |
MACRUM | 0:35a2186cf186 | 897 | |
MACRUM | 0:35a2186cf186 | 898 | int C_SNIC_WifiInterface::resolveName(const char *name, unsigned char *ipaddr) |
MACRUM | 0:35a2186cf186 | 899 | { |
MACRUM | 0:35a2186cf186 | 900 | int name_length; |
MACRUM | 0:35a2186cf186 | 901 | |
MACRUM | 0:35a2186cf186 | 902 | // Parameter check |
MACRUM | 0:35a2186cf186 | 903 | if( (name == NULL) || (ipaddr == NULL) || |
MACRUM | 0:35a2186cf186 | 904 | ((name_length = strlen(name)) > 100)) |
MACRUM | 0:35a2186cf186 | 905 | { |
MACRUM | 0:35a2186cf186 | 906 | DEBUG_PRINT("resolveName parameter error\r\n"); |
MACRUM | 0:35a2186cf186 | 907 | return -1; |
MACRUM | 0:35a2186cf186 | 908 | } |
MACRUM | 0:35a2186cf186 | 909 | |
MACRUM | 0:35a2186cf186 | 910 | C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance(); |
MACRUM | 0:35a2186cf186 | 911 | C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand(); |
MACRUM | 0:35a2186cf186 | 912 | |
MACRUM | 0:35a2186cf186 | 913 | // Get buffer for response payload from MemoryPool |
MACRUM | 0:35a2186cf186 | 914 | tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf(); |
MACRUM | 0:35a2186cf186 | 915 | if( payload_buf_p == NULL ) |
MACRUM | 0:35a2186cf186 | 916 | { |
MACRUM | 0:35a2186cf186 | 917 | DEBUG_PRINT("resolveName payload_buf_p NULL\r\n"); |
MACRUM | 0:35a2186cf186 | 918 | return -1; |
MACRUM | 0:35a2186cf186 | 919 | } |
MACRUM | 0:35a2186cf186 | 920 | |
MACRUM | 0:35a2186cf186 | 921 | unsigned char *command_array_p = snic_core_p->getCommandBuf(); |
MACRUM | 0:35a2186cf186 | 922 | unsigned int command_len; |
MACRUM | 0:35a2186cf186 | 923 | |
MACRUM | 0:35a2186cf186 | 924 | C_SNIC_Core::tagSNIC_RESOLVE_NAME_REQ_T req; |
MACRUM | 0:35a2186cf186 | 925 | // Make request |
MACRUM | 0:35a2186cf186 | 926 | req.cmd_sid = UART_CMD_SID_SNIC_RESOLVE_NAME_REQ; |
MACRUM | 0:35a2186cf186 | 927 | req.seq = mUartRequestSeq++; |
MACRUM | 0:35a2186cf186 | 928 | req.interface = 0; |
MACRUM | 0:35a2186cf186 | 929 | req.name_length = name_length; |
MACRUM | 0:35a2186cf186 | 930 | strcpy((char*)req.name, name); |
MACRUM | 0:35a2186cf186 | 931 | |
MACRUM | 0:35a2186cf186 | 932 | // Preparation of command |
MACRUM | 0:35a2186cf186 | 933 | command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req |
MACRUM | 0:35a2186cf186 | 934 | , sizeof(C_SNIC_Core::tagSNIC_RESOLVE_NAME_REQ_T) - sizeof(req.name) + name_length + 1, payload_buf_p->buf, command_array_p ); |
MACRUM | 0:35a2186cf186 | 935 | |
MACRUM | 0:35a2186cf186 | 936 | // Send uart command request |
MACRUM | 0:35a2186cf186 | 937 | snic_core_p->sendUart( command_len, command_array_p ); |
MACRUM | 0:35a2186cf186 | 938 | |
MACRUM | 0:35a2186cf186 | 939 | int ret; |
MACRUM | 0:35a2186cf186 | 940 | // Wait UART response |
MACRUM | 0:35a2186cf186 | 941 | ret = uartCmdMgr_p->wait(); |
MACRUM | 0:35a2186cf186 | 942 | if( ret != 0 ) |
MACRUM | 0:35a2186cf186 | 943 | { |
MACRUM | 0:35a2186cf186 | 944 | DEBUG_PRINT( "resolveName failed\r\n" ); |
MACRUM | 0:35a2186cf186 | 945 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 946 | return -1; |
MACRUM | 0:35a2186cf186 | 947 | } |
MACRUM | 0:35a2186cf186 | 948 | |
MACRUM | 0:35a2186cf186 | 949 | if( uartCmdMgr_p->getCommandStatus() != 0 ) |
MACRUM | 0:35a2186cf186 | 950 | { |
MACRUM | 0:35a2186cf186 | 951 | DEBUG_PRINT("resolveName status:%02x\r\n", uartCmdMgr_p->getCommandStatus()); |
MACRUM | 0:35a2186cf186 | 952 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 953 | return -1; |
MACRUM | 0:35a2186cf186 | 954 | } |
MACRUM | 0:35a2186cf186 | 955 | |
MACRUM | 0:35a2186cf186 | 956 | ipaddr[0] = payload_buf_p->buf[3]; |
MACRUM | 0:35a2186cf186 | 957 | ipaddr[1] = payload_buf_p->buf[4]; |
MACRUM | 0:35a2186cf186 | 958 | ipaddr[2] = payload_buf_p->buf[5]; |
MACRUM | 0:35a2186cf186 | 959 | ipaddr[3] = payload_buf_p->buf[6]; |
MACRUM | 0:35a2186cf186 | 960 | |
MACRUM | 0:35a2186cf186 | 961 | snic_core_p->freeCmdBuf( payload_buf_p ); |
MACRUM | 0:35a2186cf186 | 962 | return ret; |
MACRUM | 0:35a2186cf186 | 963 | } |
MACRUM | 0:35a2186cf186 | 964 | |
MACRUM | 0:35a2186cf186 | 965 |