SNICInterface for ThingPlug Example

Dependents:   ThingPlug_WiFi_Example ThingPlug_WiFi_Example_2

Fork of SNICInterface by muRata

Committer:
kishino
Date:
Tue Jul 15 09:56:37 2014 +0000
Revision:
40:b6b10c22a121
Parent:
39:a1233ca02edf
Child:
43:d80bbb12ffe6
The platform-dependent code was modified to implemented in ifdef.; The process of debug log output was changed to macro.;

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];
kishino 12:0254eaccfda2 24
kishino 12:0254eaccfda2 25 C_SNIC_WifiInterface::C_SNIC_WifiInterface( PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm, int baud)
kishino 12:0254eaccfda2 26 {
kishino 12:0254eaccfda2 27 mUART_tx = tx;
kishino 12:0254eaccfda2 28 mUART_rx = rx;
kishino 12:0254eaccfda2 29 mUART_cts = cts;
kishino 12:0254eaccfda2 30 mUART_rts = rts;;
kishino 12:0254eaccfda2 31 mUART_baud = baud;
kishino 12:0254eaccfda2 32 mModuleReset = reset;
kishino 12:0254eaccfda2 33 }
kishino 12:0254eaccfda2 34
kishino 26:f2e1030964e4 35 C_SNIC_WifiInterface::~C_SNIC_WifiInterface()
kishino 26:f2e1030964e4 36 {
kishino 26:f2e1030964e4 37 }
kishino 26:f2e1030964e4 38
kishino 12:0254eaccfda2 39 int C_SNIC_WifiInterface::init()
kishino 24:987e412ae879 40 {
kishino 24:987e412ae879 41 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
kishino 24:987e412ae879 42 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
kishino 16:6100acfeb1f1 43
kishino 37:f3a2053627c2 44 /* Initialize UART */
kishino 37:f3a2053627c2 45 snic_core_p->initUart( mUART_tx, mUART_rx, mUART_baud );
kishino 37:f3a2053627c2 46
kishino 29:6a0ba999597d 47 /* Module reset */
kishino 29:6a0ba999597d 48 snic_core_p->resetModule( mModuleReset );
kishino 29:6a0ba999597d 49
kishino 37:f3a2053627c2 50 wait(1);
kishino 12:0254eaccfda2 51 /* Initialize SNIC API */
kishino 12:0254eaccfda2 52 // Get buffer for response payload from MemoryPool
kishino 38:f13e4e563d65 53 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
kishino 38:f13e4e563d65 54 if( payload_buf_p == NULL )
kishino 12:0254eaccfda2 55 {
kishino 40:b6b10c22a121 56 DEBUG_PRINT("snic_init payload_buf_p NULL\r\n");
kishino 12:0254eaccfda2 57 return -1;
kishino 12:0254eaccfda2 58 }
kishino 12:0254eaccfda2 59
kishino 22:a9ec0cad4f84 60 C_SNIC_Core::tagSNIC_INIT_REQ_T req;
kishino 12:0254eaccfda2 61 // Make request
kishino 12:0254eaccfda2 62 req.cmd_sid = UART_CMD_SID_SNIC_INIT_REQ;
kishino 12:0254eaccfda2 63 req.seq = mUartRequestSeq++;
kishino 28:b796031f6519 64 req.buf_size[0] = 0x08;
kishino 28:b796031f6519 65 req.buf_size[1] = 0x00;
kishino 12:0254eaccfda2 66
kishino 38:f13e4e563d65 67 unsigned char *command_array_p = snic_core_p->getCommandBuf();
kishino 12:0254eaccfda2 68 unsigned int command_len;
kishino 12:0254eaccfda2 69 // Preparation of command
kishino 24:987e412ae879 70 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req
kishino 38:f13e4e563d65 71 , sizeof(C_SNIC_Core::tagSNIC_INIT_REQ_T), payload_buf_p->buf, command_array_p );
kishino 12:0254eaccfda2 72
kishino 12:0254eaccfda2 73 // Send uart command request
kishino 38:f13e4e563d65 74 snic_core_p->sendUart( command_len, command_array_p );
kishino 12:0254eaccfda2 75
kishino 12:0254eaccfda2 76 int ret;
kishino 12:0254eaccfda2 77 // Wait UART response
kishino 16:6100acfeb1f1 78 ret = uartCmdMgr_p->wait();
kishino 12:0254eaccfda2 79 if( ret != 0 )
kishino 12:0254eaccfda2 80 {
kishino 40:b6b10c22a121 81 DEBUG_PRINT( "snic_init failed\r\n" );
kishino 38:f13e4e563d65 82 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 83 return -1;
kishino 12:0254eaccfda2 84 }
kishino 12:0254eaccfda2 85
kishino 16:6100acfeb1f1 86 if( uartCmdMgr_p->getCommandStatus() != 0 )
kishino 12:0254eaccfda2 87 {
kishino 40:b6b10c22a121 88 DEBUG_PRINT("snic_init status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
kishino 39:a1233ca02edf 89 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 39:a1233ca02edf 90 return -1;
kishino 12:0254eaccfda2 91 }
kishino 38:f13e4e563d65 92 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 93
kishino 12:0254eaccfda2 94 return ret;
kishino 12:0254eaccfda2 95 }
kishino 12:0254eaccfda2 96
kishino 12:0254eaccfda2 97 int C_SNIC_WifiInterface::getFWVersion( unsigned char *version_p )
kishino 12:0254eaccfda2 98 {
kishino 24:987e412ae879 99 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
kishino 24:987e412ae879 100 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
kishino 16:6100acfeb1f1 101
kishino 12:0254eaccfda2 102 // Get buffer for response payload from MemoryPool
kishino 38:f13e4e563d65 103 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
kishino 38:f13e4e563d65 104 if( payload_buf_p == NULL )
kishino 12:0254eaccfda2 105 {
kishino 40:b6b10c22a121 106 DEBUG_PRINT("getFWVersion payload_buf_p NULL\r\n");
kishino 12:0254eaccfda2 107 return -1;
kishino 12:0254eaccfda2 108 }
kishino 12:0254eaccfda2 109
kishino 22:a9ec0cad4f84 110 C_SNIC_Core::tagGEN_FW_VER_GET_REQ_T req;
kishino 12:0254eaccfda2 111 // Make request
kishino 12:0254eaccfda2 112 req.cmd_sid = UART_CMD_SID_GEN_FW_VER_GET_REQ;
kishino 12:0254eaccfda2 113 req.seq = mUartRequestSeq++;
kishino 12:0254eaccfda2 114
kishino 38:f13e4e563d65 115 unsigned char *command_array_p = snic_core_p->getCommandBuf();
kishino 12:0254eaccfda2 116 unsigned int command_len;
kishino 12:0254eaccfda2 117 // Preparation of command
kishino 24:987e412ae879 118 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_GEN, req.cmd_sid, (unsigned char *)&req
kishino 38:f13e4e563d65 119 , sizeof(C_SNIC_Core::tagGEN_FW_VER_GET_REQ_T), payload_buf_p->buf, command_array_p );
kishino 12:0254eaccfda2 120
kishino 12:0254eaccfda2 121 int ret;
kishino 12:0254eaccfda2 122
kishino 12:0254eaccfda2 123 // Send uart command request
kishino 38:f13e4e563d65 124 snic_core_p->sendUart( command_len, command_array_p );
kishino 12:0254eaccfda2 125
kishino 12:0254eaccfda2 126 // Wait UART response
kishino 16:6100acfeb1f1 127 ret = uartCmdMgr_p->wait();
kishino 12:0254eaccfda2 128 if( ret != 0 )
kishino 12:0254eaccfda2 129 {
kishino 40:b6b10c22a121 130 DEBUG_PRINT( "getFWversion failed\r\n" );
kishino 38:f13e4e563d65 131 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 132 return -1;
kishino 12:0254eaccfda2 133 }
kishino 12:0254eaccfda2 134
kishino 16:6100acfeb1f1 135 if( uartCmdMgr_p->getCommandStatus() == 0 )
kishino 12:0254eaccfda2 136 {
kishino 38:f13e4e563d65 137 unsigned char version_len = payload_buf_p->buf[3];
kishino 38:f13e4e563d65 138 memcpy( version_p, &payload_buf_p->buf[4], version_len );
kishino 12:0254eaccfda2 139 }
kishino 38:f13e4e563d65 140 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 141 return 0;
kishino 12:0254eaccfda2 142 }
kishino 12:0254eaccfda2 143
kishino 12:0254eaccfda2 144 int C_SNIC_WifiInterface::connect(const char *ssid_p, unsigned char ssid_len, E_SECURITY sec_type
kishino 12:0254eaccfda2 145 , const char *sec_key_p, unsigned char sec_key_len)
kishino 12:0254eaccfda2 146 {
kishino 24:987e412ae879 147 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
kishino 24:987e412ae879 148 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
kishino 16:6100acfeb1f1 149
kishino 12:0254eaccfda2 150 // Parameter check(SSID)
kishino 12:0254eaccfda2 151 if( (ssid_p == NULL) || (ssid_len == 0) )
kishino 12:0254eaccfda2 152 {
kishino 40:b6b10c22a121 153 DEBUG_PRINT( "connect failed [ parameter NG:SSID ]\r\n" );
kishino 12:0254eaccfda2 154 return -1;
kishino 12:0254eaccfda2 155 }
kishino 12:0254eaccfda2 156
kishino 12:0254eaccfda2 157 // Parameter check(Security key)
kishino 12:0254eaccfda2 158 if( (sec_type != e_SEC_OPEN) && ( (sec_key_len == 0) || (sec_key_p == NULL) ) )
kishino 12:0254eaccfda2 159 {
kishino 40:b6b10c22a121 160 DEBUG_PRINT( "connect failed [ parameter NG:Security key ]\r\n" );
kishino 12:0254eaccfda2 161 return -1;
kishino 12:0254eaccfda2 162 }
kishino 12:0254eaccfda2 163
kishino 12:0254eaccfda2 164 // Get buffer for response payload from MemoryPool
kishino 38:f13e4e563d65 165 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
kishino 38:f13e4e563d65 166 if( payload_buf_p == NULL )
kishino 12:0254eaccfda2 167 {
kishino 40:b6b10c22a121 168 DEBUG_PRINT("connect payload_buf_p NULL\r\n");
kishino 12:0254eaccfda2 169 return -1;
kishino 12:0254eaccfda2 170 }
kishino 12:0254eaccfda2 171
kishino 29:6a0ba999597d 172 unsigned char *buf = &gCONNECT_BUF[0];
kishino 12:0254eaccfda2 173 unsigned int buf_len = 0;
kishino 12:0254eaccfda2 174 unsigned int command_len;
kishino 12:0254eaccfda2 175
kishino 36:f33fcf5975ab 176 memset( buf, 0, UART_CONNECT_BUF_SIZE );
kishino 12:0254eaccfda2 177 // Make request
kishino 12:0254eaccfda2 178 buf[0] = UART_CMD_SID_WIFI_JOIN_REQ;
kishino 12:0254eaccfda2 179 buf_len++;
kishino 12:0254eaccfda2 180 buf[1] = mUartRequestSeq++;
kishino 12:0254eaccfda2 181 buf_len++;
kishino 12:0254eaccfda2 182 // SSID
kishino 12:0254eaccfda2 183 memcpy( &buf[2], ssid_p, ssid_len );
kishino 12:0254eaccfda2 184 buf_len += ssid_len;
kishino 12:0254eaccfda2 185 buf_len++;
kishino 12:0254eaccfda2 186
kishino 12:0254eaccfda2 187 // Security mode
kishino 12:0254eaccfda2 188 buf[ buf_len ] = (unsigned char)sec_type;
kishino 12:0254eaccfda2 189 buf_len++;
kishino 12:0254eaccfda2 190
kishino 12:0254eaccfda2 191 // Security key
kishino 12:0254eaccfda2 192 if( sec_type != e_SEC_OPEN )
kishino 12:0254eaccfda2 193 {
kishino 12:0254eaccfda2 194 buf[ buf_len ] = sec_key_len;
kishino 12:0254eaccfda2 195 buf_len++;
kishino 12:0254eaccfda2 196 if( sec_key_len > 0 )
kishino 12:0254eaccfda2 197 {
kishino 12:0254eaccfda2 198 memcpy( &buf[buf_len], sec_key_p, sec_key_len );
kishino 12:0254eaccfda2 199 buf_len += sec_key_len;
kishino 12:0254eaccfda2 200 }
kishino 12:0254eaccfda2 201 }
kishino 12:0254eaccfda2 202
kishino 38:f13e4e563d65 203 unsigned char *command_array_p = snic_core_p->getCommandBuf();
kishino 12:0254eaccfda2 204 // Preparation of command
kishino 24:987e412ae879 205 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, UART_CMD_SID_WIFI_JOIN_REQ, buf
kishino 38:f13e4e563d65 206 , buf_len, payload_buf_p->buf, command_array_p );
kishino 12:0254eaccfda2 207
kishino 12:0254eaccfda2 208 // Send uart command request
kishino 38:f13e4e563d65 209 snic_core_p->sendUart( command_len, command_array_p );
kishino 12:0254eaccfda2 210
kishino 12:0254eaccfda2 211 int ret;
kishino 12:0254eaccfda2 212 // Wait UART response
kishino 16:6100acfeb1f1 213 ret = uartCmdMgr_p->wait();
kishino 12:0254eaccfda2 214 if( ret != 0 )
kishino 12:0254eaccfda2 215 {
kishino 40:b6b10c22a121 216 DEBUG_PRINT( "join failed\r\n" );
kishino 38:f13e4e563d65 217 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 218 return -1;
kishino 12:0254eaccfda2 219 }
kishino 12:0254eaccfda2 220
kishino 29:6a0ba999597d 221 if( (uartCmdMgr_p->getCommandStatus() != 0) &&
kishino 29:6a0ba999597d 222 (uartCmdMgr_p->getCommandStatus() != UART_CMD_RES_WIFI_ERR_ALREADY_JOINED) )
kishino 12:0254eaccfda2 223 {
kishino 40:b6b10c22a121 224 DEBUG_PRINT("join status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
kishino 39:a1233ca02edf 225 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 39:a1233ca02edf 226 return -1;
kishino 12:0254eaccfda2 227 }
kishino 38:f13e4e563d65 228 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 229
kishino 12:0254eaccfda2 230 return ret;
kishino 12:0254eaccfda2 231 }
kishino 12:0254eaccfda2 232
kishino 12:0254eaccfda2 233 int C_SNIC_WifiInterface::disconnect()
kishino 12:0254eaccfda2 234 {
kishino 24:987e412ae879 235 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
kishino 24:987e412ae879 236 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
kishino 16:6100acfeb1f1 237
kishino 12:0254eaccfda2 238 // Get buffer for response payload from MemoryPool
kishino 38:f13e4e563d65 239 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
kishino 38:f13e4e563d65 240 if( payload_buf_p == NULL )
kishino 12:0254eaccfda2 241 {
kishino 40:b6b10c22a121 242 DEBUG_PRINT("disconnect payload_buf_p NULL\r\n");
kishino 12:0254eaccfda2 243 return -1;
kishino 12:0254eaccfda2 244 }
kishino 12:0254eaccfda2 245
kishino 22:a9ec0cad4f84 246 C_SNIC_Core::tagWIFI_DISCONNECT_REQ_T req;
kishino 12:0254eaccfda2 247 // Make request
kishino 12:0254eaccfda2 248 req.cmd_sid = UART_CMD_SID_WIFI_DISCONNECT_REQ;
kishino 12:0254eaccfda2 249 req.seq = mUartRequestSeq++;
kishino 12:0254eaccfda2 250
kishino 38:f13e4e563d65 251 unsigned char *command_array_p = snic_core_p->getCommandBuf();
kishino 12:0254eaccfda2 252 unsigned int command_len;
kishino 12:0254eaccfda2 253 // Preparation of command
kishino 24:987e412ae879 254 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req
kishino 38:f13e4e563d65 255 , sizeof(C_SNIC_Core::tagWIFI_DISCONNECT_REQ_T), payload_buf_p->buf, command_array_p );
kishino 12:0254eaccfda2 256
kishino 12:0254eaccfda2 257 // Send uart command request
kishino 38:f13e4e563d65 258 snic_core_p->sendUart( command_len, command_array_p );
kishino 12:0254eaccfda2 259
kishino 12:0254eaccfda2 260 int ret;
kishino 12:0254eaccfda2 261 // Wait UART response
kishino 16:6100acfeb1f1 262 ret = uartCmdMgr_p->wait();
kishino 12:0254eaccfda2 263 if( ret != 0 )
kishino 12:0254eaccfda2 264 {
kishino 40:b6b10c22a121 265 DEBUG_PRINT( "disconnect failed\r\n" );
kishino 38:f13e4e563d65 266 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 267 return -1;
kishino 12:0254eaccfda2 268 }
kishino 12:0254eaccfda2 269
kishino 16:6100acfeb1f1 270 if( uartCmdMgr_p->getCommandStatus() != 0 )
kishino 12:0254eaccfda2 271 {
kishino 40:b6b10c22a121 272 DEBUG_PRINT("disconnect status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
kishino 12:0254eaccfda2 273 ret = -1;
kishino 12:0254eaccfda2 274 }
kishino 38:f13e4e563d65 275 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 276 return ret;
kishino 12:0254eaccfda2 277 }
kishino 12:0254eaccfda2 278
kishino 12:0254eaccfda2 279 int C_SNIC_WifiInterface::scan( const char *ssid_p, unsigned char *bssid_p
kishino 12:0254eaccfda2 280 , void (*result_handler_p)(tagSCAN_RESULT_T *scan_result) )
kishino 12:0254eaccfda2 281 {
kishino 24:987e412ae879 282 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
kishino 24:987e412ae879 283 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
kishino 16:6100acfeb1f1 284
kishino 12:0254eaccfda2 285 // Get buffer for response payload from MemoryPool
kishino 38:f13e4e563d65 286 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
kishino 38:f13e4e563d65 287 if( payload_buf_p == NULL )
kishino 12:0254eaccfda2 288 {
kishino 40:b6b10c22a121 289 DEBUG_PRINT("scan payload_buf_p NULL\r\n");
kishino 12:0254eaccfda2 290 return -1;
kishino 12:0254eaccfda2 291 }
kishino 12:0254eaccfda2 292
kishino 22:a9ec0cad4f84 293 C_SNIC_Core::tagWIFI_SCAN_REQ_T req;
kishino 12:0254eaccfda2 294 unsigned int buf_len = 0;
kishino 12:0254eaccfda2 295
kishino 22:a9ec0cad4f84 296 memset( &req, 0, sizeof(C_SNIC_Core::tagWIFI_SCAN_REQ_T) );
kishino 12:0254eaccfda2 297 // Make request
kishino 12:0254eaccfda2 298 req.cmd_sid = UART_CMD_SID_WIFI_SCAN_REQ;
kishino 12:0254eaccfda2 299 buf_len++;
kishino 12:0254eaccfda2 300 req.seq = mUartRequestSeq++;
kishino 12:0254eaccfda2 301 buf_len++;
kishino 12:0254eaccfda2 302
kishino 12:0254eaccfda2 303 // Set scan type(Active scan)
kishino 12:0254eaccfda2 304 req.scan_type = 0;
kishino 12:0254eaccfda2 305 buf_len++;
kishino 12:0254eaccfda2 306 // Set bss type(any)
kishino 12:0254eaccfda2 307 req.bss_type = 2;
kishino 12:0254eaccfda2 308 buf_len++;
kishino 12:0254eaccfda2 309 // Set BSSID
kishino 12:0254eaccfda2 310 if( bssid_p != NULL )
kishino 12:0254eaccfda2 311 {
kishino 12:0254eaccfda2 312 memcpy( req.bssid, bssid_p, BSSID_MAC_LENTH );
kishino 12:0254eaccfda2 313 }
kishino 12:0254eaccfda2 314 buf_len += BSSID_MAC_LENTH;
kishino 12:0254eaccfda2 315 // Set channel list(0)
kishino 12:0254eaccfda2 316 req.chan_list = 0;
kishino 12:0254eaccfda2 317 buf_len++;
kishino 12:0254eaccfda2 318 //Set SSID
kishino 12:0254eaccfda2 319 if( ssid_p != NULL )
kishino 12:0254eaccfda2 320 {
kishino 12:0254eaccfda2 321 strcpy( (char *)req.ssid, ssid_p );
kishino 12:0254eaccfda2 322 buf_len += strlen(ssid_p);
kishino 12:0254eaccfda2 323 }
kishino 12:0254eaccfda2 324 buf_len++;
kishino 12:0254eaccfda2 325
kishino 38:f13e4e563d65 326 unsigned char *command_array_p = snic_core_p->getCommandBuf();
kishino 12:0254eaccfda2 327 unsigned int command_len;
kishino 12:0254eaccfda2 328 // Preparation of command
kishino 24:987e412ae879 329 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req
kishino 38:f13e4e563d65 330 , buf_len, payload_buf_p->buf, command_array_p );
kishino 12:0254eaccfda2 331
kishino 12:0254eaccfda2 332 // Set scan result callback
kishino 16:6100acfeb1f1 333 uartCmdMgr_p->setScanResultHandler( result_handler_p );
kishino 12:0254eaccfda2 334
kishino 12:0254eaccfda2 335 // Send uart command request
kishino 38:f13e4e563d65 336 snic_core_p->sendUart( command_len, command_array_p );
kishino 12:0254eaccfda2 337
kishino 12:0254eaccfda2 338 int ret;
kishino 12:0254eaccfda2 339 // Wait UART response
kishino 16:6100acfeb1f1 340 ret = uartCmdMgr_p->wait();
kishino 40:b6b10c22a121 341 DEBUG_PRINT( "scan wait:%d\r\n", ret );
kishino 12:0254eaccfda2 342 if( ret != 0 )
kishino 12:0254eaccfda2 343 {
kishino 40:b6b10c22a121 344 DEBUG_PRINT( "scan failed\r\n" );
kishino 38:f13e4e563d65 345 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 346 return -1;
kishino 12:0254eaccfda2 347 }
kishino 12:0254eaccfda2 348
kishino 16:6100acfeb1f1 349 if( uartCmdMgr_p->getCommandStatus() != 0 )
kishino 12:0254eaccfda2 350 {
kishino 40:b6b10c22a121 351 DEBUG_PRINT("scan status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
kishino 39:a1233ca02edf 352 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 39:a1233ca02edf 353 return -1;
kishino 12:0254eaccfda2 354 }
kishino 12:0254eaccfda2 355
kishino 38:f13e4e563d65 356 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 357
kishino 12:0254eaccfda2 358 return ret;
kishino 12:0254eaccfda2 359 }
kishino 12:0254eaccfda2 360
kishino 12:0254eaccfda2 361 int C_SNIC_WifiInterface::wifi_on( const char *country_p )
kishino 12:0254eaccfda2 362 {
kishino 24:987e412ae879 363 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
kishino 24:987e412ae879 364 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
kishino 16:6100acfeb1f1 365
kishino 12:0254eaccfda2 366 // Parameter check
kishino 12:0254eaccfda2 367 if( country_p == NULL )
kishino 12:0254eaccfda2 368 {
kishino 40:b6b10c22a121 369 DEBUG_PRINT("wifi_on parameter error\r\n");
kishino 12:0254eaccfda2 370 return -1;
kishino 12:0254eaccfda2 371 }
kishino 12:0254eaccfda2 372
kishino 12:0254eaccfda2 373 // Get buffer for response payload from MemoryPool
kishino 38:f13e4e563d65 374 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
kishino 38:f13e4e563d65 375 if( payload_buf_p == NULL )
kishino 12:0254eaccfda2 376 {
kishino 40:b6b10c22a121 377 DEBUG_PRINT("wifi_on payload_buf_p NULL\r\n");
kishino 12:0254eaccfda2 378 return -1;
kishino 12:0254eaccfda2 379 }
kishino 12:0254eaccfda2 380
kishino 22:a9ec0cad4f84 381 C_SNIC_Core::tagWIFI_ON_REQ_T req;
kishino 12:0254eaccfda2 382 // Make request
kishino 12:0254eaccfda2 383 req.cmd_sid = UART_CMD_SID_WIFI_ON_REQ;
kishino 12:0254eaccfda2 384 req.seq = mUartRequestSeq++;
kishino 12:0254eaccfda2 385 memcpy( req.country, country_p, COUNTRYC_CODE_LENTH );
kishino 12:0254eaccfda2 386
kishino 38:f13e4e563d65 387 unsigned char *command_array_p = snic_core_p->getCommandBuf();
kishino 12:0254eaccfda2 388 unsigned int command_len;
kishino 12:0254eaccfda2 389 // Preparation of command
kishino 24:987e412ae879 390 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req
kishino 38:f13e4e563d65 391 , sizeof(C_SNIC_Core::tagWIFI_ON_REQ_T), payload_buf_p->buf, command_array_p );
kishino 12:0254eaccfda2 392
kishino 12:0254eaccfda2 393 // Send uart command request
kishino 38:f13e4e563d65 394 snic_core_p->sendUart( command_len, command_array_p );
kishino 12:0254eaccfda2 395
kishino 12:0254eaccfda2 396 int ret;
kishino 12:0254eaccfda2 397 // Wait UART response
kishino 16:6100acfeb1f1 398 ret = uartCmdMgr_p->wait();
kishino 12:0254eaccfda2 399 if( ret != 0 )
kishino 12:0254eaccfda2 400 {
kishino 40:b6b10c22a121 401 DEBUG_PRINT( "wifi_on failed\r\n" );
kishino 38:f13e4e563d65 402 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 403 return -1;
kishino 12:0254eaccfda2 404 }
kishino 12:0254eaccfda2 405
kishino 16:6100acfeb1f1 406 if( uartCmdMgr_p->getCommandStatus() != 0 )
kishino 12:0254eaccfda2 407 {
kishino 40:b6b10c22a121 408 DEBUG_PRINT("wifi_on status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
kishino 39:a1233ca02edf 409 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 39:a1233ca02edf 410 return -1;
kishino 12:0254eaccfda2 411 }
kishino 38:f13e4e563d65 412 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 413
kishino 12:0254eaccfda2 414 return ret;
kishino 12:0254eaccfda2 415 }
kishino 12:0254eaccfda2 416
kishino 12:0254eaccfda2 417 int C_SNIC_WifiInterface::wifi_off()
kishino 12:0254eaccfda2 418 {
kishino 24:987e412ae879 419 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
kishino 24:987e412ae879 420 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
kishino 16:6100acfeb1f1 421
kishino 12:0254eaccfda2 422 // Get buffer for response payload from MemoryPool
kishino 38:f13e4e563d65 423 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
kishino 38:f13e4e563d65 424 if( payload_buf_p == NULL )
kishino 12:0254eaccfda2 425 {
kishino 40:b6b10c22a121 426 DEBUG_PRINT("wifi_off payload_buf_p NULL\r\n");
kishino 12:0254eaccfda2 427 return -1;
kishino 12:0254eaccfda2 428 }
kishino 12:0254eaccfda2 429
kishino 22:a9ec0cad4f84 430 C_SNIC_Core::tagWIFI_OFF_REQ_T req;
kishino 12:0254eaccfda2 431 // Make request
kishino 12:0254eaccfda2 432 req.cmd_sid = UART_CMD_SID_WIFI_OFF_REQ;
kishino 12:0254eaccfda2 433 req.seq = mUartRequestSeq++;
kishino 12:0254eaccfda2 434
kishino 38:f13e4e563d65 435 unsigned char *command_array_p = snic_core_p->getCommandBuf();
kishino 12:0254eaccfda2 436 unsigned int command_len;
kishino 12:0254eaccfda2 437 // Preparation of command
kishino 24:987e412ae879 438 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req
kishino 38:f13e4e563d65 439 , sizeof(C_SNIC_Core::tagWIFI_OFF_REQ_T), payload_buf_p->buf, command_array_p );
kishino 12:0254eaccfda2 440
kishino 12:0254eaccfda2 441 // Send uart command request
kishino 38:f13e4e563d65 442 snic_core_p->sendUart( command_len, command_array_p );
kishino 12:0254eaccfda2 443
kishino 12:0254eaccfda2 444 int ret;
kishino 12:0254eaccfda2 445 // Wait UART response
kishino 16:6100acfeb1f1 446 ret = uartCmdMgr_p->wait();
kishino 12:0254eaccfda2 447 if( ret != 0 )
kishino 12:0254eaccfda2 448 {
kishino 40:b6b10c22a121 449 DEBUG_PRINT( "wifi_off failed\r\n" );
kishino 38:f13e4e563d65 450 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 451 return -1;
kishino 12:0254eaccfda2 452 }
kishino 12:0254eaccfda2 453
kishino 16:6100acfeb1f1 454 if( uartCmdMgr_p->getCommandStatus() != 0 )
kishino 12:0254eaccfda2 455 {
kishino 40:b6b10c22a121 456 DEBUG_PRINT("wifi_off status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
kishino 39:a1233ca02edf 457 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 39:a1233ca02edf 458 return -1;
kishino 12:0254eaccfda2 459 }
kishino 38:f13e4e563d65 460 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 461
kishino 12:0254eaccfda2 462 return ret;
kishino 12:0254eaccfda2 463 }
kishino 12:0254eaccfda2 464
kishino 12:0254eaccfda2 465 int C_SNIC_WifiInterface::getRssi( signed char *rssi_p )
kishino 12:0254eaccfda2 466 {
kishino 24:987e412ae879 467 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
kishino 24:987e412ae879 468 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
kishino 12:0254eaccfda2 469 if( rssi_p == NULL )
kishino 12:0254eaccfda2 470 {
kishino 40:b6b10c22a121 471 DEBUG_PRINT("getRssi parameter error\r\n");
kishino 12:0254eaccfda2 472 return -1;
kishino 12:0254eaccfda2 473 }
kishino 12:0254eaccfda2 474
kishino 12:0254eaccfda2 475 // Get buffer for response payload from MemoryPool
kishino 38:f13e4e563d65 476 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
kishino 38:f13e4e563d65 477 if( payload_buf_p == NULL )
kishino 12:0254eaccfda2 478 {
kishino 40:b6b10c22a121 479 DEBUG_PRINT("getRssi payload_buf_p NULL\r\n");
kishino 12:0254eaccfda2 480 return -1;
kishino 12:0254eaccfda2 481 }
kishino 12:0254eaccfda2 482
kishino 22:a9ec0cad4f84 483 C_SNIC_Core::tagWIFI_GET_STA_RSSI_REQ_T req;
kishino 12:0254eaccfda2 484
kishino 12:0254eaccfda2 485 // Make request
kishino 12:0254eaccfda2 486 req.cmd_sid = UART_CMD_SID_WIFI_GET_STA_RSSI_REQ;
kishino 12:0254eaccfda2 487 req.seq = mUartRequestSeq++;
kishino 12:0254eaccfda2 488
kishino 38:f13e4e563d65 489 unsigned char *command_array_p = snic_core_p->getCommandBuf();
kishino 12:0254eaccfda2 490 unsigned int command_len;
kishino 24:987e412ae879 491 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req
kishino 38:f13e4e563d65 492 , sizeof(C_SNIC_Core::tagWIFI_GET_STA_RSSI_REQ_T), payload_buf_p->buf, command_array_p );
kishino 12:0254eaccfda2 493
kishino 12:0254eaccfda2 494 int ret;
kishino 12:0254eaccfda2 495 // Send uart command request
kishino 38:f13e4e563d65 496 snic_core_p->sendUart( command_len, command_array_p );
kishino 12:0254eaccfda2 497
kishino 12:0254eaccfda2 498 // Wait UART response
kishino 16:6100acfeb1f1 499 ret = uartCmdMgr_p->wait();
kishino 12:0254eaccfda2 500 if( ret != 0 )
kishino 12:0254eaccfda2 501 {
kishino 40:b6b10c22a121 502 DEBUG_PRINT( "getRssi failed\r\n" );
kishino 38:f13e4e563d65 503 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 504 return -1;
kishino 12:0254eaccfda2 505 }
kishino 12:0254eaccfda2 506
kishino 38:f13e4e563d65 507 *rssi_p = (signed char)payload_buf_p->buf[2];
kishino 12:0254eaccfda2 508
kishino 38:f13e4e563d65 509 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 510 return 0;
kishino 12:0254eaccfda2 511 }
kishino 12:0254eaccfda2 512
kishino 12:0254eaccfda2 513 int C_SNIC_WifiInterface::getWifiStatus( tagWIFI_STATUS_T *status_p)
kishino 12:0254eaccfda2 514 {
kishino 24:987e412ae879 515 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
kishino 24:987e412ae879 516 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
kishino 16:6100acfeb1f1 517
kishino 12:0254eaccfda2 518 if( status_p == NULL )
kishino 12:0254eaccfda2 519 {
kishino 40:b6b10c22a121 520 DEBUG_PRINT("getWifiStatus parameter error\r\n");
kishino 12:0254eaccfda2 521 return -1;
kishino 12:0254eaccfda2 522 }
kishino 12:0254eaccfda2 523
kishino 12:0254eaccfda2 524 // Get buffer for response payload from MemoryPool
kishino 38:f13e4e563d65 525 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
kishino 38:f13e4e563d65 526 if( payload_buf_p == NULL )
kishino 12:0254eaccfda2 527 {
kishino 40:b6b10c22a121 528 DEBUG_PRINT("getWifiStatus payload_buf_p NULL\r\n");
kishino 12:0254eaccfda2 529 return -1;
kishino 12:0254eaccfda2 530 }
kishino 12:0254eaccfda2 531
kishino 22:a9ec0cad4f84 532 C_SNIC_Core::tagWIFI_GET_STATUS_REQ_T req;
kishino 12:0254eaccfda2 533 // Make request
kishino 12:0254eaccfda2 534 req.cmd_sid = UART_CMD_SID_WIFI_GET_STATUS_REQ;
kishino 12:0254eaccfda2 535 req.seq = mUartRequestSeq++;
kishino 12:0254eaccfda2 536 req.interface = 0;
kishino 12:0254eaccfda2 537
kishino 38:f13e4e563d65 538 unsigned char *command_array_p = snic_core_p->getCommandBuf();
kishino 12:0254eaccfda2 539 unsigned int command_len;
kishino 24:987e412ae879 540 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req
kishino 38:f13e4e563d65 541 , sizeof(C_SNIC_Core::tagWIFI_GET_STATUS_REQ_T), payload_buf_p->buf, command_array_p );
kishino 12:0254eaccfda2 542
kishino 12:0254eaccfda2 543 // Send uart command request
kishino 38:f13e4e563d65 544 snic_core_p->sendUart( command_len, command_array_p );
kishino 12:0254eaccfda2 545
kishino 12:0254eaccfda2 546 int ret;
kishino 12:0254eaccfda2 547 // Wait UART response
kishino 16:6100acfeb1f1 548 ret = uartCmdMgr_p->wait();
kishino 12:0254eaccfda2 549 if( ret != 0 )
kishino 12:0254eaccfda2 550 {
kishino 40:b6b10c22a121 551 DEBUG_PRINT( "getWifiStatus failed\r\n" );
kishino 38:f13e4e563d65 552 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 553 return -1;
kishino 12:0254eaccfda2 554 }
kishino 12:0254eaccfda2 555
kishino 12:0254eaccfda2 556 // set status
kishino 38:f13e4e563d65 557 status_p->status = (E_WIFI_STATUS)payload_buf_p->buf[2];
kishino 12:0254eaccfda2 558
kishino 12:0254eaccfda2 559 // set Mac address
kishino 12:0254eaccfda2 560 if( status_p->status != e_STATUS_OFF )
kishino 12:0254eaccfda2 561 {
kishino 38:f13e4e563d65 562 memcpy( status_p->mac_address, &payload_buf_p->buf[3], BSSID_MAC_LENTH );
kishino 12:0254eaccfda2 563 }
kishino 12:0254eaccfda2 564
kishino 12:0254eaccfda2 565 // set SSID
kishino 37:f3a2053627c2 566 if( ( status_p->status == e_STA_JOINED ) || ( status_p->status == e_AP_STARTED ) )
kishino 12:0254eaccfda2 567 {
kishino 38:f13e4e563d65 568 memcpy( status_p->ssid, &payload_buf_p->buf[9], strlen( (char *)&payload_buf_p->buf[9]) );
kishino 12:0254eaccfda2 569 }
kishino 12:0254eaccfda2 570
kishino 38:f13e4e563d65 571 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 12:0254eaccfda2 572 return 0;
kishino 12:0254eaccfda2 573 }
kishino 31:15c22824cc46 574
kishino 31:15c22824cc46 575 int C_SNIC_WifiInterface::setIPConfig( bool is_DHCP
kishino 31:15c22824cc46 576 , const char *ip_p, const char *mask_p, const char *gateway_p )
kishino 31:15c22824cc46 577 {
kishino 31:15c22824cc46 578 // Parameter check
kishino 31:15c22824cc46 579 if( is_DHCP == false )
kishino 31:15c22824cc46 580 {
kishino 31:15c22824cc46 581 if( (ip_p == NULL) || (mask_p == NULL) ||(gateway_p == NULL) )
kishino 31:15c22824cc46 582 {
kishino 40:b6b10c22a121 583 DEBUG_PRINT("setIPConfig parameter error\r\n");
kishino 31:15c22824cc46 584 return -1;
kishino 31:15c22824cc46 585 }
kishino 31:15c22824cc46 586 }
kishino 31:15c22824cc46 587
kishino 31:15c22824cc46 588 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
kishino 31:15c22824cc46 589 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
kishino 31:15c22824cc46 590
kishino 31:15c22824cc46 591 // Get buffer for response payload from MemoryPool
kishino 38:f13e4e563d65 592 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
kishino 38:f13e4e563d65 593 if( payload_buf_p == NULL )
kishino 31:15c22824cc46 594 {
kishino 40:b6b10c22a121 595 DEBUG_PRINT("setIPConfig payload_buf_p NULL\r\n");
kishino 31:15c22824cc46 596 return -1;
kishino 31:15c22824cc46 597 }
kishino 31:15c22824cc46 598
kishino 38:f13e4e563d65 599 unsigned char *command_array_p = snic_core_p->getCommandBuf();
kishino 31:15c22824cc46 600 unsigned int command_len;
kishino 31:15c22824cc46 601 if( is_DHCP == true )
kishino 31:15c22824cc46 602 {
kishino 31:15c22824cc46 603 C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_DHCP_T req;
kishino 31:15c22824cc46 604 // Make request
kishino 31:15c22824cc46 605 req.cmd_sid = UART_CMD_SID_SNIC_IP_CONFIG_REQ;
kishino 31:15c22824cc46 606 req.seq = mUartRequestSeq++;
kishino 31:15c22824cc46 607 req.interface = 0;
kishino 31:15c22824cc46 608 req.dhcp = 1;
kishino 31:15c22824cc46 609
kishino 31:15c22824cc46 610 // Preparation of command
kishino 31:15c22824cc46 611 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req
kishino 38:f13e4e563d65 612 , sizeof(C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_DHCP_T), payload_buf_p->buf, command_array_p );
kishino 31:15c22824cc46 613 }
kishino 31:15c22824cc46 614 else
kishino 31:15c22824cc46 615 {
kishino 31:15c22824cc46 616 C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_STATIC_T req;
kishino 31:15c22824cc46 617 // Make request
kishino 31:15c22824cc46 618 req.cmd_sid = UART_CMD_SID_SNIC_IP_CONFIG_REQ;
kishino 31:15c22824cc46 619 req.seq = mUartRequestSeq++;
kishino 31:15c22824cc46 620 req.interface = 0;
kishino 31:15c22824cc46 621 req.dhcp = 0;
kishino 31:15c22824cc46 622
kishino 31:15c22824cc46 623 // Set paramter of address
kishino 31:15c22824cc46 624 int addr_temp;
kishino 31:15c22824cc46 625 addr_temp = C_SNIC_UartMsgUtil::addrToInteger( ip_p );
kishino 31:15c22824cc46 626 C_SNIC_UartMsgUtil::convertIntToByteAdday( addr_temp, (char *)req.ip_addr );
kishino 31:15c22824cc46 627 addr_temp = C_SNIC_UartMsgUtil::addrToInteger( mask_p );
kishino 31:15c22824cc46 628 C_SNIC_UartMsgUtil::convertIntToByteAdday( addr_temp, (char *)req.netmask );
kishino 31:15c22824cc46 629 addr_temp = C_SNIC_UartMsgUtil::addrToInteger( gateway_p );
kishino 31:15c22824cc46 630 C_SNIC_UartMsgUtil::convertIntToByteAdday( addr_temp, (char *)req.gateway );
kishino 31:15c22824cc46 631
kishino 31:15c22824cc46 632 // Preparation of command
kishino 31:15c22824cc46 633 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req
kishino 38:f13e4e563d65 634 , sizeof(C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_STATIC_T), payload_buf_p->buf, command_array_p );
kishino 31:15c22824cc46 635 }
kishino 31:15c22824cc46 636 // Send uart command request
kishino 38:f13e4e563d65 637 snic_core_p->sendUart( command_len, command_array_p );
kishino 31:15c22824cc46 638
kishino 31:15c22824cc46 639 int ret;
kishino 31:15c22824cc46 640 // Wait UART response
kishino 31:15c22824cc46 641 ret = uartCmdMgr_p->wait();
kishino 31:15c22824cc46 642 if( ret != 0 )
kishino 31:15c22824cc46 643 {
kishino 40:b6b10c22a121 644 DEBUG_PRINT( "setIPConfig failed\r\n" );
kishino 38:f13e4e563d65 645 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 31:15c22824cc46 646 return -1;
kishino 31:15c22824cc46 647 }
kishino 31:15c22824cc46 648
kishino 31:15c22824cc46 649 if( uartCmdMgr_p->getCommandStatus() != 0 )
kishino 31:15c22824cc46 650 {
kishino 40:b6b10c22a121 651 DEBUG_PRINT("setIPConfig status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
kishino 39:a1233ca02edf 652 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 39:a1233ca02edf 653 return -1;
kishino 31:15c22824cc46 654 }
kishino 31:15c22824cc46 655
kishino 38:f13e4e563d65 656 snic_core_p->freeCmdBuf( payload_buf_p );
kishino 36:f33fcf5975ab 657 return ret;
kishino 31:15c22824cc46 658 }