2018-07-17 20:29:33 +08:00
|
|
|
/*
|
2021-03-08 18:19:04 +08:00
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
2018-07-17 20:29:33 +08:00
|
|
|
*
|
2018-10-15 01:23:33 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2018-07-17 20:29:33 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2018-06-06 ChenYong First version
|
|
|
|
*/
|
|
|
|
|
2018-08-27 19:50:37 +08:00
|
|
|
#include <rtthread.h>
|
|
|
|
|
2018-07-17 20:29:33 +08:00
|
|
|
#include <netdb.h>
|
2022-05-16 09:05:50 +08:00
|
|
|
#include <sal_low_lvl.h>
|
2018-07-17 20:29:33 +08:00
|
|
|
|
|
|
|
#include <at_socket.h>
|
2018-08-24 20:39:10 +08:00
|
|
|
#include <af_inet.h>
|
2018-07-17 20:29:33 +08:00
|
|
|
|
2019-04-16 18:24:55 +08:00
|
|
|
#include <netdev.h>
|
|
|
|
|
2018-07-17 20:29:33 +08:00
|
|
|
#ifdef SAL_USING_POSIX
|
2021-09-11 23:48:14 +08:00
|
|
|
#include <poll.h>
|
2018-07-17 20:29:33 +08:00
|
|
|
#endif
|
|
|
|
|
2018-10-16 10:31:06 +08:00
|
|
|
#ifdef SAL_USING_AT
|
|
|
|
|
2018-07-17 20:29:33 +08:00
|
|
|
#ifdef SAL_USING_POSIX
|
2023-04-08 22:25:51 +08:00
|
|
|
static int at_poll(struct dfs_file *file, struct rt_pollreq *req)
|
2018-07-17 20:29:33 +08:00
|
|
|
{
|
|
|
|
int mask = 0;
|
|
|
|
struct at_socket *sock;
|
|
|
|
struct sal_socket *sal_sock;
|
|
|
|
|
|
|
|
sal_sock = sal_get_socket((int) file->data);
|
|
|
|
if(!sal_sock)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
sock = at_get_socket((int)sal_sock->user_data);
|
|
|
|
if (sock != NULL)
|
|
|
|
{
|
|
|
|
rt_base_t level;
|
|
|
|
|
|
|
|
rt_poll_add(&sock->wait_head, req);
|
|
|
|
|
|
|
|
level = rt_hw_interrupt_disable();
|
|
|
|
if (sock->rcvevent)
|
|
|
|
{
|
|
|
|
mask |= POLLIN;
|
|
|
|
}
|
|
|
|
if (sock->sendevent)
|
|
|
|
{
|
|
|
|
mask |= POLLOUT;
|
|
|
|
}
|
|
|
|
if (sock->errevent)
|
|
|
|
{
|
|
|
|
mask |= POLLERR;
|
|
|
|
}
|
|
|
|
rt_hw_interrupt_enable(level);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-11-15 14:39:31 +08:00
|
|
|
static const struct sal_socket_ops at_socket_ops =
|
2018-07-17 20:29:33 +08:00
|
|
|
{
|
|
|
|
at_socket,
|
|
|
|
at_closesocket,
|
|
|
|
at_bind,
|
2022-06-02 19:47:12 +08:00
|
|
|
#ifdef AT_USING_SOCKET_SERVER
|
|
|
|
at_listen,
|
|
|
|
#else
|
2018-07-17 20:29:33 +08:00
|
|
|
NULL,
|
2022-06-02 19:47:12 +08:00
|
|
|
#endif
|
2018-07-17 20:29:33 +08:00
|
|
|
at_connect,
|
2022-06-02 19:47:12 +08:00
|
|
|
#ifdef AT_USING_SOCKET_SERVER
|
|
|
|
at_accept,
|
|
|
|
#else
|
2018-07-17 20:29:33 +08:00
|
|
|
NULL,
|
2022-06-02 19:47:12 +08:00
|
|
|
#endif
|
2018-07-17 20:29:33 +08:00
|
|
|
at_sendto,
|
|
|
|
at_recvfrom,
|
|
|
|
at_getsockopt,
|
|
|
|
at_setsockopt,
|
|
|
|
at_shutdown,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
#ifdef SAL_USING_POSIX
|
|
|
|
at_poll,
|
|
|
|
#endif /* SAL_USING_POSIX */
|
|
|
|
};
|
|
|
|
|
2021-03-08 18:19:04 +08:00
|
|
|
static const struct sal_netdb_ops at_netdb_ops =
|
2018-11-15 14:39:31 +08:00
|
|
|
{
|
2018-07-17 20:29:33 +08:00
|
|
|
at_gethostbyname,
|
|
|
|
NULL,
|
|
|
|
at_getaddrinfo,
|
2018-11-15 14:39:31 +08:00
|
|
|
at_freeaddrinfo,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct sal_proto_family at_inet_family =
|
|
|
|
{
|
|
|
|
AF_AT,
|
|
|
|
AF_INET,
|
2019-04-16 18:24:55 +08:00
|
|
|
&at_socket_ops,
|
|
|
|
&at_netdb_ops,
|
2018-07-17 20:29:33 +08:00
|
|
|
};
|
|
|
|
|
2019-04-16 18:24:55 +08:00
|
|
|
|
|
|
|
/* Set AT network interface device protocol family information */
|
|
|
|
int sal_at_netdev_set_pf_info(struct netdev *netdev)
|
2018-07-17 20:29:33 +08:00
|
|
|
{
|
2019-04-16 18:24:55 +08:00
|
|
|
RT_ASSERT(netdev);
|
2018-07-17 20:29:33 +08:00
|
|
|
|
2019-04-16 18:24:55 +08:00
|
|
|
netdev->sal_user_data = (void *) &at_inet_family;
|
2018-07-17 20:29:33 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2018-10-16 10:31:06 +08:00
|
|
|
|
|
|
|
#endif /* SAL_USING_AT */
|