af_inet_at.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (c) 2006-2018, 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.h>
  13. #include <at_socket.h>
  14. #include <af_inet.h>
  15. #include <netdev.h>
  16. #ifdef SAL_USING_POSIX
  17. #include <dfs_poll.h>
  18. #endif
  19. #ifdef SAL_USING_AT
  20. #ifdef SAL_USING_POSIX
  21. static int at_poll(struct dfs_fd *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. NULL,
  60. at_connect,
  61. NULL,
  62. at_sendto,
  63. at_recvfrom,
  64. at_getsockopt,
  65. at_setsockopt,
  66. at_shutdown,
  67. NULL,
  68. NULL,
  69. NULL,
  70. #ifdef SAL_USING_POSIX
  71. at_poll,
  72. #endif /* SAL_USING_POSIX */
  73. };
  74. static const struct sal_netdb_ops at_netdb_ops =
  75. {
  76. at_gethostbyname,
  77. NULL,
  78. at_getaddrinfo,
  79. at_freeaddrinfo,
  80. };
  81. static const struct sal_proto_family at_inet_family =
  82. {
  83. AF_AT,
  84. AF_INET,
  85. &at_socket_ops,
  86. &at_netdb_ops,
  87. };
  88. /* Set AT network interface device protocol family information */
  89. int sal_at_netdev_set_pf_info(struct netdev *netdev)
  90. {
  91. RT_ASSERT(netdev);
  92. netdev->sal_user_data = (void *) &at_inet_family;
  93. return 0;
  94. }
  95. #endif /* SAL_USING_AT */