RC

Dependents:   WizFi250_AP_HelloWorld

Fork of WizFi250Interface by DongEun Koak

Committer:
kaizen
Date:
Mon Jun 02 23:34:10 2014 +0000
Revision:
0:f2039204c8f6
Child:
5:8a0702aa91e3
WizFi250 Library First Release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kaizen 0:f2039204c8f6 1 /*
kaizen 0:f2039204c8f6 2 /* Copyright (C) 2013 gsfan, MIT License
kaizen 0:f2039204c8f6 3 *
kaizen 0:f2039204c8f6 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
kaizen 0:f2039204c8f6 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
kaizen 0:f2039204c8f6 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
kaizen 0:f2039204c8f6 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
kaizen 0:f2039204c8f6 8 * furnished to do so, subject to the following conditions:
kaizen 0:f2039204c8f6 9 *
kaizen 0:f2039204c8f6 10 * The above copyright notice and this permission notice shall be included in all copies or
kaizen 0:f2039204c8f6 11 * substantial portions of the Software.
kaizen 0:f2039204c8f6 12 *
kaizen 0:f2039204c8f6 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
kaizen 0:f2039204c8f6 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
kaizen 0:f2039204c8f6 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
kaizen 0:f2039204c8f6 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
kaizen 0:f2039204c8f6 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
kaizen 0:f2039204c8f6 18 */
kaizen 0:f2039204c8f6 19 /* Copyright (C) 2014 Wiznet, MIT License
kaizen 0:f2039204c8f6 20 * port to the Wiznet Module WizFi250
kaizen 0:f2039204c8f6 21 */
kaizen 0:f2039204c8f6 22
kaizen 0:f2039204c8f6 23 #include "WizFi250.h"
kaizen 0:f2039204c8f6 24
kaizen 0:f2039204c8f6 25 #ifdef CFG_ENABLE_RTOS
kaizen 0:f2039204c8f6 26 #undef DBG
kaizen 0:f2039204c8f6 27 #define DBG(x, ...)
kaizen 0:f2039204c8f6 28 #endif
kaizen 0:f2039204c8f6 29
kaizen 0:f2039204c8f6 30 // This function is operating in ISR. So you can't use debug message.
kaizen 0:f2039204c8f6 31 void WizFi250::recvData ( char c )
kaizen 0:f2039204c8f6 32 {
kaizen 0:f2039204c8f6 33 static int cid, sub, len, count;
kaizen 0:f2039204c8f6 34
kaizen 0:f2039204c8f6 35 switch(_state.mode) {
kaizen 0:f2039204c8f6 36 case MODE_COMMAND:
kaizen 0:f2039204c8f6 37 switch(c) {
kaizen 0:f2039204c8f6 38 case 0:
kaizen 0:f2039204c8f6 39 case 0x0a: // LF
kaizen 0:f2039204c8f6 40 case 0x0d: // CR
kaizen 0:f2039204c8f6 41 break;
kaizen 0:f2039204c8f6 42
kaizen 0:f2039204c8f6 43 case '{':
kaizen 0:f2039204c8f6 44 _state.buf->flush();
kaizen 0:f2039204c8f6 45 _state.mode = MODE_DATA_RX;
kaizen 0:f2039204c8f6 46 sub = 0;
kaizen 0:f2039204c8f6 47 break;
kaizen 0:f2039204c8f6 48
kaizen 0:f2039204c8f6 49 default:
kaizen 0:f2039204c8f6 50 _state.buf->flush();
kaizen 0:f2039204c8f6 51 _state.buf->queue(c);
kaizen 0:f2039204c8f6 52 _state.mode = MODE_CMDRESP;
kaizen 0:f2039204c8f6 53 break;
kaizen 0:f2039204c8f6 54 }
kaizen 0:f2039204c8f6 55 break;
kaizen 0:f2039204c8f6 56
kaizen 0:f2039204c8f6 57 case MODE_CMDRESP:
kaizen 0:f2039204c8f6 58 switch(c){
kaizen 0:f2039204c8f6 59 case 0:
kaizen 0:f2039204c8f6 60 break;
kaizen 0:f2039204c8f6 61 case 0x0a: // LF
kaizen 0:f2039204c8f6 62 break;
kaizen 0:f2039204c8f6 63 case 0x0d: // CR
kaizen 0:f2039204c8f6 64
kaizen 0:f2039204c8f6 65 if (_flow == 2) setRts(false); // block
kaizen 0:f2039204c8f6 66 _state.mode = MODE_COMMAND;
kaizen 0:f2039204c8f6 67 parseMessage();
kaizen 0:f2039204c8f6 68 if (_flow == 2) setRts(true); // release
kaizen 0:f2039204c8f6 69
kaizen 0:f2039204c8f6 70 break;
kaizen 0:f2039204c8f6 71 default:
kaizen 0:f2039204c8f6 72 _state.buf->queue(c);
kaizen 0:f2039204c8f6 73 break;
kaizen 0:f2039204c8f6 74 }
kaizen 0:f2039204c8f6 75 break;
kaizen 0:f2039204c8f6 76
kaizen 0:f2039204c8f6 77 case MODE_DATA_RX:
kaizen 0:f2039204c8f6 78 switch(sub){
kaizen 0:f2039204c8f6 79 case 0:
kaizen 0:f2039204c8f6 80 // cid
kaizen 0:f2039204c8f6 81 if( (c >= '0') && (c <= '9') )
kaizen 0:f2039204c8f6 82 {
kaizen 0:f2039204c8f6 83 cid = x2i(c);
kaizen 0:f2039204c8f6 84 }
kaizen 0:f2039204c8f6 85 else if ( c == ',' )
kaizen 0:f2039204c8f6 86 {
kaizen 0:f2039204c8f6 87 sub++;
kaizen 0:f2039204c8f6 88 count = 0;
kaizen 0:f2039204c8f6 89 len = 0;
kaizen 0:f2039204c8f6 90 }
kaizen 0:f2039204c8f6 91 else
kaizen 0:f2039204c8f6 92 {
kaizen 0:f2039204c8f6 93 _state.mode = MODE_COMMAND;
kaizen 0:f2039204c8f6 94 }
kaizen 0:f2039204c8f6 95 break;
kaizen 0:f2039204c8f6 96
kaizen 0:f2039204c8f6 97 case 1:
kaizen 0:f2039204c8f6 98 // ip
kaizen 0:f2039204c8f6 99 if ((c >= '0' && c <= '9') || c == '.')
kaizen 0:f2039204c8f6 100 {
kaizen 0:f2039204c8f6 101 _con[cid].ip[count] = c;
kaizen 0:f2039204c8f6 102 count++;
kaizen 0:f2039204c8f6 103 }
kaizen 0:f2039204c8f6 104 else if( c == ',' )
kaizen 0:f2039204c8f6 105 {
kaizen 0:f2039204c8f6 106 _con[cid].ip[count] = '\0';
kaizen 0:f2039204c8f6 107 _con[cid].port = 0;
kaizen 0:f2039204c8f6 108 sub++;
kaizen 0:f2039204c8f6 109 }
kaizen 0:f2039204c8f6 110 else
kaizen 0:f2039204c8f6 111 {
kaizen 0:f2039204c8f6 112 _state.mode = MODE_COMMAND;
kaizen 0:f2039204c8f6 113 }
kaizen 0:f2039204c8f6 114 break;
kaizen 0:f2039204c8f6 115
kaizen 0:f2039204c8f6 116 case 2:
kaizen 0:f2039204c8f6 117 // port
kaizen 0:f2039204c8f6 118 if ( c >= '0' && c <= '9' )
kaizen 0:f2039204c8f6 119 {
kaizen 0:f2039204c8f6 120 _con[cid].port = (_con[cid].port * 10) + ( c - '0' );
kaizen 0:f2039204c8f6 121 }
kaizen 0:f2039204c8f6 122 else if( c == ',')
kaizen 0:f2039204c8f6 123 {
kaizen 0:f2039204c8f6 124 sub++;
kaizen 0:f2039204c8f6 125 count = 0;
kaizen 0:f2039204c8f6 126 }
kaizen 0:f2039204c8f6 127 else
kaizen 0:f2039204c8f6 128 {
kaizen 0:f2039204c8f6 129 _state.mode = MODE_COMMAND;
kaizen 0:f2039204c8f6 130 }
kaizen 0:f2039204c8f6 131 break;
kaizen 0:f2039204c8f6 132
kaizen 0:f2039204c8f6 133 case 3:
kaizen 0:f2039204c8f6 134 // data length
kaizen 0:f2039204c8f6 135 if ( c >= '0' && c <= '9' )
kaizen 0:f2039204c8f6 136 {
kaizen 0:f2039204c8f6 137 //_con[cid].recv_length = (_con[cid].recv_length * 10) + (c - '0');
kaizen 0:f2039204c8f6 138 len = (len * 10) + (c - '0');
kaizen 0:f2039204c8f6 139 }
kaizen 0:f2039204c8f6 140 else if( c == '}' )
kaizen 0:f2039204c8f6 141 {
kaizen 0:f2039204c8f6 142 sub++;
kaizen 0:f2039204c8f6 143 count = 0;
kaizen 0:f2039204c8f6 144 }
kaizen 0:f2039204c8f6 145 else
kaizen 0:f2039204c8f6 146 {
kaizen 0:f2039204c8f6 147 _state.mode = MODE_COMMAND;
kaizen 0:f2039204c8f6 148 }
kaizen 0:f2039204c8f6 149 break;
kaizen 0:f2039204c8f6 150
kaizen 0:f2039204c8f6 151 default:
kaizen 0:f2039204c8f6 152 if(_con[cid].buf != NULL)
kaizen 0:f2039204c8f6 153 {
kaizen 0:f2039204c8f6 154 _con[cid].buf->queue(c);
kaizen 0:f2039204c8f6 155 if(_con[cid].buf->available() > CFG_DATA_SIZE - 16 )
kaizen 0:f2039204c8f6 156 {
kaizen 0:f2039204c8f6 157 setRts(false); // blcok
kaizen 0:f2039204c8f6 158 _con[cid].received = true;
kaizen 0:f2039204c8f6 159 //WARN("buf full");
kaizen 0:f2039204c8f6 160 }
kaizen 0:f2039204c8f6 161 }
kaizen 0:f2039204c8f6 162 count++;
kaizen 0:f2039204c8f6 163 if(count >= len)
kaizen 0:f2039204c8f6 164 {
kaizen 0:f2039204c8f6 165 // DBG("recv cid: %d, count : %d, len : %d",cid, count, len);
kaizen 0:f2039204c8f6 166 _con[cid].received = true;
kaizen 0:f2039204c8f6 167 _state.mode = MODE_COMMAND;
kaizen 0:f2039204c8f6 168 }
kaizen 0:f2039204c8f6 169 break;
kaizen 0:f2039204c8f6 170 }
kaizen 0:f2039204c8f6 171 break;
kaizen 0:f2039204c8f6 172 }
kaizen 0:f2039204c8f6 173 }
kaizen 0:f2039204c8f6 174
kaizen 0:f2039204c8f6 175
kaizen 0:f2039204c8f6 176 #define MSG_TABLE_NUM 6
kaizen 0:f2039204c8f6 177 #define RES_TABLE_NUM 7
kaizen 0:f2039204c8f6 178 int WizFi250::parseMessage () {
kaizen 0:f2039204c8f6 179 int i;
kaizen 0:f2039204c8f6 180 char buf[256];
kaizen 0:f2039204c8f6 181
kaizen 0:f2039204c8f6 182 static const struct MSG_TABLE {
kaizen 0:f2039204c8f6 183 const char msg[24];
kaizen 0:f2039204c8f6 184 void (WizFi250::*func)(const char *);
kaizen 0:f2039204c8f6 185 } msg_table[MSG_TABLE_NUM] = {
kaizen 0:f2039204c8f6 186 {"[OK]", &WizFi250::msgOk},
kaizen 0:f2039204c8f6 187 {"[ERROR]", &WizFi250::msgError},
kaizen 0:f2039204c8f6 188 {"[ERROR:INVALIDINPUT]", &WizFi250::msgError},
kaizen 0:f2039204c8f6 189 {"[CONNECT ", &WizFi250::msgConnect},
kaizen 0:f2039204c8f6 190 {"[DISCONNECT ", &WizFi250::msgDisconnect},
kaizen 0:f2039204c8f6 191 {"[LISTEN ", &WizFi250::msgListen},
kaizen 0:f2039204c8f6 192 };
kaizen 0:f2039204c8f6 193 static const struct RES_TABLE{
kaizen 0:f2039204c8f6 194 const Response res;
kaizen 0:f2039204c8f6 195 void (WizFi250::*func)(const char *);
kaizen 0:f2039204c8f6 196 }res_table[RES_TABLE_NUM]={
kaizen 0:f2039204c8f6 197 {RES_NULL, NULL},
kaizen 0:f2039204c8f6 198 {RES_MACADDRESS, &WizFi250::resMacAddress},
kaizen 0:f2039204c8f6 199 {RES_WJOIN, &WizFi250::resWJOIN},
kaizen 0:f2039204c8f6 200 {RES_CONNECT, &WizFi250::resConnect},
kaizen 0:f2039204c8f6 201 {RES_SSEND, &WizFi250::resSSEND},
kaizen 0:f2039204c8f6 202 {RES_FDNS, &WizFi250::resFDNS},
kaizen 0:f2039204c8f6 203 {RES_SMGMT, &WizFi250::resSMGMT},
kaizen 0:f2039204c8f6 204 };
kaizen 0:f2039204c8f6 205
kaizen 0:f2039204c8f6 206
kaizen 0:f2039204c8f6 207 for( i=0; i<sizeof(buf); i++ )
kaizen 0:f2039204c8f6 208 {
kaizen 0:f2039204c8f6 209 if( _state.buf->dequeue(&buf[i]) == false) break;
kaizen 0:f2039204c8f6 210 }
kaizen 0:f2039204c8f6 211
kaizen 0:f2039204c8f6 212 buf[i] = '\0';
kaizen 0:f2039204c8f6 213 //strncpy(_state.dbgRespBuf, buf, sizeof(buf));
kaizen 0:f2039204c8f6 214
kaizen 0:f2039204c8f6 215 if(_state.res != RES_NULL)
kaizen 0:f2039204c8f6 216 {
kaizen 0:f2039204c8f6 217 for( i=0; i<RES_TABLE_NUM; i++)
kaizen 0:f2039204c8f6 218 {
kaizen 0:f2039204c8f6 219 if(res_table[i].res == _state.res)
kaizen 0:f2039204c8f6 220 {
kaizen 0:f2039204c8f6 221 //DBG("parse res %d '%s'\r\n", i, buf);
kaizen 0:f2039204c8f6 222 if(res_table[i].func != NULL)
kaizen 0:f2039204c8f6 223 {
kaizen 0:f2039204c8f6 224 (this->*(res_table[i].func))(buf);
kaizen 0:f2039204c8f6 225 }
kaizen 0:f2039204c8f6 226
kaizen 0:f2039204c8f6 227 if(res_table[i].res == RES_CONNECT && _state.n < 2)
kaizen 0:f2039204c8f6 228 return -1;
kaizen 0:f2039204c8f6 229 }
kaizen 0:f2039204c8f6 230 }
kaizen 0:f2039204c8f6 231 }
kaizen 0:f2039204c8f6 232
kaizen 0:f2039204c8f6 233 for( i=0; i<MSG_TABLE_NUM; i++)
kaizen 0:f2039204c8f6 234 {
kaizen 0:f2039204c8f6 235 if( strncmp(buf, msg_table[i].msg, strlen(msg_table[i].msg)) == 0 )
kaizen 0:f2039204c8f6 236 {
kaizen 0:f2039204c8f6 237 //DBG("parse msg '%s'\r\n", buf);
kaizen 0:f2039204c8f6 238 if(msg_table[i].func != NULL)
kaizen 0:f2039204c8f6 239 {
kaizen 0:f2039204c8f6 240 (this->*(msg_table[i].func))(buf);
kaizen 0:f2039204c8f6 241 }
kaizen 0:f2039204c8f6 242 return 0;
kaizen 0:f2039204c8f6 243 }
kaizen 0:f2039204c8f6 244 }
kaizen 0:f2039204c8f6 245
kaizen 0:f2039204c8f6 246 return -1;
kaizen 0:f2039204c8f6 247 }
kaizen 0:f2039204c8f6 248
kaizen 0:f2039204c8f6 249
kaizen 0:f2039204c8f6 250 void WizFi250::msgOk (const char *buf)
kaizen 0:f2039204c8f6 251 {
kaizen 0:f2039204c8f6 252 _state.ok = true;
kaizen 0:f2039204c8f6 253 strncpy(_state.dummyBuf,buf,strlen(buf));
kaizen 0:f2039204c8f6 254 // if(_state.status == STAT_DEEPSLEEP){
kaizen 0:f2039204c8f6 255 // _state.status = STAT_READY;
kaizen 0:f2039204c8f6 256 // }
kaizen 0:f2039204c8f6 257 }
kaizen 0:f2039204c8f6 258
kaizen 0:f2039204c8f6 259 void WizFi250::msgError (const char *buf)
kaizen 0:f2039204c8f6 260 {
kaizen 0:f2039204c8f6 261 _state.failure = true;
kaizen 0:f2039204c8f6 262 }
kaizen 0:f2039204c8f6 263
kaizen 0:f2039204c8f6 264 void WizFi250::msgConnect (const char *buf)
kaizen 0:f2039204c8f6 265 {
kaizen 0:f2039204c8f6 266 int cid;
kaizen 0:f2039204c8f6 267
kaizen 0:f2039204c8f6 268 if (buf[9] < '0' || buf[9] > '8' || buf[10] != ']') return;
kaizen 0:f2039204c8f6 269
kaizen 0:f2039204c8f6 270 cid = x2i(buf[9]);
kaizen 0:f2039204c8f6 271
kaizen 0:f2039204c8f6 272 initCon(cid, true);
kaizen 0:f2039204c8f6 273 _state.cid = cid;
kaizen 0:f2039204c8f6 274 _con[cid].accept = true;
kaizen 0:f2039204c8f6 275 _con[cid].parent = cid;
kaizen 0:f2039204c8f6 276 }
kaizen 0:f2039204c8f6 277
kaizen 0:f2039204c8f6 278 void WizFi250::msgDisconnect (const char *buf)
kaizen 0:f2039204c8f6 279 {
kaizen 0:f2039204c8f6 280 int cid;
kaizen 0:f2039204c8f6 281
kaizen 0:f2039204c8f6 282 if(buf[12] < '0' || buf[12] > '8' || buf[13] != ']') return;
kaizen 0:f2039204c8f6 283
kaizen 0:f2039204c8f6 284 cid = x2i(buf[12]);
kaizen 0:f2039204c8f6 285 _con[cid].connected = false;
kaizen 0:f2039204c8f6 286 }
kaizen 0:f2039204c8f6 287
kaizen 0:f2039204c8f6 288 void WizFi250::msgListen (const char *buf)
kaizen 0:f2039204c8f6 289 {
kaizen 0:f2039204c8f6 290 int cid;
kaizen 0:f2039204c8f6 291
kaizen 0:f2039204c8f6 292 if(buf[8] < '0' || buf[8] > '8' || buf[9] != ']') return;
kaizen 0:f2039204c8f6 293
kaizen 0:f2039204c8f6 294 cid = x2i(buf[8]);
kaizen 0:f2039204c8f6 295 _state.cid = cid;
kaizen 0:f2039204c8f6 296 }
kaizen 0:f2039204c8f6 297
kaizen 0:f2039204c8f6 298 void WizFi250::resMacAddress (const char *buf)
kaizen 0:f2039204c8f6 299 {
kaizen 0:f2039204c8f6 300 if( buf[2] == ':' && buf[5] == ':')
kaizen 0:f2039204c8f6 301 {
kaizen 0:f2039204c8f6 302 strncpy(_state.mac, buf, sizeof(_state.mac));
kaizen 0:f2039204c8f6 303 _state.mac[17] = 0;
kaizen 0:f2039204c8f6 304 _state.res = RES_NULL;
kaizen 0:f2039204c8f6 305 //DBG("mac %s\r\n", _state.mac);
kaizen 0:f2039204c8f6 306 }
kaizen 0:f2039204c8f6 307 }
kaizen 0:f2039204c8f6 308
kaizen 0:f2039204c8f6 309 void WizFi250::resWJOIN (const char *buf)
kaizen 0:f2039204c8f6 310 {
kaizen 0:f2039204c8f6 311 const char *tmp;
kaizen 0:f2039204c8f6 312 int i;
kaizen 0:f2039204c8f6 313
kaizen 0:f2039204c8f6 314
kaizen 0:f2039204c8f6 315 if(_state.n == 0 && strstr(buf, "IP Addr"))
kaizen 0:f2039204c8f6 316 {
kaizen 0:f2039204c8f6 317 tmp = strstr(buf, ":") + 2; // Because space
kaizen 0:f2039204c8f6 318 for(i=0; i<strlen(tmp); i++)
kaizen 0:f2039204c8f6 319 _state.ip[i] = tmp[i];
kaizen 0:f2039204c8f6 320
kaizen 0:f2039204c8f6 321 _state.ip[i] = '\0';
kaizen 0:f2039204c8f6 322 _state.n++;
kaizen 0:f2039204c8f6 323 }
kaizen 0:f2039204c8f6 324
kaizen 0:f2039204c8f6 325 if(_state.n == 1 && strstr(buf, "Gateway"))
kaizen 0:f2039204c8f6 326 {
kaizen 0:f2039204c8f6 327 tmp = strstr(buf, ":") + 2;
kaizen 0:f2039204c8f6 328 for(i=0; i<strlen(tmp); i++)
kaizen 0:f2039204c8f6 329 _state.gateway[i] = tmp[i];
kaizen 0:f2039204c8f6 330
kaizen 0:f2039204c8f6 331 _state.gateway[i] = '\0';
kaizen 0:f2039204c8f6 332 _state.res = RES_NULL;
kaizen 0:f2039204c8f6 333 }
kaizen 0:f2039204c8f6 334 }
kaizen 0:f2039204c8f6 335
kaizen 0:f2039204c8f6 336 void WizFi250::resConnect (const char *buf)
kaizen 0:f2039204c8f6 337 {
kaizen 0:f2039204c8f6 338 int cid;
kaizen 0:f2039204c8f6 339
kaizen 0:f2039204c8f6 340 if (strncmp(buf,"[OK]",4) == 0)
kaizen 0:f2039204c8f6 341 _state.n++;
kaizen 0:f2039204c8f6 342 else if( strncmp(buf,"[CONNECT",8) == 0 )
kaizen 0:f2039204c8f6 343 {
kaizen 0:f2039204c8f6 344 cid = x2i(buf[9]);
kaizen 0:f2039204c8f6 345 initCon(cid, true);
kaizen 0:f2039204c8f6 346 _state.cid = cid;
kaizen 0:f2039204c8f6 347 _state.res = RES_NULL;
kaizen 0:f2039204c8f6 348 _state.n++;
kaizen 0:f2039204c8f6 349
kaizen 0:f2039204c8f6 350 // for debuging
kaizen 0:f2039204c8f6 351 // _state.dummyBuf[0] = buf[9];
kaizen 0:f2039204c8f6 352 // _state.dummyBuf[1] = '\0';
kaizen 0:f2039204c8f6 353 }
kaizen 0:f2039204c8f6 354
kaizen 0:f2039204c8f6 355 if(_state.n == 2)
kaizen 0:f2039204c8f6 356 {
kaizen 0:f2039204c8f6 357 _state.ok = true;
kaizen 0:f2039204c8f6 358 }
kaizen 0:f2039204c8f6 359 }
kaizen 0:f2039204c8f6 360
kaizen 0:f2039204c8f6 361 void WizFi250::resSSEND (const char *buf)
kaizen 0:f2039204c8f6 362 {
kaizen 0:f2039204c8f6 363
kaizen 0:f2039204c8f6 364 if(_state.cid != -1)
kaizen 0:f2039204c8f6 365 {
kaizen 0:f2039204c8f6 366 // sprintf(dummyBuf,"[%d,,,%d]",_state.cid, _con[_state.cid].length);
kaizen 0:f2039204c8f6 367
kaizen 0:f2039204c8f6 368 // if (strncmp(buf,dummyBuf,strlen(dummyBuf)) == 0)
kaizen 0:f2039204c8f6 369 // {
kaizen 0:f2039204c8f6 370 // strncpy(_state.dummyBuf,dummyBuf,strlen(dummyBuf));
kaizen 0:f2039204c8f6 371 _state.res = RES_NULL;
kaizen 0:f2039204c8f6 372 _state.ok = true;
kaizen 0:f2039204c8f6 373 // }
kaizen 0:f2039204c8f6 374 }
kaizen 0:f2039204c8f6 375 }
kaizen 0:f2039204c8f6 376
kaizen 0:f2039204c8f6 377 void WizFi250::resFDNS (const char *buf)
kaizen 0:f2039204c8f6 378 {
kaizen 0:f2039204c8f6 379 int i;
kaizen 0:f2039204c8f6 380
kaizen 0:f2039204c8f6 381 for(i=0; i<strlen(buf); i++)
kaizen 0:f2039204c8f6 382 {
kaizen 0:f2039204c8f6 383 if( (buf[i] < '0' || buf[i] > '9') && buf[i] != '.' )
kaizen 0:f2039204c8f6 384 {
kaizen 0:f2039204c8f6 385 return;
kaizen 0:f2039204c8f6 386 }
kaizen 0:f2039204c8f6 387 }
kaizen 0:f2039204c8f6 388
kaizen 0:f2039204c8f6 389 strncpy(_state.resolv, buf, sizeof(_state.resolv));
kaizen 0:f2039204c8f6 390 _state.res = RES_NULL;
kaizen 0:f2039204c8f6 391 }
kaizen 0:f2039204c8f6 392
kaizen 0:f2039204c8f6 393 void WizFi250::resSMGMT (const char *buf)
kaizen 0:f2039204c8f6 394 {
kaizen 0:f2039204c8f6 395 int cid, i;
kaizen 0:f2039204c8f6 396 char *c;
kaizen 0:f2039204c8f6 397
kaizen 0:f2039204c8f6 398 if( (buf[0] < '0' || buf[0] > '8') ) return;
kaizen 0:f2039204c8f6 399
kaizen 0:f2039204c8f6 400 cid = x2i(buf[0]);
kaizen 0:f2039204c8f6 401 if( cid != _state.cid ) return;
kaizen 0:f2039204c8f6 402
kaizen 0:f2039204c8f6 403 // IP
kaizen 0:f2039204c8f6 404 c = (char*)(buf+6);
kaizen 0:f2039204c8f6 405 for( i=0; i<16; i++ )
kaizen 0:f2039204c8f6 406 {
kaizen 0:f2039204c8f6 407 if( *(c+i) == ':')
kaizen 0:f2039204c8f6 408 {
kaizen 0:f2039204c8f6 409 _con[cid].ip[i] = '\0';
kaizen 0:f2039204c8f6 410 i++;
kaizen 0:f2039204c8f6 411 break;
kaizen 0:f2039204c8f6 412 }
kaizen 0:f2039204c8f6 413 if( ( *(c+i) < '0' || *(c+i) > '9') && *(c+i) != '.' ) return;
kaizen 0:f2039204c8f6 414 _con[cid].ip[i] = *(c+i);
kaizen 0:f2039204c8f6 415 }
kaizen 0:f2039204c8f6 416
kaizen 0:f2039204c8f6 417 // Port
kaizen 0:f2039204c8f6 418 c = (c+i);
kaizen 0:f2039204c8f6 419 _con[cid].port = 0;
kaizen 0:f2039204c8f6 420 for( i=0; i<5; i++ )
kaizen 0:f2039204c8f6 421 {
kaizen 0:f2039204c8f6 422 if( *(c+i) == '/') break;
kaizen 0:f2039204c8f6 423 if( *(c+i) < '0' || *(c+i) > '9' ) return;
kaizen 0:f2039204c8f6 424
kaizen 0:f2039204c8f6 425 _con[cid].port = (_con[cid].port * 10) + ( *(c+i) - '0' );
kaizen 0:f2039204c8f6 426 }
kaizen 0:f2039204c8f6 427
kaizen 0:f2039204c8f6 428 _state.res = RES_NULL;
kaizen 0:f2039204c8f6 429 }