at_socket_air720.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-06-12 malongwei first version
  9. * 2019-05-13 chenyong multi AT socket client support
  10. */
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include <at_device_air720.h>
  14. #if !defined(AT_SW_VERSION_NUM) || AT_SW_VERSION_NUM < 0x10300
  15. #error "This AT Client version is older, please check and update latest AT Client!"
  16. #endif
  17. #define LOG_TAG "at.skt"
  18. #include <at_log.h>
  19. #if defined(AT_DEVICE_USING_AIR720) && defined(AT_USING_SOCKET)
  20. #define AIR720_MODULE_SEND_MAX_SIZE 1000
  21. /* set real event by current socket and current state */
  22. #define SET_EVENT(socket, event) (((socket + 1) << 16) | (event))
  23. /* AT socket event type */
  24. #define AIR720_EVENT_CONN_OK (1L << 0)
  25. #define AIR720_EVENT_SEND_OK (1L << 1)
  26. #define AIR720_EVENT_RECV_OK (1L << 2)
  27. #define AIR720_EVNET_CLOSE_OK (1L << 3)
  28. #define AIR720_EVENT_CONN_FAIL (1L << 4)
  29. #define AIR720_EVENT_SEND_FAIL (1L << 5)
  30. static at_evt_cb_t at_evt_cb_set[] = {
  31. [AT_SOCKET_EVT_RECV] = NULL,
  32. [AT_SOCKET_EVT_CLOSED] = NULL,
  33. };
  34. static int air720_socket_event_send(struct at_device *device, uint32_t event)
  35. {
  36. return (int)rt_event_send(device->socket_event, event);
  37. }
  38. static int air720_socket_event_recv(struct at_device *device, uint32_t event, uint32_t timeout, rt_uint8_t option)
  39. {
  40. int result = RT_EOK;
  41. rt_uint32_t recved;
  42. result = rt_event_recv(device->socket_event, event, option | RT_EVENT_FLAG_CLEAR, timeout, &recved);
  43. if (result != RT_EOK)
  44. {
  45. return -RT_ETIMEOUT;
  46. }
  47. return recved;
  48. }
  49. /**
  50. * close socket by AT commands.
  51. *
  52. * @param current socket
  53. *
  54. * @return 0: close socket success
  55. * -1: send AT commands error
  56. * -2: wait socket event timeout
  57. * -5: no memory
  58. */
  59. static int air720_socket_close(struct at_socket *socket)
  60. {
  61. uint32_t event = 0;
  62. int result = RT_EOK;
  63. int device_socket = (int)socket->user_data;
  64. struct at_device *device = (struct at_device *)socket->device;
  65. /* clear socket close event */
  66. event = SET_EVENT(device_socket, AIR720_EVNET_CLOSE_OK);
  67. air720_socket_event_recv(device, event, 0, RT_EVENT_FLAG_OR);
  68. if (at_obj_exec_cmd(device->client, NULL, "AT+CIPCLOSE=%d", device_socket) < 0)
  69. {
  70. result = -RT_ERROR;
  71. goto __exit;
  72. }
  73. if (air720_socket_event_recv(device, event, rt_tick_from_millisecond(300 * 3), RT_EVENT_FLAG_AND) < 0)
  74. {
  75. LOG_E("air720 device(%s) socket(%d) close failed, wait close OK timeout.", device->name, device_socket);
  76. result = -RT_ETIMEOUT;
  77. goto __exit;
  78. }
  79. __exit:
  80. return result;
  81. }
  82. /**
  83. * create TCP/UDP client or server connect by AT commands.
  84. *
  85. * @param socket current socket
  86. * @param ip server or client IP address
  87. * @param port server or client port
  88. * @param type connect socket type(tcp, udp)
  89. * @param is_client connection is client
  90. *
  91. * @return 0: connect success
  92. * -1: connect failed, send commands error or type error
  93. * -2: wait socket event timeout
  94. * -5: no memory
  95. */
  96. static int air720_socket_connect(struct at_socket *socket, char *ip, int32_t port, enum at_socket_type type, rt_bool_t is_client)
  97. {
  98. uint32_t event = 0;
  99. rt_bool_t retryed = RT_FALSE;
  100. at_response_t resp = RT_NULL;
  101. int result = RT_EOK, event_result = 0;
  102. int device_socket = (int)socket->user_data;
  103. struct at_device *device = (struct at_device *)socket->device;
  104. RT_ASSERT(ip);
  105. RT_ASSERT(port >= 0);
  106. resp = at_create_resp(128, 0, 5 * RT_TICK_PER_SECOND);
  107. if (resp == RT_NULL)
  108. {
  109. LOG_E("no memory for air720 device(%s) response structure.", device->name);
  110. return -RT_ENOMEM;
  111. }
  112. __retry:
  113. /* clear socket connect event */
  114. event = SET_EVENT(device_socket, AIR720_EVENT_CONN_OK | AIR720_EVENT_CONN_FAIL);
  115. air720_socket_event_recv(device, event, 0, RT_EVENT_FLAG_OR);
  116. if (is_client)
  117. {
  118. switch (type)
  119. {
  120. case AT_SOCKET_TCP:
  121. /* send AT commands(eg: AT+QIOPEN=0,"TCP","x.x.x.x", 1234) to connect TCP server */
  122. if (at_obj_exec_cmd(device->client, RT_NULL,
  123. "AT+CIPSTART=%d,\"TCP\",\"%s\",%d", device_socket, ip, port) < 0)
  124. {
  125. result = -RT_ERROR;
  126. goto __exit;
  127. }
  128. break;
  129. case AT_SOCKET_UDP:
  130. if (at_obj_exec_cmd(device->client, RT_NULL,
  131. "AT+CIPSTART=%d,\"UDP\",\"%s\",%d", device_socket, ip, port) < 0)
  132. {
  133. result = -RT_ERROR;
  134. goto __exit;
  135. }
  136. break;
  137. default:
  138. LOG_E("air720 device(%s) not supported connect type : %d.", device->name, type);
  139. result = -RT_ERROR;
  140. goto __exit;
  141. }
  142. }
  143. /* waiting result event from AT URC, the device default connection timeout is 75 seconds, but it set to 10 seconds is convenient to use */
  144. if (air720_socket_event_recv(device, SET_EVENT(device_socket, 0), 10 * RT_TICK_PER_SECOND, RT_EVENT_FLAG_OR) < 0)
  145. {
  146. LOG_E("air720 device(%s) socket(%d) connect failed, wait connect result timeout.", device->name, device_socket);
  147. result = -RT_ETIMEOUT;
  148. goto __exit;
  149. }
  150. /* waiting OK or failed result */
  151. event_result = air720_socket_event_recv(device,
  152. AIR720_EVENT_CONN_OK | AIR720_EVENT_CONN_FAIL, 1 * RT_TICK_PER_SECOND, RT_EVENT_FLAG_OR);
  153. if (event_result < 0)
  154. {
  155. LOG_E("air720 device(%s) socket(%d) connect failed, wait connect OK|FAIL timeout.", device->name, device_socket);
  156. result = -RT_ETIMEOUT;
  157. goto __exit;
  158. }
  159. /* check result */
  160. if (event_result & AIR720_EVENT_CONN_FAIL)
  161. {
  162. if (retryed == RT_FALSE)
  163. {
  164. LOG_D("air720 device(%s) socket(%d) connect failed, maybe the socket was not be closed at the last time and now will retry.",
  165. device->name, device_socket);
  166. if (air720_socket_close(socket) < 0)
  167. {
  168. result = -RT_ERROR;
  169. goto __exit;
  170. }
  171. retryed = RT_TRUE;
  172. goto __retry;
  173. }
  174. LOG_E("air720 device(%s) socket(%d) connect failed.", device->name, device_socket);
  175. result = -RT_ERROR;
  176. goto __exit;
  177. }
  178. __exit:
  179. if (resp)
  180. {
  181. at_delete_resp(resp);
  182. }
  183. if (result != RT_EOK)
  184. {
  185. }
  186. return result;
  187. }
  188. /**
  189. * send data to server or client by AT commands.
  190. *
  191. * @param socket current socket
  192. * @param buff send buffer
  193. * @param bfsz send buffer size
  194. * @param type connect socket type(tcp, udp)
  195. *
  196. * @return >=0: the size of send success
  197. * -1: send AT commands error or send data error
  198. * -2: waited socket event timeout
  199. * -5: no memory
  200. */
  201. static int air720_socket_send(struct at_socket *socket, const char *buff, size_t bfsz, enum at_socket_type type)
  202. {
  203. uint32_t event = 0;
  204. int result = RT_EOK, event_result = 0;
  205. size_t cur_pkt_size = 0, sent_size = 0;
  206. at_response_t resp = RT_NULL;
  207. int device_socket = (int)socket->user_data;
  208. struct at_device *device = (struct at_device *)socket->device;
  209. rt_mutex_t lock = at_device_get_client_lock(device);
  210. RT_ASSERT(buff);
  211. resp = at_create_resp(128, 2, 5 * RT_TICK_PER_SECOND);
  212. if (resp == RT_NULL)
  213. {
  214. LOG_E("no memory for air720 device(%s) response structure.", device->name);
  215. return -RT_ENOMEM;
  216. }
  217. rt_mutex_take(lock, RT_WAITING_FOREVER);
  218. /* clear socket connect event */
  219. event = SET_EVENT(device_socket, AIR720_EVENT_SEND_OK | AIR720_EVENT_SEND_FAIL);
  220. air720_socket_event_recv(device, event, 0, RT_EVENT_FLAG_OR);
  221. /* set AT client end sign to deal with '>' sign.*/
  222. at_obj_set_end_sign(device->client, '>');
  223. while (sent_size < bfsz)
  224. {
  225. if (bfsz - sent_size < AIR720_MODULE_SEND_MAX_SIZE)
  226. {
  227. cur_pkt_size = bfsz - sent_size;
  228. }
  229. else
  230. {
  231. cur_pkt_size = AIR720_MODULE_SEND_MAX_SIZE;
  232. }
  233. /* send the "AT+QISEND" commands to AT server than receive the '>' response on the first line. */
  234. if (at_obj_exec_cmd(device->client, resp, "AT+CIPSEND=%d,%d", device_socket, cur_pkt_size) < 0)
  235. {
  236. result = -RT_ERROR;
  237. goto __exit;
  238. }
  239. /* send the real data to server or client */
  240. result = (int)at_client_obj_send(device->client, buff + sent_size, cur_pkt_size);
  241. if (result == 0)
  242. {
  243. result = -RT_ERROR;
  244. goto __exit;
  245. }
  246. /* waiting result event from AT URC */
  247. if (air720_socket_event_recv(device, SET_EVENT(device_socket, 0), 15 * RT_TICK_PER_SECOND, RT_EVENT_FLAG_OR) < 0)
  248. {
  249. LOG_E("air720 device(%s) socket(%d) send failed, wait connect result timeout.", device->name, device_socket);
  250. result = -RT_ETIMEOUT;
  251. goto __exit;
  252. }
  253. /* waiting OK or failed result */
  254. event_result = air720_socket_event_recv(device,
  255. AIR720_EVENT_SEND_OK | AIR720_EVENT_SEND_FAIL, 5 * RT_TICK_PER_SECOND, RT_EVENT_FLAG_OR);
  256. if (event_result < 0)
  257. {
  258. LOG_E("air720 device(%s) socket(%d) send failed, wait connect OK|FAIL timeout.", device->name, device_socket);
  259. result = -RT_ETIMEOUT;
  260. goto __exit;
  261. }
  262. /* check result */
  263. if (event_result & AIR720_EVENT_SEND_FAIL)
  264. {
  265. LOG_E("air720 device(%s) socket(%d) send failed.", device->name, device_socket);
  266. result = -RT_ERROR;
  267. goto __exit;
  268. }
  269. sent_size += cur_pkt_size;
  270. }
  271. __exit:
  272. /* reset the end sign for data conflict */
  273. at_obj_set_end_sign(device->client, 0);
  274. rt_mutex_release(lock);
  275. if (resp)
  276. {
  277. at_delete_resp(resp);
  278. }
  279. return result > 0 ? sent_size : result;
  280. }
  281. /**
  282. * domain resolve by AT commands.
  283. *
  284. * @param name domain name
  285. * @param ip parsed IP address, it's length must be 16
  286. *
  287. * @return 0: domain resolve success
  288. * -1: send AT commands error or response error
  289. * -2: wait socket event timeout
  290. * -5: no memory
  291. */
  292. static int air720_domain_resolve(const char *name, char ip[16])
  293. {
  294. #define RESOLVE_RETRY 5
  295. int i, result = RT_EOK;
  296. char recv_ip[16] = {0};
  297. at_response_t resp = RT_NULL;
  298. struct at_device *device = RT_NULL;
  299. RT_ASSERT(name);
  300. RT_ASSERT(ip);
  301. device = at_device_get_first_initialized();
  302. if (device == RT_NULL)
  303. {
  304. LOG_E("get first initialization air720 device failed.");
  305. return -RT_ERROR;
  306. }
  307. /* The maximum response time is 14 seconds, affected by network status */
  308. resp = at_create_resp(128, 4, 14 * RT_TICK_PER_SECOND);
  309. if (resp == RT_NULL)
  310. {
  311. LOG_E("no memory for air720 device(%s) response structure.", device->name);
  312. return -RT_ENOMEM;
  313. }
  314. for (i = 0; i < RESOLVE_RETRY; i++)
  315. {
  316. int err_code = 0;
  317. if (at_obj_exec_cmd(device->client, resp, "AT+CDNSGIP=\"%s\"", name) < 0)
  318. {
  319. result = -RT_ERROR;
  320. goto __exit;
  321. }
  322. /* domain name prase error options */
  323. if (at_resp_parse_line_args_by_kw(resp, "+CDNSGIP: 0", "+CDNSGIP: 0,%d", &err_code) > 0)
  324. {
  325. /* 3 - network error, 8 - dns common error */
  326. if (err_code == 3 || err_code == 8)
  327. {
  328. result = -RT_ERROR;
  329. goto __exit;
  330. }
  331. }
  332. /* parse the third line of response data, get the IP address */
  333. if (at_resp_parse_line_args_by_kw(resp, "+CDNSGIP:", "%*[^,],%*[^,],\"%[^\"]", recv_ip) < 0)
  334. {
  335. rt_thread_mdelay(100);
  336. /* resolve failed, maybe receive an URC CRLF */
  337. continue;
  338. }
  339. if (rt_strlen(recv_ip) < 8)
  340. {
  341. rt_thread_mdelay(100);
  342. /* resolve failed, maybe receive an URC CRLF */
  343. continue;
  344. }
  345. else
  346. {
  347. rt_thread_mdelay(10);
  348. rt_strncpy(ip, recv_ip, 15);
  349. ip[15] = '\0';
  350. break;
  351. }
  352. }
  353. __exit:
  354. if (resp)
  355. {
  356. at_delete_resp(resp);
  357. }
  358. return result;
  359. }
  360. /**
  361. * set AT socket event notice callback
  362. *
  363. * @param event notice event
  364. * @param cb notice callback
  365. */
  366. static void air720_socket_set_event_cb(at_socket_evt_t event, at_evt_cb_t cb)
  367. {
  368. if (event < sizeof(at_evt_cb_set) / sizeof(at_evt_cb_set[1]))
  369. {
  370. at_evt_cb_set[event] = cb;
  371. }
  372. }
  373. static void urc_connect_func(struct at_client *client, const char *data, rt_size_t size)
  374. {
  375. int device_socket = 0;
  376. struct at_device *device = RT_NULL;
  377. char *client_name = client->device->parent.name;
  378. RT_ASSERT(data && size);
  379. device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
  380. if (device == RT_NULL)
  381. {
  382. LOG_E("get air720 device by client name(%s) failed.", client_name);
  383. return;
  384. }
  385. /* get the current socket by receive data */
  386. rt_sscanf(data, "%d,%*s", &device_socket);
  387. if (strstr(data, "CONNECT OK"))
  388. {
  389. air720_socket_event_send(device, SET_EVENT(device_socket, AIR720_EVENT_CONN_OK));
  390. }
  391. else if (strstr(data, "CONNECT FAIL"))
  392. {
  393. air720_socket_event_send(device, SET_EVENT(device_socket, AIR720_EVENT_CONN_FAIL));
  394. }
  395. }
  396. static void urc_send_func(struct at_client *client, const char *data, rt_size_t size)
  397. {
  398. int device_socket = 0;
  399. struct at_device *device = RT_NULL;
  400. char *client_name = client->device->parent.name;
  401. RT_ASSERT(data && size);
  402. device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
  403. if (device == RT_NULL)
  404. {
  405. LOG_E("get air720 device by client name(%s) failed.", client_name);
  406. return;
  407. }
  408. /* get the current socket by receive data */
  409. rt_sscanf(data, "%d,%*s", &device_socket);
  410. if (rt_strstr(data, "SEND OK"))
  411. {
  412. air720_socket_event_send(device, SET_EVENT(device_socket, AIR720_EVENT_SEND_OK));
  413. }
  414. else if (rt_strstr(data, "SEND FAIL"))
  415. {
  416. air720_socket_event_send(device, SET_EVENT(device_socket, AIR720_EVENT_SEND_FAIL));
  417. }
  418. }
  419. static void urc_close_func(struct at_client *client, const char *data, rt_size_t size)
  420. {
  421. int device_socket = 0;
  422. struct at_device *device = RT_NULL;
  423. char *client_name = client->device->parent.name;
  424. RT_ASSERT(data && size);
  425. device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
  426. if (device == RT_NULL)
  427. {
  428. LOG_E("get air720 device by client name(%s) failed.", client_name);
  429. return;
  430. }
  431. /* get the current socket by receive data */
  432. rt_sscanf(data, "%d,%*s", &device_socket);
  433. if (rt_strstr(data, "CLOSE OK"))
  434. {
  435. air720_socket_event_send(device, SET_EVENT(device_socket, AIR720_EVNET_CLOSE_OK));
  436. }
  437. else if (rt_strstr(data, "CLOSED"))
  438. {
  439. struct at_socket *socket = RT_NULL;
  440. /* get AT socket object by device socket descriptor */
  441. socket = &(device->sockets[device_socket]);
  442. /* notice the socket is disconnect by remote */
  443. if (at_evt_cb_set[AT_SOCKET_EVT_CLOSED])
  444. {
  445. at_evt_cb_set[AT_SOCKET_EVT_CLOSED](socket, AT_SOCKET_EVT_CLOSED, RT_NULL, 0);
  446. }
  447. }
  448. }
  449. static void urc_recv_func(struct at_client *client, const char *data, rt_size_t size)
  450. {
  451. int device_socket = 0;
  452. rt_int32_t timeout;
  453. rt_size_t bfsz = 0, temp_size = 0;
  454. char *recv_buf = RT_NULL, temp[8] = {0};
  455. struct at_socket *socket = RT_NULL;
  456. struct at_device *device = RT_NULL;
  457. char *client_name = client->device->parent.name;
  458. RT_ASSERT(data && size);
  459. //LOG_I("get +receive data %s", data);
  460. /* get the current socket and receive buffer size by receive data */
  461. rt_sscanf(data, "%*[^,],%d,%d:", &device_socket, (int *)&bfsz);
  462. // rt_sscanf(data, "+RECEIVE,%d,%d:", &device_socket, (int *)&bfsz);
  463. /* get receive timeout by receive buffer length */
  464. timeout = bfsz;
  465. if (device_socket < 0 || bfsz == 0)
  466. {
  467. return;
  468. }
  469. device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
  470. if (device == RT_NULL)
  471. {
  472. LOG_E("get air720 device by client name(%s) failed.", client_name);
  473. return;
  474. }
  475. recv_buf = (char *)rt_calloc(1, bfsz);
  476. if (recv_buf == RT_NULL)
  477. {
  478. LOG_E("no memory for air720 device(%s) URC receive buffer (%d).", device->name, bfsz);
  479. /* read and clean the coming data */
  480. while (temp_size < bfsz)
  481. {
  482. if (bfsz - temp_size > sizeof(temp))
  483. {
  484. at_client_obj_recv(client, temp, sizeof(temp), timeout);
  485. }
  486. else
  487. {
  488. at_client_obj_recv(client, temp, bfsz - temp_size, timeout);
  489. }
  490. temp_size += sizeof(temp);
  491. }
  492. return;
  493. }
  494. /* sync receive data */
  495. if (at_client_obj_recv(client, recv_buf, bfsz, timeout) != bfsz)
  496. {
  497. LOG_E("air720 device(%s) receive size(%d) data failed.", device->name, bfsz);
  498. rt_free(recv_buf);
  499. return;
  500. }
  501. /* get AT socket object by device socket descriptor */
  502. socket = &(device->sockets[device_socket]);
  503. /* notice the receive buffer and buffer size */
  504. if (at_evt_cb_set[AT_SOCKET_EVT_RECV])
  505. {
  506. at_evt_cb_set[AT_SOCKET_EVT_RECV](socket, AT_SOCKET_EVT_RECV, recv_buf, bfsz);
  507. }
  508. }
  509. static void urc_dataaccept_func(struct at_client *client, const char *data, rt_size_t size)
  510. {
  511. RT_ASSERT(data && size);
  512. int device_socket = 0;
  513. rt_size_t bfsz = 0;
  514. struct at_device *device = RT_NULL;
  515. char *client_name = client->device->parent.name;
  516. RT_ASSERT(data && size);
  517. device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
  518. if (device == RT_NULL)
  519. {
  520. LOG_E("get air720 device by client name(%s) failed.", client_name);
  521. return;
  522. }
  523. /* get the current socket by receive data */
  524. rt_sscanf(data, "DATA ACCEPT:%d,%d", &device_socket, (int *)&bfsz);
  525. air720_socket_event_send(device, SET_EVENT(device_socket, AIR720_EVENT_SEND_OK));
  526. }
  527. //DATA ACCEPT:
  528. /* air720 device URC table for the socket data */
  529. static const struct at_urc urc_table[] =
  530. {
  531. {"", ", CONNECT OK\r\n", urc_connect_func},
  532. {"", ", CONNECT FAIL\r\n", urc_connect_func},
  533. {"", ", SEND OK\r\n", urc_send_func},
  534. {"", ", SEND FAIL\r\n", urc_send_func},
  535. {"", ", CLOSE OK\r\n", urc_close_func},
  536. {"", ", CLOSED\r\n", urc_close_func},
  537. {"ECEIVE,", "\r\n", urc_recv_func},
  538. {"+RECEIVE,", "\r\n", urc_recv_func},
  539. {"DATA ACCEPT:", "\r\n", urc_dataaccept_func},
  540. };
  541. static const struct at_socket_ops air720_socket_ops =
  542. {
  543. air720_socket_connect,
  544. air720_socket_close,
  545. air720_socket_send,
  546. air720_domain_resolve,
  547. air720_socket_set_event_cb,
  548. #if defined(AT_SW_VERSION_NUM) && AT_SW_VERSION_NUM > 0x10300
  549. RT_NULL,
  550. #endif
  551. };
  552. int air720_socket_init(struct at_device *device)
  553. {
  554. RT_ASSERT(device);
  555. /* register URC data execution function */
  556. at_obj_set_urc_table(device->client, urc_table, sizeof(urc_table) / sizeof(urc_table[0]));
  557. return RT_EOK;
  558. }
  559. int air720_socket_class_register(struct at_device_class *class)
  560. {
  561. RT_ASSERT(class);
  562. class->socket_num = AT_DEVICE_AIR720_SOCKETS_NUM;
  563. class->socket_ops = &air720_socket_ops;
  564. return RT_EOK;
  565. }
  566. #endif /* AT_DEVICE_USING_air720 && AT_USING_SOCKET */