Customized

Dependents:   MurataTypeYD_RPC_Sample

Fork of SNICInterface_mod by Toyomasa Watarai

Committer:
MACRUM
Date:
Fri Jan 23 09:56:01 2015 +0000
Revision:
47:62ba69ff80d2
Parent:
43:d80bbb12ffe6
Added getIPAddress() function

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kishino 39:a1233ca02edf 1 /* Copyright (C) 2014 Murata Manufacturing Co.,Ltd., MIT License
kishino 39:a1233ca02edf 2 * muRata, SWITCH SCIENCE Wi-FI module TypeYD-SNIC UART.
kishino 14:54378c96d285 3 *
kishino 39:a1233ca02edf 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
kishino 39:a1233ca02edf 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
kishino 39:a1233ca02edf 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
kishino 39:a1233ca02edf 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
kishino 39:a1233ca02edf 8 * furnished to do so, subject to the following conditions:
kishino 14:54378c96d285 9 *
kishino 39:a1233ca02edf 10 * The above copyright notice and this permission notice shall be included in all copies or
kishino 39:a1233ca02edf 11 * substantial portions of the Software.
kishino 14:54378c96d285 12 *
kishino 39:a1233ca02edf 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
kishino 39:a1233ca02edf 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
kishino 39:a1233ca02edf 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
kishino 39:a1233ca02edf 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
kishino 39:a1233ca02edf 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
kishino 39:a1233ca02edf 18 */
kishino 12:0254eaccfda2 19 #include "SNIC_WifiInterface.h"
kishino 12:0254eaccfda2 20 #include "SNIC_UartMsgUtil.h"
kishino 12:0254eaccfda2 21
kishino 36:f33fcf5975ab 22 #define UART_CONNECT_BUF_SIZE 512
kishino 36:f33fcf5975ab 23 unsigned char gCONNECT_BUF[UART_CONNECT_BUF_SIZE];
MACRUM 47:62ba69ff80d2 24 static char ip_addr[17] = "\0";
kishino 12:0254eaccfda2 25
kishino 12:0254eaccfda2 26 C_SNIC_WifiInterface::C_SNIC_WifiInterface( PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm, int baud)
kishino 12:0254eaccfda2 27 {
kishino 12:0254eaccfda2 28 mUART_tx = tx;
kishino 12:0254eaccfda2 29 mUART_rx = rx;
kishino 12:0254eaccfda2 30 mUART_cts = cts;
kishino 12:0254eaccfda2 31 mUART_rts = rts;;
kishino 12:0254eaccfda2 32 mUART_baud = baud;
kishino 12:0254eaccfda2 33 mModuleReset = reset;
kishino 12:0254eaccfda2 34 }
kishino 12:0254eaccfda2 35
kishino 26:f2e1030964e4 36 C_SNIC_WifiInterface::~C_SNIC_WifiInterface()
kishino 26:f2e1030964e4 37 {
kishino 26:f2e1030964e4 38 }
kishino 26:f2e1030964e4 39
kishino 12:0254eaccfda2 40 int C_SNIC_WifiInterface::init()
kishino 24:987e412ae879 41 {
kishino 24:987e412ae879 42 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
kishino 24:987e412ae879 43 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
kishino 16:6100acfeb1f1 44
kishino 37:f3a2053627c2 45 /* Initialize UART */
kishino 37:f3a2053627c2 46 snic_core_p->initUart( mUART_tx, mUART_rx, mUART_baud );
kishino 37:f3a2053627c2 47
kishino 29:6a0ba999597d 48 /* Module reset */
kishino 29:6a0ba999597d 49 snic_core_p->resetModule( mModuleReset );
kishino 29:6a0ba999597d 50
kishino 37:f3a2053627c2 51 wait(1);
kishino 12:0254eaccfda2 52 /* Initialize SNIC API */
kishino 12:0254eaccfda2 53 // Get buffer for response payload from MemoryPool
kishino 38:f13e4e563d65 54 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
kishino 38:f13e4e563d65 55 if( payload_buf_p == NULL )
kishino 12:0254eaccfda2 56 {
kishino 40:b6b10c22a121 57 DEBUG_PRINT("snic_init payload_buf_p NULL\r\n");
kishino 12:0254eaccfda2 58 return -1;
kishino 12:0254eaccfda2 59 }
kishino 12:0254eaccfda2 60
kishino 22:a9ec0cad4f84 61 C_SNIC_Core::tagSNIC_INIT_REQ_T req;
kishino 12:0254eaccfda2 62 // Make request
kishino 12:0254eaccfda2 63 req.cmd_sid = UART_CMD_SID_SNIC_INIT_REQ;
kishino 12:0254eaccfda2 64 req.seq = mUartRequestSeq++;
kishino 28:b796031f6519 65 req.buf_size[0] = 0x08;
kishino 28:b796031f6519 66 req.buf_size[1] = 0x00;
kishino 12:0254eaccfda2 67
kishino 38:f13e4e563d65 68 unsigned char *command_array_p = snic_core_p->getCommandBuf();
kishino 12:0254eaccfda2 69 unsigned int command_len;
kishino 12:0254eaccfda2 70 // Preparation of command
kishino 24:987e412ae879 71 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req
kishino 38:f13e4e563d65 72 , sizeof(C_SNIC_Core::tagSNIC_INIT_REQ_T), payload_buf_p->buf, command_array_p );
kishino 12:0254eaccfda2 73
kishino 12:0254eaccfda2 74 // Send uart command request
kishino 38:f13e4e563d65 75 snic_core_p->sendUart( command_len, command_array_p );
kishino 12:0254eaccfda2 76
kishino 12:0254eaccfda2 77 int ret;
kishino 12:0254eaccfda2 78 // Wait UART response
kishino 16:6100acfeb1f1 79 ret = uartCmdMgr_p->wait();
kishino 12:0254eaccfda2 80 if( ret != 0 )
kishino 12:0254eaccfda2 81 {
kishino 40:b6b10c22a121 82 DEBUG_PRINT( "snic_init failed\r\n" );
kishino 38:f13e4e563d65 83 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 84 return -1;
kishino 12:0254eaccfda2 85 }
kishino 12:0254eaccfda2 86
kishino 16:6100acfeb1f1 87 if( uartCmdMgr_p->getCommandStatus() != 0 )
kishino 12:0254eaccfda2 88 {
kishino 40:b6b10c22a121 89 DEBUG_PRINT("snic_init status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
kishino 39:a1233ca02edf 90 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 39:a1233ca02edf 91 return -1;
kishino 12:0254eaccfda2 92 }
kishino 38:f13e4e563d65 93 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 94
kishino 12:0254eaccfda2 95 return ret;
kishino 12:0254eaccfda2 96 }
kishino 12:0254eaccfda2 97
kishino 12:0254eaccfda2 98 int C_SNIC_WifiInterface::getFWVersion( unsigned char *version_p )
kishino 12:0254eaccfda2 99 {
kishino 24:987e412ae879 100 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
kishino 24:987e412ae879 101 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
kishino 16:6100acfeb1f1 102
kishino 12:0254eaccfda2 103 // Get buffer for response payload from MemoryPool
kishino 38:f13e4e563d65 104 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
kishino 38:f13e4e563d65 105 if( payload_buf_p == NULL )
kishino 12:0254eaccfda2 106 {
kishino 40:b6b10c22a121 107 DEBUG_PRINT("getFWVersion payload_buf_p NULL\r\n");
kishino 12:0254eaccfda2 108 return -1;
kishino 12:0254eaccfda2 109 }
kishino 12:0254eaccfda2 110
kishino 22:a9ec0cad4f84 111 C_SNIC_Core::tagGEN_FW_VER_GET_REQ_T req;
kishino 12:0254eaccfda2 112 // Make request
kishino 12:0254eaccfda2 113 req.cmd_sid = UART_CMD_SID_GEN_FW_VER_GET_REQ;
kishino 12:0254eaccfda2 114 req.seq = mUartRequestSeq++;
kishino 12:0254eaccfda2 115
kishino 38:f13e4e563d65 116 unsigned char *command_array_p = snic_core_p->getCommandBuf();
kishino 12:0254eaccfda2 117 unsigned int command_len;
kishino 12:0254eaccfda2 118 // Preparation of command
kishino 24:987e412ae879 119 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_GEN, req.cmd_sid, (unsigned char *)&req
kishino 38:f13e4e563d65 120 , sizeof(C_SNIC_Core::tagGEN_FW_VER_GET_REQ_T), payload_buf_p->buf, command_array_p );
kishino 12:0254eaccfda2 121
kishino 12:0254eaccfda2 122 int ret;
kishino 12:0254eaccfda2 123
kishino 12:0254eaccfda2 124 // Send uart command request
kishino 38:f13e4e563d65 125 snic_core_p->sendUart( command_len, command_array_p );
kishino 12:0254eaccfda2 126
kishino 12:0254eaccfda2 127 // Wait UART response
kishino 16:6100acfeb1f1 128 ret = uartCmdMgr_p->wait();
kishino 12:0254eaccfda2 129 if( ret != 0 )
kishino 12:0254eaccfda2 130 {
kishino 40:b6b10c22a121 131 DEBUG_PRINT( "getFWversion failed\r\n" );
kishino 38:f13e4e563d65 132 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 133 return -1;
kishino 12:0254eaccfda2 134 }
kishino 12:0254eaccfda2 135
kishino 16:6100acfeb1f1 136 if( uartCmdMgr_p->getCommandStatus() == 0 )
kishino 12:0254eaccfda2 137 {
kishino 38:f13e4e563d65 138 unsigned char version_len = payload_buf_p->buf[3];
kishino 38:f13e4e563d65 139 memcpy( version_p, &payload_buf_p->buf[4], version_len );
kishino 12:0254eaccfda2 140 }
kishino 38:f13e4e563d65 141 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 142 return 0;
kishino 12:0254eaccfda2 143 }
kishino 12:0254eaccfda2 144
kishino 12:0254eaccfda2 145 int C_SNIC_WifiInterface::connect(const char *ssid_p, unsigned char ssid_len, E_SECURITY sec_type
kishino 12:0254eaccfda2 146 , const char *sec_key_p, unsigned char sec_key_len)
kishino 12:0254eaccfda2 147 {
kishino 24:987e412ae879 148 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
kishino 24:987e412ae879 149 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
kishino 16:6100acfeb1f1 150
kishino 12:0254eaccfda2 151 // Parameter check(SSID)
kishino 12:0254eaccfda2 152 if( (ssid_p == NULL) || (ssid_len == 0) )
kishino 12:0254eaccfda2 153 {
kishino 40:b6b10c22a121 154 DEBUG_PRINT( "connect failed [ parameter NG:SSID ]\r\n" );
kishino 12:0254eaccfda2 155 return -1;
kishino 12:0254eaccfda2 156 }
kishino 12:0254eaccfda2 157
kishino 12:0254eaccfda2 158 // Parameter check(Security key)
kishino 12:0254eaccfda2 159 if( (sec_type != e_SEC_OPEN) && ( (sec_key_len == 0) || (sec_key_p == NULL) ) )
kishino 12:0254eaccfda2 160 {
kishino 40:b6b10c22a121 161 DEBUG_PRINT( "connect failed [ parameter NG:Security key ]\r\n" );
kishino 12:0254eaccfda2 162 return -1;
kishino 12:0254eaccfda2 163 }
kishino 12:0254eaccfda2 164
kishino 12:0254eaccfda2 165 // Get buffer for response payload from MemoryPool
kishino 38:f13e4e563d65 166 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
kishino 38:f13e4e563d65 167 if( payload_buf_p == NULL )
kishino 12:0254eaccfda2 168 {
kishino 40:b6b10c22a121 169 DEBUG_PRINT("connect payload_buf_p NULL\r\n");
kishino 12:0254eaccfda2 170 return -1;
kishino 12:0254eaccfda2 171 }
kishino 12:0254eaccfda2 172
kishino 29:6a0ba999597d 173 unsigned char *buf = &gCONNECT_BUF[0];
kishino 12:0254eaccfda2 174 unsigned int buf_len = 0;
kishino 12:0254eaccfda2 175 unsigned int command_len;
kishino 12:0254eaccfda2 176
kishino 36:f33fcf5975ab 177 memset( buf, 0, UART_CONNECT_BUF_SIZE );
kishino 12:0254eaccfda2 178 // Make request
kishino 12:0254eaccfda2 179 buf[0] = UART_CMD_SID_WIFI_JOIN_REQ;
kishino 12:0254eaccfda2 180 buf_len++;
kishino 12:0254eaccfda2 181 buf[1] = mUartRequestSeq++;
kishino 12:0254eaccfda2 182 buf_len++;
kishino 12:0254eaccfda2 183 // SSID
kishino 12:0254eaccfda2 184 memcpy( &buf[2], ssid_p, ssid_len );
kishino 12:0254eaccfda2 185 buf_len += ssid_len;
kishino 12:0254eaccfda2 186 buf_len++;
kishino 12:0254eaccfda2 187
kishino 12:0254eaccfda2 188 // Security mode
kishino 12:0254eaccfda2 189 buf[ buf_len ] = (unsigned char)sec_type;
kishino 12:0254eaccfda2 190 buf_len++;
kishino 12:0254eaccfda2 191
kishino 12:0254eaccfda2 192 // Security key
kishino 12:0254eaccfda2 193 if( sec_type != e_SEC_OPEN )
kishino 12:0254eaccfda2 194 {
kishino 12:0254eaccfda2 195 buf[ buf_len ] = sec_key_len;
kishino 12:0254eaccfda2 196 buf_len++;
kishino 12:0254eaccfda2 197 if( sec_key_len > 0 )
kishino 12:0254eaccfda2 198 {
kishino 12:0254eaccfda2 199 memcpy( &buf[buf_len], sec_key_p, sec_key_len );
kishino 12:0254eaccfda2 200 buf_len += sec_key_len;
kishino 12:0254eaccfda2 201 }
kishino 12:0254eaccfda2 202 }
kishino 12:0254eaccfda2 203
kishino 38:f13e4e563d65 204 unsigned char *command_array_p = snic_core_p->getCommandBuf();
kishino 12:0254eaccfda2 205 // Preparation of command
kishino 24:987e412ae879 206 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, UART_CMD_SID_WIFI_JOIN_REQ, buf
kishino 38:f13e4e563d65 207 , buf_len, payload_buf_p->buf, command_array_p );
kishino 12:0254eaccfda2 208
kishino 12:0254eaccfda2 209 // Send uart command request
kishino 38:f13e4e563d65 210 snic_core_p->sendUart( command_len, command_array_p );
kishino 12:0254eaccfda2 211
kishino 12:0254eaccfda2 212 int ret;
kishino 12:0254eaccfda2 213 // Wait UART response
kishino 16:6100acfeb1f1 214 ret = uartCmdMgr_p->wait();
kishino 43:d80bbb12ffe6 215 if(uartCmdMgr_p->getCommandStatus() != UART_CMD_RES_WIFI_ERR_ALREADY_JOINED)
kishino 43:d80bbb12ffe6 216 {
kishino 43:d80bbb12ffe6 217 DEBUG_PRINT( "Already connected\r\n" );
kishino 43:d80bbb12ffe6 218 }
kishino 43:d80bbb12ffe6 219 else
kishino 12:0254eaccfda2 220 {
kishino 43:d80bbb12ffe6 221 if( ret != 0 )
kishino 43:d80bbb12ffe6 222 {
kishino 43:d80bbb12ffe6 223 DEBUG_PRINT( "join failed\r\n" );
kishino 43:d80bbb12ffe6 224 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 43:d80bbb12ffe6 225 return -1;
kishino 43:d80bbb12ffe6 226 }
kishino 12:0254eaccfda2 227 }
kishino 12:0254eaccfda2 228
kishino 43:d80bbb12ffe6 229 if(uartCmdMgr_p->getCommandStatus() != 0)
kishino 12:0254eaccfda2 230 {
kishino 40:b6b10c22a121 231 DEBUG_PRINT("join status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
kishino 39:a1233ca02edf 232 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 39:a1233ca02edf 233 return -1;
kishino 12:0254eaccfda2 234 }
kishino 38:f13e4e563d65 235 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 236
kishino 12:0254eaccfda2 237 return ret;
kishino 12:0254eaccfda2 238 }
kishino 12:0254eaccfda2 239
kishino 12:0254eaccfda2 240 int C_SNIC_WifiInterface::disconnect()
kishino 12:0254eaccfda2 241 {
kishino 24:987e412ae879 242 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
kishino 24:987e412ae879 243 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
kishino 16:6100acfeb1f1 244
kishino 12:0254eaccfda2 245 // Get buffer for response payload from MemoryPool
kishino 38:f13e4e563d65 246 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
kishino 38:f13e4e563d65 247 if( payload_buf_p == NULL )
kishino 12:0254eaccfda2 248 {
kishino 40:b6b10c22a121 249 DEBUG_PRINT("disconnect payload_buf_p NULL\r\n");
kishino 12:0254eaccfda2 250 return -1;
kishino 12:0254eaccfda2 251 }
kishino 12:0254eaccfda2 252
kishino 22:a9ec0cad4f84 253 C_SNIC_Core::tagWIFI_DISCONNECT_REQ_T req;
kishino 12:0254eaccfda2 254 // Make request
kishino 12:0254eaccfda2 255 req.cmd_sid = UART_CMD_SID_WIFI_DISCONNECT_REQ;
kishino 12:0254eaccfda2 256 req.seq = mUartRequestSeq++;
kishino 12:0254eaccfda2 257
kishino 38:f13e4e563d65 258 unsigned char *command_array_p = snic_core_p->getCommandBuf();
kishino 12:0254eaccfda2 259 unsigned int command_len;
kishino 12:0254eaccfda2 260 // Preparation of command
kishino 24:987e412ae879 261 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req
kishino 38:f13e4e563d65 262 , sizeof(C_SNIC_Core::tagWIFI_DISCONNECT_REQ_T), payload_buf_p->buf, command_array_p );
kishino 12:0254eaccfda2 263
kishino 12:0254eaccfda2 264 // Send uart command request
kishino 38:f13e4e563d65 265 snic_core_p->sendUart( command_len, command_array_p );
kishino 12:0254eaccfda2 266
kishino 12:0254eaccfda2 267 int ret;
kishino 12:0254eaccfda2 268 // Wait UART response
kishino 16:6100acfeb1f1 269 ret = uartCmdMgr_p->wait();
kishino 12:0254eaccfda2 270 if( ret != 0 )
kishino 12:0254eaccfda2 271 {
kishino 40:b6b10c22a121 272 DEBUG_PRINT( "disconnect failed\r\n" );
kishino 38:f13e4e563d65 273 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 274 return -1;
kishino 12:0254eaccfda2 275 }
kishino 12:0254eaccfda2 276
kishino 16:6100acfeb1f1 277 if( uartCmdMgr_p->getCommandStatus() != 0 )
kishino 12:0254eaccfda2 278 {
kishino 40:b6b10c22a121 279 DEBUG_PRINT("disconnect status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
kishino 12:0254eaccfda2 280 ret = -1;
kishino 12:0254eaccfda2 281 }
kishino 38:f13e4e563d65 282 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 283 return ret;
kishino 12:0254eaccfda2 284 }
kishino 12:0254eaccfda2 285
kishino 12:0254eaccfda2 286 int C_SNIC_WifiInterface::scan( const char *ssid_p, unsigned char *bssid_p
kishino 12:0254eaccfda2 287 , void (*result_handler_p)(tagSCAN_RESULT_T *scan_result) )
kishino 12:0254eaccfda2 288 {
kishino 24:987e412ae879 289 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
kishino 24:987e412ae879 290 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
kishino 16:6100acfeb1f1 291
kishino 12:0254eaccfda2 292 // Get buffer for response payload from MemoryPool
kishino 38:f13e4e563d65 293 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
kishino 38:f13e4e563d65 294 if( payload_buf_p == NULL )
kishino 12:0254eaccfda2 295 {
kishino 40:b6b10c22a121 296 DEBUG_PRINT("scan payload_buf_p NULL\r\n");
kishino 12:0254eaccfda2 297 return -1;
kishino 12:0254eaccfda2 298 }
kishino 12:0254eaccfda2 299
kishino 22:a9ec0cad4f84 300 C_SNIC_Core::tagWIFI_SCAN_REQ_T req;
kishino 12:0254eaccfda2 301 unsigned int buf_len = 0;
kishino 12:0254eaccfda2 302
kishino 22:a9ec0cad4f84 303 memset( &req, 0, sizeof(C_SNIC_Core::tagWIFI_SCAN_REQ_T) );
kishino 12:0254eaccfda2 304 // Make request
kishino 12:0254eaccfda2 305 req.cmd_sid = UART_CMD_SID_WIFI_SCAN_REQ;
kishino 12:0254eaccfda2 306 buf_len++;
kishino 12:0254eaccfda2 307 req.seq = mUartRequestSeq++;
kishino 12:0254eaccfda2 308 buf_len++;
kishino 12:0254eaccfda2 309
kishino 12:0254eaccfda2 310 // Set scan type(Active scan)
kishino 12:0254eaccfda2 311 req.scan_type = 0;
kishino 12:0254eaccfda2 312 buf_len++;
kishino 12:0254eaccfda2 313 // Set bss type(any)
kishino 12:0254eaccfda2 314 req.bss_type = 2;
kishino 12:0254eaccfda2 315 buf_len++;
kishino 12:0254eaccfda2 316 // Set BSSID
kishino 12:0254eaccfda2 317 if( bssid_p != NULL )
kishino 12:0254eaccfda2 318 {
kishino 12:0254eaccfda2 319 memcpy( req.bssid, bssid_p, BSSID_MAC_LENTH );
kishino 12:0254eaccfda2 320 }
kishino 12:0254eaccfda2 321 buf_len += BSSID_MAC_LENTH;
kishino 12:0254eaccfda2 322 // Set channel list(0)
kishino 12:0254eaccfda2 323 req.chan_list = 0;
kishino 12:0254eaccfda2 324 buf_len++;
kishino 12:0254eaccfda2 325 //Set SSID
kishino 12:0254eaccfda2 326 if( ssid_p != NULL )
kishino 12:0254eaccfda2 327 {
kishino 12:0254eaccfda2 328 strcpy( (char *)req.ssid, ssid_p );
kishino 12:0254eaccfda2 329 buf_len += strlen(ssid_p);
kishino 12:0254eaccfda2 330 }
kishino 12:0254eaccfda2 331 buf_len++;
kishino 12:0254eaccfda2 332
kishino 38:f13e4e563d65 333 unsigned char *command_array_p = snic_core_p->getCommandBuf();
kishino 12:0254eaccfda2 334 unsigned int command_len;
kishino 12:0254eaccfda2 335 // Preparation of command
kishino 24:987e412ae879 336 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req
kishino 38:f13e4e563d65 337 , buf_len, payload_buf_p->buf, command_array_p );
kishino 12:0254eaccfda2 338
kishino 12:0254eaccfda2 339 // Set scan result callback
kishino 16:6100acfeb1f1 340 uartCmdMgr_p->setScanResultHandler( result_handler_p );
kishino 12:0254eaccfda2 341
kishino 12:0254eaccfda2 342 // Send uart command request
kishino 38:f13e4e563d65 343 snic_core_p->sendUart( command_len, command_array_p );
kishino 12:0254eaccfda2 344
kishino 12:0254eaccfda2 345 int ret;
kishino 12:0254eaccfda2 346 // Wait UART response
kishino 16:6100acfeb1f1 347 ret = uartCmdMgr_p->wait();
kishino 40:b6b10c22a121 348 DEBUG_PRINT( "scan wait:%d\r\n", ret );
kishino 12:0254eaccfda2 349 if( ret != 0 )
kishino 12:0254eaccfda2 350 {
kishino 40:b6b10c22a121 351 DEBUG_PRINT( "scan failed\r\n" );
kishino 38:f13e4e563d65 352 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 353 return -1;
kishino 12:0254eaccfda2 354 }
kishino 12:0254eaccfda2 355
kishino 16:6100acfeb1f1 356 if( uartCmdMgr_p->getCommandStatus() != 0 )
kishino 12:0254eaccfda2 357 {
kishino 40:b6b10c22a121 358 DEBUG_PRINT("scan status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
kishino 39:a1233ca02edf 359 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 39:a1233ca02edf 360 return -1;
kishino 12:0254eaccfda2 361 }
kishino 12:0254eaccfda2 362
kishino 38:f13e4e563d65 363 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 364
kishino 12:0254eaccfda2 365 return ret;
kishino 12:0254eaccfda2 366 }
kishino 12:0254eaccfda2 367
kishino 12:0254eaccfda2 368 int C_SNIC_WifiInterface::wifi_on( const char *country_p )
kishino 12:0254eaccfda2 369 {
kishino 24:987e412ae879 370 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
kishino 24:987e412ae879 371 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
kishino 16:6100acfeb1f1 372
kishino 12:0254eaccfda2 373 // Parameter check
kishino 12:0254eaccfda2 374 if( country_p == NULL )
kishino 12:0254eaccfda2 375 {
kishino 40:b6b10c22a121 376 DEBUG_PRINT("wifi_on parameter error\r\n");
kishino 12:0254eaccfda2 377 return -1;
kishino 12:0254eaccfda2 378 }
kishino 12:0254eaccfda2 379
kishino 12:0254eaccfda2 380 // Get buffer for response payload from MemoryPool
kishino 38:f13e4e563d65 381 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
kishino 38:f13e4e563d65 382 if( payload_buf_p == NULL )
kishino 12:0254eaccfda2 383 {
kishino 40:b6b10c22a121 384 DEBUG_PRINT("wifi_on payload_buf_p NULL\r\n");
kishino 12:0254eaccfda2 385 return -1;
kishino 12:0254eaccfda2 386 }
kishino 12:0254eaccfda2 387
kishino 22:a9ec0cad4f84 388 C_SNIC_Core::tagWIFI_ON_REQ_T req;
kishino 12:0254eaccfda2 389 // Make request
kishino 12:0254eaccfda2 390 req.cmd_sid = UART_CMD_SID_WIFI_ON_REQ;
kishino 12:0254eaccfda2 391 req.seq = mUartRequestSeq++;
kishino 12:0254eaccfda2 392 memcpy( req.country, country_p, COUNTRYC_CODE_LENTH );
kishino 12:0254eaccfda2 393
kishino 38:f13e4e563d65 394 unsigned char *command_array_p = snic_core_p->getCommandBuf();
kishino 12:0254eaccfda2 395 unsigned int command_len;
kishino 12:0254eaccfda2 396 // Preparation of command
kishino 24:987e412ae879 397 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req
kishino 38:f13e4e563d65 398 , sizeof(C_SNIC_Core::tagWIFI_ON_REQ_T), payload_buf_p->buf, command_array_p );
kishino 12:0254eaccfda2 399
kishino 12:0254eaccfda2 400 // Send uart command request
kishino 38:f13e4e563d65 401 snic_core_p->sendUart( command_len, command_array_p );
kishino 12:0254eaccfda2 402
kishino 12:0254eaccfda2 403 int ret;
kishino 12:0254eaccfda2 404 // Wait UART response
kishino 16:6100acfeb1f1 405 ret = uartCmdMgr_p->wait();
kishino 12:0254eaccfda2 406 if( ret != 0 )
kishino 12:0254eaccfda2 407 {
kishino 40:b6b10c22a121 408 DEBUG_PRINT( "wifi_on failed\r\n" );
kishino 38:f13e4e563d65 409 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 410 return -1;
kishino 12:0254eaccfda2 411 }
kishino 12:0254eaccfda2 412
kishino 16:6100acfeb1f1 413 if( uartCmdMgr_p->getCommandStatus() != 0 )
kishino 12:0254eaccfda2 414 {
kishino 40:b6b10c22a121 415 DEBUG_PRINT("wifi_on status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
kishino 39:a1233ca02edf 416 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 39:a1233ca02edf 417 return -1;
kishino 12:0254eaccfda2 418 }
kishino 38:f13e4e563d65 419 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 420
kishino 12:0254eaccfda2 421 return ret;
kishino 12:0254eaccfda2 422 }
kishino 12:0254eaccfda2 423
kishino 12:0254eaccfda2 424 int C_SNIC_WifiInterface::wifi_off()
kishino 12:0254eaccfda2 425 {
kishino 24:987e412ae879 426 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
kishino 24:987e412ae879 427 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
kishino 16:6100acfeb1f1 428
kishino 12:0254eaccfda2 429 // Get buffer for response payload from MemoryPool
kishino 38:f13e4e563d65 430 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
kishino 38:f13e4e563d65 431 if( payload_buf_p == NULL )
kishino 12:0254eaccfda2 432 {
kishino 40:b6b10c22a121 433 DEBUG_PRINT("wifi_off payload_buf_p NULL\r\n");
kishino 12:0254eaccfda2 434 return -1;
kishino 12:0254eaccfda2 435 }
kishino 12:0254eaccfda2 436
kishino 22:a9ec0cad4f84 437 C_SNIC_Core::tagWIFI_OFF_REQ_T req;
kishino 12:0254eaccfda2 438 // Make request
kishino 12:0254eaccfda2 439 req.cmd_sid = UART_CMD_SID_WIFI_OFF_REQ;
kishino 12:0254eaccfda2 440 req.seq = mUartRequestSeq++;
kishino 12:0254eaccfda2 441
kishino 38:f13e4e563d65 442 unsigned char *command_array_p = snic_core_p->getCommandBuf();
kishino 12:0254eaccfda2 443 unsigned int command_len;
kishino 12:0254eaccfda2 444 // Preparation of command
kishino 24:987e412ae879 445 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req
kishino 38:f13e4e563d65 446 , sizeof(C_SNIC_Core::tagWIFI_OFF_REQ_T), payload_buf_p->buf, command_array_p );
kishino 12:0254eaccfda2 447
kishino 12:0254eaccfda2 448 // Send uart command request
kishino 38:f13e4e563d65 449 snic_core_p->sendUart( command_len, command_array_p );
kishino 12:0254eaccfda2 450
kishino 12:0254eaccfda2 451 int ret;
kishino 12:0254eaccfda2 452 // Wait UART response
kishino 16:6100acfeb1f1 453 ret = uartCmdMgr_p->wait();
kishino 12:0254eaccfda2 454 if( ret != 0 )
kishino 12:0254eaccfda2 455 {
kishino 40:b6b10c22a121 456 DEBUG_PRINT( "wifi_off failed\r\n" );
kishino 38:f13e4e563d65 457 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 458 return -1;
kishino 12:0254eaccfda2 459 }
kishino 12:0254eaccfda2 460
kishino 16:6100acfeb1f1 461 if( uartCmdMgr_p->getCommandStatus() != 0 )
kishino 12:0254eaccfda2 462 {
kishino 40:b6b10c22a121 463 DEBUG_PRINT("wifi_off status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
kishino 39:a1233ca02edf 464 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 39:a1233ca02edf 465 return -1;
kishino 12:0254eaccfda2 466 }
kishino 38:f13e4e563d65 467 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 468
kishino 12:0254eaccfda2 469 return ret;
kishino 12:0254eaccfda2 470 }
kishino 12:0254eaccfda2 471
kishino 12:0254eaccfda2 472 int C_SNIC_WifiInterface::getRssi( signed char *rssi_p )
kishino 12:0254eaccfda2 473 {
kishino 24:987e412ae879 474 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
kishino 24:987e412ae879 475 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
kishino 12:0254eaccfda2 476 if( rssi_p == NULL )
kishino 12:0254eaccfda2 477 {
kishino 40:b6b10c22a121 478 DEBUG_PRINT("getRssi parameter error\r\n");
kishino 12:0254eaccfda2 479 return -1;
kishino 12:0254eaccfda2 480 }
kishino 12:0254eaccfda2 481
kishino 12:0254eaccfda2 482 // Get buffer for response payload from MemoryPool
kishino 38:f13e4e563d65 483 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
kishino 38:f13e4e563d65 484 if( payload_buf_p == NULL )
kishino 12:0254eaccfda2 485 {
kishino 40:b6b10c22a121 486 DEBUG_PRINT("getRssi payload_buf_p NULL\r\n");
kishino 12:0254eaccfda2 487 return -1;
kishino 12:0254eaccfda2 488 }
kishino 12:0254eaccfda2 489
kishino 22:a9ec0cad4f84 490 C_SNIC_Core::tagWIFI_GET_STA_RSSI_REQ_T req;
kishino 12:0254eaccfda2 491
kishino 12:0254eaccfda2 492 // Make request
kishino 12:0254eaccfda2 493 req.cmd_sid = UART_CMD_SID_WIFI_GET_STA_RSSI_REQ;
kishino 12:0254eaccfda2 494 req.seq = mUartRequestSeq++;
kishino 12:0254eaccfda2 495
kishino 38:f13e4e563d65 496 unsigned char *command_array_p = snic_core_p->getCommandBuf();
kishino 12:0254eaccfda2 497 unsigned int command_len;
kishino 24:987e412ae879 498 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req
kishino 38:f13e4e563d65 499 , sizeof(C_SNIC_Core::tagWIFI_GET_STA_RSSI_REQ_T), payload_buf_p->buf, command_array_p );
kishino 12:0254eaccfda2 500
kishino 12:0254eaccfda2 501 int ret;
kishino 12:0254eaccfda2 502 // Send uart command request
kishino 38:f13e4e563d65 503 snic_core_p->sendUart( command_len, command_array_p );
kishino 12:0254eaccfda2 504
kishino 12:0254eaccfda2 505 // Wait UART response
kishino 16:6100acfeb1f1 506 ret = uartCmdMgr_p->wait();
kishino 12:0254eaccfda2 507 if( ret != 0 )
kishino 12:0254eaccfda2 508 {
kishino 40:b6b10c22a121 509 DEBUG_PRINT( "getRssi failed\r\n" );
kishino 38:f13e4e563d65 510 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 511 return -1;
kishino 12:0254eaccfda2 512 }
kishino 12:0254eaccfda2 513
kishino 38:f13e4e563d65 514 *rssi_p = (signed char)payload_buf_p->buf[2];
kishino 12:0254eaccfda2 515
kishino 38:f13e4e563d65 516 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 517 return 0;
kishino 12:0254eaccfda2 518 }
kishino 12:0254eaccfda2 519
kishino 12:0254eaccfda2 520 int C_SNIC_WifiInterface::getWifiStatus( tagWIFI_STATUS_T *status_p)
kishino 12:0254eaccfda2 521 {
kishino 24:987e412ae879 522 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
kishino 24:987e412ae879 523 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
kishino 16:6100acfeb1f1 524
kishino 12:0254eaccfda2 525 if( status_p == NULL )
kishino 12:0254eaccfda2 526 {
kishino 40:b6b10c22a121 527 DEBUG_PRINT("getWifiStatus parameter error\r\n");
kishino 12:0254eaccfda2 528 return -1;
kishino 12:0254eaccfda2 529 }
kishino 12:0254eaccfda2 530
kishino 12:0254eaccfda2 531 // Get buffer for response payload from MemoryPool
kishino 38:f13e4e563d65 532 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
kishino 38:f13e4e563d65 533 if( payload_buf_p == NULL )
kishino 12:0254eaccfda2 534 {
kishino 40:b6b10c22a121 535 DEBUG_PRINT("getWifiStatus payload_buf_p NULL\r\n");
kishino 12:0254eaccfda2 536 return -1;
kishino 12:0254eaccfda2 537 }
kishino 12:0254eaccfda2 538
kishino 22:a9ec0cad4f84 539 C_SNIC_Core::tagWIFI_GET_STATUS_REQ_T req;
kishino 12:0254eaccfda2 540 // Make request
kishino 12:0254eaccfda2 541 req.cmd_sid = UART_CMD_SID_WIFI_GET_STATUS_REQ;
kishino 12:0254eaccfda2 542 req.seq = mUartRequestSeq++;
kishino 12:0254eaccfda2 543 req.interface = 0;
kishino 12:0254eaccfda2 544
kishino 38:f13e4e563d65 545 unsigned char *command_array_p = snic_core_p->getCommandBuf();
kishino 12:0254eaccfda2 546 unsigned int command_len;
kishino 24:987e412ae879 547 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req
kishino 38:f13e4e563d65 548 , sizeof(C_SNIC_Core::tagWIFI_GET_STATUS_REQ_T), payload_buf_p->buf, command_array_p );
kishino 12:0254eaccfda2 549
kishino 12:0254eaccfda2 550 // Send uart command request
kishino 38:f13e4e563d65 551 snic_core_p->sendUart( command_len, command_array_p );
kishino 12:0254eaccfda2 552
kishino 12:0254eaccfda2 553 int ret;
kishino 12:0254eaccfda2 554 // Wait UART response
kishino 16:6100acfeb1f1 555 ret = uartCmdMgr_p->wait();
kishino 12:0254eaccfda2 556 if( ret != 0 )
kishino 12:0254eaccfda2 557 {
kishino 40:b6b10c22a121 558 DEBUG_PRINT( "getWifiStatus failed\r\n" );
kishino 38:f13e4e563d65 559 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 560 return -1;
kishino 12:0254eaccfda2 561 }
kishino 12:0254eaccfda2 562
kishino 12:0254eaccfda2 563 // set status
kishino 38:f13e4e563d65 564 status_p->status = (E_WIFI_STATUS)payload_buf_p->buf[2];
kishino 12:0254eaccfda2 565
kishino 12:0254eaccfda2 566 // set Mac address
kishino 12:0254eaccfda2 567 if( status_p->status != e_STATUS_OFF )
kishino 12:0254eaccfda2 568 {
kishino 38:f13e4e563d65 569 memcpy( status_p->mac_address, &payload_buf_p->buf[3], BSSID_MAC_LENTH );
kishino 12:0254eaccfda2 570 }
kishino 12:0254eaccfda2 571
kishino 12:0254eaccfda2 572 // set SSID
kishino 37:f3a2053627c2 573 if( ( status_p->status == e_STA_JOINED ) || ( status_p->status == e_AP_STARTED ) )
kishino 12:0254eaccfda2 574 {
kishino 38:f13e4e563d65 575 memcpy( status_p->ssid, &payload_buf_p->buf[9], strlen( (char *)&payload_buf_p->buf[9]) );
kishino 12:0254eaccfda2 576 }
kishino 12:0254eaccfda2 577
kishino 38:f13e4e563d65 578 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 579 return 0;
kishino 12:0254eaccfda2 580 }
kishino 31:15c22824cc46 581
kishino 31:15c22824cc46 582 int C_SNIC_WifiInterface::setIPConfig( bool is_DHCP
kishino 31:15c22824cc46 583 , const char *ip_p, const char *mask_p, const char *gateway_p )
kishino 31:15c22824cc46 584 {
kishino 31:15c22824cc46 585 // Parameter check
kishino 31:15c22824cc46 586 if( is_DHCP == false )
kishino 31:15c22824cc46 587 {
kishino 31:15c22824cc46 588 if( (ip_p == NULL) || (mask_p == NULL) ||(gateway_p == NULL) )
kishino 31:15c22824cc46 589 {
kishino 40:b6b10c22a121 590 DEBUG_PRINT("setIPConfig parameter error\r\n");
kishino 31:15c22824cc46 591 return -1;
kishino 31:15c22824cc46 592 }
kishino 31:15c22824cc46 593 }
kishino 31:15c22824cc46 594
kishino 31:15c22824cc46 595 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
kishino 31:15c22824cc46 596 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
kishino 31:15c22824cc46 597
kishino 31:15c22824cc46 598 // Get buffer for response payload from MemoryPool
kishino 38:f13e4e563d65 599 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
kishino 38:f13e4e563d65 600 if( payload_buf_p == NULL )
kishino 31:15c22824cc46 601 {
kishino 40:b6b10c22a121 602 DEBUG_PRINT("setIPConfig payload_buf_p NULL\r\n");
kishino 31:15c22824cc46 603 return -1;
kishino 31:15c22824cc46 604 }
kishino 31:15c22824cc46 605
kishino 38:f13e4e563d65 606 unsigned char *command_array_p = snic_core_p->getCommandBuf();
kishino 31:15c22824cc46 607 unsigned int command_len;
kishino 31:15c22824cc46 608 if( is_DHCP == true )
kishino 31:15c22824cc46 609 {
kishino 31:15c22824cc46 610 C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_DHCP_T req;
kishino 31:15c22824cc46 611 // Make request
kishino 31:15c22824cc46 612 req.cmd_sid = UART_CMD_SID_SNIC_IP_CONFIG_REQ;
kishino 31:15c22824cc46 613 req.seq = mUartRequestSeq++;
kishino 31:15c22824cc46 614 req.interface = 0;
kishino 31:15c22824cc46 615 req.dhcp = 1;
kishino 31:15c22824cc46 616
kishino 31:15c22824cc46 617 // Preparation of command
kishino 31:15c22824cc46 618 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req
kishino 38:f13e4e563d65 619 , sizeof(C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_DHCP_T), payload_buf_p->buf, command_array_p );
kishino 31:15c22824cc46 620 }
kishino 31:15c22824cc46 621 else
kishino 31:15c22824cc46 622 {
kishino 31:15c22824cc46 623 C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_STATIC_T req;
kishino 31:15c22824cc46 624 // Make request
kishino 31:15c22824cc46 625 req.cmd_sid = UART_CMD_SID_SNIC_IP_CONFIG_REQ;
kishino 31:15c22824cc46 626 req.seq = mUartRequestSeq++;
kishino 31:15c22824cc46 627 req.interface = 0;
kishino 31:15c22824cc46 628 req.dhcp = 0;
kishino 31:15c22824cc46 629
kishino 31:15c22824cc46 630 // Set paramter of address
kishino 31:15c22824cc46 631 int addr_temp;
kishino 31:15c22824cc46 632 addr_temp = C_SNIC_UartMsgUtil::addrToInteger( ip_p );
kishino 31:15c22824cc46 633 C_SNIC_UartMsgUtil::convertIntToByteAdday( addr_temp, (char *)req.ip_addr );
kishino 31:15c22824cc46 634 addr_temp = C_SNIC_UartMsgUtil::addrToInteger( mask_p );
kishino 31:15c22824cc46 635 C_SNIC_UartMsgUtil::convertIntToByteAdday( addr_temp, (char *)req.netmask );
kishino 31:15c22824cc46 636 addr_temp = C_SNIC_UartMsgUtil::addrToInteger( gateway_p );
kishino 31:15c22824cc46 637 C_SNIC_UartMsgUtil::convertIntToByteAdday( addr_temp, (char *)req.gateway );
kishino 31:15c22824cc46 638
kishino 31:15c22824cc46 639 // Preparation of command
kishino 31:15c22824cc46 640 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req
kishino 38:f13e4e563d65 641 , sizeof(C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_STATIC_T), payload_buf_p->buf, command_array_p );
kishino 31:15c22824cc46 642 }
kishino 31:15c22824cc46 643 // Send uart command request
kishino 38:f13e4e563d65 644 snic_core_p->sendUart( command_len, command_array_p );
kishino 31:15c22824cc46 645
kishino 31:15c22824cc46 646 int ret;
kishino 31:15c22824cc46 647 // Wait UART response
kishino 31:15c22824cc46 648 ret = uartCmdMgr_p->wait();
kishino 31:15c22824cc46 649 if( ret != 0 )
kishino 31:15c22824cc46 650 {
kishino 40:b6b10c22a121 651 DEBUG_PRINT( "setIPConfig failed\r\n" );
kishino 38:f13e4e563d65 652 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 31:15c22824cc46 653 return -1;
kishino 31:15c22824cc46 654 }
kishino 31:15c22824cc46 655
kishino 31:15c22824cc46 656 if( uartCmdMgr_p->getCommandStatus() != 0 )
kishino 31:15c22824cc46 657 {
kishino 40:b6b10c22a121 658 DEBUG_PRINT("setIPConfig status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
kishino 39:a1233ca02edf 659 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 39:a1233ca02edf 660 return -1;
kishino 31:15c22824cc46 661 }
kishino 31:15c22824cc46 662
kishino 38:f13e4e563d65 663 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 36:f33fcf5975ab 664 return ret;
kishino 31:15c22824cc46 665 }
MACRUM 47:62ba69ff80d2 666
MACRUM 47:62ba69ff80d2 667 char* C_SNIC_WifiInterface::getIPAddress() {
MACRUM 47:62ba69ff80d2 668 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
MACRUM 47:62ba69ff80d2 669 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
MACRUM 47:62ba69ff80d2 670
MACRUM 47:62ba69ff80d2 671 snic_core_p->lockAPI();
MACRUM 47:62ba69ff80d2 672 // Get local ip address.
MACRUM 47:62ba69ff80d2 673 // Get buffer for response payload from MemoryPool
MACRUM 47:62ba69ff80d2 674 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
MACRUM 47:62ba69ff80d2 675 if( payload_buf_p == NULL )
MACRUM 47:62ba69ff80d2 676 {
MACRUM 47:62ba69ff80d2 677 DEBUG_PRINT("getIPAddress payload_buf_p NULL\r\n");
MACRUM 47:62ba69ff80d2 678 snic_core_p->unlockAPI();
MACRUM 47:62ba69ff80d2 679 return 0;
MACRUM 47:62ba69ff80d2 680 }
MACRUM 47:62ba69ff80d2 681
MACRUM 47:62ba69ff80d2 682 C_SNIC_Core::tagSNIC_GET_DHCP_INFO_REQ_T req;
MACRUM 47:62ba69ff80d2 683 // Make request
MACRUM 47:62ba69ff80d2 684 req.cmd_sid = UART_CMD_SID_SNIC_GET_DHCP_INFO_REQ;
MACRUM 47:62ba69ff80d2 685 req.seq = mUartRequestSeq++;
MACRUM 47:62ba69ff80d2 686 req.interface = 0;
MACRUM 47:62ba69ff80d2 687
MACRUM 47:62ba69ff80d2 688 unsigned char *command_array_p = snic_core_p->getCommandBuf();
MACRUM 47:62ba69ff80d2 689 unsigned int command_len;
MACRUM 47:62ba69ff80d2 690 // Preparation of command
MACRUM 47:62ba69ff80d2 691 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req
MACRUM 47:62ba69ff80d2 692 , sizeof(C_SNIC_Core::tagSNIC_GET_DHCP_INFO_REQ_T), payload_buf_p->buf, command_array_p );
MACRUM 47:62ba69ff80d2 693 // Send uart command request
MACRUM 47:62ba69ff80d2 694 snic_core_p->sendUart( command_len, command_array_p );
MACRUM 47:62ba69ff80d2 695 // Wait UART response
MACRUM 47:62ba69ff80d2 696 int ret = uartCmdMgr_p->wait();
MACRUM 47:62ba69ff80d2 697 if( ret != 0 )
MACRUM 47:62ba69ff80d2 698 {
MACRUM 47:62ba69ff80d2 699 DEBUG_PRINT( "getIPAddress failed\r\n" );
MACRUM 47:62ba69ff80d2 700 snic_core_p->freeCmdBuf( payload_buf_p );
MACRUM 47:62ba69ff80d2 701 snic_core_p->unlockAPI();
MACRUM 47:62ba69ff80d2 702 return 0;
MACRUM 47:62ba69ff80d2 703 }
MACRUM 47:62ba69ff80d2 704
MACRUM 47:62ba69ff80d2 705 if( uartCmdMgr_p->getCommandStatus() != UART_CMD_RES_SNIC_SUCCESS )
MACRUM 47:62ba69ff80d2 706 {
MACRUM 47:62ba69ff80d2 707 snic_core_p->freeCmdBuf( payload_buf_p );
MACRUM 47:62ba69ff80d2 708 snic_core_p->unlockAPI();
MACRUM 47:62ba69ff80d2 709 return 0;
MACRUM 47:62ba69ff80d2 710 }
MACRUM 47:62ba69ff80d2 711
MACRUM 47:62ba69ff80d2 712 snic_core_p->freeCmdBuf( payload_buf_p );
MACRUM 47:62ba69ff80d2 713 snic_core_p->unlockAPI();
MACRUM 47:62ba69ff80d2 714
MACRUM 47:62ba69ff80d2 715 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 47:62ba69ff80d2 716
MACRUM 47:62ba69ff80d2 717 return ip_addr;
MACRUM 47:62ba69ff80d2 718 }
MACRUM 47:62ba69ff80d2 719