at_socket_n21.c 19 KB

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