af_inet_at.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-06-06 ChenYong First version
  9. */
  10. #include <rtthread.h>
  11. #include <netdb.h>
  12. #include <sal_low_lvl.h>
  13. #include <at_socket.h>
  14. #include <af_inet.h>
  15. #include <netdev.h>
  16. #ifdef SAL_USING_POSIX
  17. #include <poll.h>
  18. #endif
  19. #ifdef SAL_USING_AT
  20. #ifdef SAL_USING_POSIX
  21. static int at_poll(struct dfs_file *file, struct rt_pollreq *req)
  22. {
  23. int mask = 0;
  24. struct at_socket *sock;
  25. struct sal_socket *sal_sock;
  26. sal_sock = sal_get_socket((int) file->data);
  27. if(!sal_sock)
  28. {
  29. return -1;
  30. }
  31. sock = at_get_socket((int)sal_sock->user_data);
  32. if (sock != NULL)
  33. {
  34. rt_base_t level;
  35. rt_poll_add(&sock->wait_head, req);
  36. level = rt_hw_interrupt_disable();
  37. if (sock->rcvevent)
  38. {
  39. mask |= POLLIN;
  40. }
  41. if (sock->sendevent)
  42. {
  43. mask |= POLLOUT;
  44. }
  45. if (sock->errevent)
  46. {
  47. mask |= POLLERR;
  48. }
  49. rt_hw_interrupt_enable(level);
  50. }
  51. return mask;
  52. }
  53. #endif
  54. static const struct sal_socket_ops at_socket_ops =
  55. {
  56. at_socket,
  57. at_closesocket,
  58. at_bind,
  59. #ifdef AT_USING_SOCKET_SERVER
  60. at_listen,
  61. #else
  62. NULL,
  63. #endif
  64. at_connect,
  65. #ifdef AT_USING_SOCKET_SERVER
  66. at_accept,
  67. #else
  68. NULL,
  69. #endif
  70. at_sendto,
  71. NULL,
  72. NULL,
  73. at_recvfrom,
  74. at_getsockopt,
  75. at_setsockopt,
  76. at_shutdown,
  77. NULL,
  78. NULL,
  79. NULL,
  80. NULL,
  81. #ifdef SAL_USING_POSIX
  82. at_poll,
  83. #endif /* SAL_USING_POSIX */
  84. };
  85. static const struct sal_netdb_ops at_netdb_ops =
  86. {
  87. at_gethostbyname,
  88. NULL,
  89. at_getaddrinfo,
  90. at_freeaddrinfo,
  91. };
  92. static const struct sal_proto_family at_inet_family =
  93. {
  94. AF_AT,
  95. AF_INET,
  96. &at_socket_ops,
  97. &at_netdb_ops,
  98. };
  99. /* Set AT network interface device protocol family information */
  100. int sal_at_netdev_set_pf_info(struct netdev *netdev)
  101. {
  102. RT_ASSERT(netdev);
  103. netdev->sal_user_data = (void *) &at_inet_family;
  104. return 0;
  105. }
  106. #endif /* SAL_USING_AT */