at_socket_ml305.c 19 KB

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