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 11 #include <rtthread.h> 12 13 #include <netdb.h> 14 #include <sal.h> 15 16 #include <at_socket.h> 17 #include <af_inet.h> 18 19 #ifdef SAL_USING_POSIX 20 #include <dfs_poll.h> 21 #endif 22 23 #ifdef SAL_USING_AT 24 25 #ifdef SAL_USING_POSIX 26 static int at_poll(struct dfs_fd *file, struct rt_pollreq *req) 27 { 28 int mask = 0; 29 struct at_socket *sock; 30 struct sal_socket *sal_sock; 31 32 sal_sock = sal_get_socket((int) file->data); 33 if(!sal_sock) 34 { 35 return -1; 36 } 37 38 sock = at_get_socket((int)sal_sock->user_data); 39 if (sock != NULL) 40 { 41 rt_base_t level; 42 43 rt_poll_add(&sock->wait_head, req); 44 45 level = rt_hw_interrupt_disable(); 46 if (sock->rcvevent) 47 { 48 mask |= POLLIN; 49 } 50 if (sock->sendevent) 51 { 52 mask |= POLLOUT; 53 } 54 if (sock->errevent) 55 { 56 mask |= POLLERR; 57 } 58 rt_hw_interrupt_enable(level); 59 } 60 61 return mask; 62 } 63 #endif 64 65 static const struct sal_socket_ops at_socket_ops = 66 { 67 at_socket, 68 at_closesocket, 69 at_bind, 70 NULL, 71 at_connect, 72 NULL, 73 at_sendto, 74 at_recvfrom, 75 at_getsockopt, 76 at_setsockopt, 77 at_shutdown, 78 NULL, 79 NULL, 80 NULL, 81 82 #ifdef SAL_USING_POSIX 83 at_poll, 84 #endif /* SAL_USING_POSIX */ 85 }; 86 87 static int at_create(struct sal_socket *socket, int type, int protocol) 88 { 89 RT_ASSERT(socket); 90 91 //TODO Check type & protocol 92 93 socket->ops = &at_socket_ops; 94 95 return 0; 96 } 97 98 static struct sal_proto_ops at_proto_ops = 99 { 100 at_gethostbyname, 101 NULL, 102 at_getaddrinfo, 103 at_freeaddrinfo, 104 }; 105 106 static const struct sal_proto_family at_inet_family = 107 { 108 AF_AT, 109 AF_INET, 110 at_create, 111 &at_proto_ops, 112 }; 113 114 int at_inet_init(void) 115 { 116 sal_proto_family_register(&at_inet_family); 117 118 return 0; 119 } 120 INIT_COMPONENT_EXPORT(at_inet_init); 121 122 #endif /* SAL_USING_AT */ 123