Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of PicoTCP by
pico_socket.h
00001 /********************************************************************* 00002 PicoTCP. Copyright (c) 2012 TASS Belgium NV. Some rights reserved. 00003 See LICENSE and COPYING for usage. 00004 00005 *********************************************************************/ 00006 #ifndef _INCLUDE_PICO_SOCKET 00007 #define _INCLUDE_PICO_SOCKET 00008 #include "pico_queue.h" 00009 #include "pico_addressing.h" 00010 #include "pico_config.h" 00011 #include "pico_protocol.h" 00012 00013 //#define PICO_DEFAULT_SOCKETQ (128 * 1024) 00014 #define PICO_DEFAULT_SOCKETQ (4 * 1024) 00015 00016 #define PICO_SHUT_RD 1 00017 #define PICO_SHUT_WR 2 00018 #define PICO_SHUT_RDWR 3 00019 00020 00021 struct pico_socket { 00022 struct pico_protocol *proto; 00023 struct pico_protocol *net; 00024 00025 union { 00026 struct pico_ip4 ip4; 00027 struct pico_ip6 ip6; 00028 } local_addr; 00029 00030 union { 00031 struct pico_ip4 ip4; 00032 struct pico_ip6 ip6; 00033 } remote_addr; 00034 00035 uint16_t local_port; 00036 uint16_t remote_port; 00037 00038 struct pico_queue q_in; 00039 struct pico_queue q_out; 00040 00041 void (*wakeup)(uint16_t ev, struct pico_socket *s); 00042 00043 00044 #ifdef PICO_SUPPORT_TCP 00045 /* For the TCP backlog queue */ 00046 struct pico_socket *backlog; 00047 struct pico_socket *next; 00048 struct pico_socket *parent; 00049 int max_backlog; 00050 #endif 00051 #ifdef PICO_SUPPORT_MCAST 00052 struct pico_tree *MCASTListen; 00053 #endif 00054 uint16_t ev_pending; 00055 00056 struct pico_device *dev; 00057 00058 /* Private field. */ 00059 int id; 00060 uint16_t state; 00061 uint16_t opt_flags; 00062 void *priv; 00063 }; 00064 00065 struct pico_remote_duple { 00066 union { 00067 struct pico_ip4 ip4; 00068 struct pico_ip6 ip6; 00069 } remote_addr; 00070 00071 uint16_t remote_port; 00072 }; 00073 00074 00075 /* request struct for multicast socket opt */ 00076 struct pico_ip_mreq { 00077 struct pico_ip4 mcast_group_addr; 00078 struct pico_ip4 mcast_link_addr; 00079 }; 00080 00081 struct pico_ip_mreq_source { 00082 struct pico_ip4 mcast_group_addr; 00083 struct pico_ip4 mcast_source_addr; 00084 struct pico_ip4 mcast_link_addr; 00085 }; 00086 00087 #define PICO_SOCKET_STATE_UNDEFINED 0x0000 00088 #define PICO_SOCKET_STATE_SHUT_LOCAL 0x0001 00089 #define PICO_SOCKET_STATE_SHUT_REMOTE 0x0002 00090 #define PICO_SOCKET_STATE_BOUND 0x0004 00091 #define PICO_SOCKET_STATE_CONNECTED 0x0008 00092 #define PICO_SOCKET_STATE_CLOSING 0x0010 00093 #define PICO_SOCKET_STATE_CLOSED 0x0020 00094 00095 # define PICO_SOCKET_STATE_TCP 0xFF00 00096 # define PICO_SOCKET_STATE_TCP_UNDEF 0x00FF 00097 # define PICO_SOCKET_STATE_TCP_CLOSED 0x0100 00098 # define PICO_SOCKET_STATE_TCP_LISTEN 0x0200 00099 # define PICO_SOCKET_STATE_TCP_SYN_SENT 0x0300 00100 # define PICO_SOCKET_STATE_TCP_SYN_RECV 0x0400 00101 # define PICO_SOCKET_STATE_TCP_ESTABLISHED 0x0500 00102 # define PICO_SOCKET_STATE_TCP_CLOSE_WAIT 0x0600 00103 # define PICO_SOCKET_STATE_TCP_LAST_ACK 0x0700 00104 # define PICO_SOCKET_STATE_TCP_FIN_WAIT1 0x0800 00105 # define PICO_SOCKET_STATE_TCP_FIN_WAIT2 0x0900 00106 # define PICO_SOCKET_STATE_TCP_CLOSING 0x0a00 00107 # define PICO_SOCKET_STATE_TCP_TIME_WAIT 0x0b00 00108 # define PICO_SOCKET_STATE_TCP_ARRAYSIZ 0x0c 00109 00110 # define PICO_TCP_NODELAY 1 00111 00112 # define PICO_SOCKET_OPT_TCPNODELAY 0x0000 00113 00114 # define PICO_IP_MULTICAST_EXCLUDE 0 00115 # define PICO_IP_MULTICAST_INCLUDE 1 00116 # define PICO_IP_MULTICAST_IF 32 00117 # define PICO_IP_MULTICAST_TTL 33 00118 # define PICO_IP_MULTICAST_LOOP 34 00119 # define PICO_IP_ADD_MEMBERSHIP 35 00120 # define PICO_IP_DROP_MEMBERSHIP 36 00121 # define PICO_IP_UNBLOCK_SOURCE 37 00122 # define PICO_IP_BLOCK_SOURCE 38 00123 # define PICO_IP_ADD_SOURCE_MEMBERSHIP 39 00124 # define PICO_IP_DROP_SOURCE_MEMBERSHIP 40 00125 00126 # define PICO_SOCKET_OPT_MULTICAST_LOOP 1 00127 00128 # define PICO_IP_DEFAULT_MULTICAST_TTL 1 00129 # define PICO_IP_DEFAULT_MULTICAST_LOOP 1 00130 00131 #define PICO_SOCKET_SHUTDOWN_WRITE 0x01 00132 #define PICO_SOCKET_SHUTDOWN_READ 0x02 00133 #define TCPSTATE(s) ((s)->state & PICO_SOCKET_STATE_TCP) 00134 00135 #define PICO_SOCK_EV_RD 1 00136 #define PICO_SOCK_EV_WR 2 00137 #define PICO_SOCK_EV_CONN 4 00138 #define PICO_SOCK_EV_CLOSE 8 00139 #define PICO_SOCK_EV_FIN 0x10 00140 #define PICO_SOCK_EV_ERR 0x80 00141 00142 00143 struct pico_socket *pico_socket_open(uint16_t net, uint16_t proto, void (*wakeup)(uint16_t ev, struct pico_socket *s)); 00144 00145 int pico_socket_read(struct pico_socket *s, void *buf, int len); 00146 int pico_socket_write(struct pico_socket *s, void *buf, int len); 00147 00148 int pico_socket_sendto(struct pico_socket *s, void *buf, int len, void *dst, uint16_t remote_port); 00149 int pico_socket_recvfrom(struct pico_socket *s, void *buf, int len, void *orig, uint16_t *local_port); 00150 00151 int pico_socket_send(struct pico_socket *s, void *buf, int len); 00152 int pico_socket_recv(struct pico_socket *s, void *buf, int len); 00153 00154 int pico_socket_bind(struct pico_socket *s, void *local_addr, uint16_t *port); 00155 int pico_socket_connect(struct pico_socket *s, void *srv_addr, uint16_t remote_port); 00156 int pico_socket_listen(struct pico_socket *s, int backlog); 00157 struct pico_socket *pico_socket_accept(struct pico_socket *s, void *orig, uint16_t *port); 00158 int pico_socket_del(struct pico_socket *s); 00159 00160 int pico_socket_setoption(struct pico_socket *s, int option, void *value); 00161 int pico_socket_getoption(struct pico_socket *s, int option, void *value); 00162 00163 int pico_socket_shutdown(struct pico_socket *s, int mode); 00164 int pico_socket_close(struct pico_socket *s); 00165 00166 struct pico_frame *pico_socket_frame_alloc(struct pico_socket *s, int len); 00167 00168 #ifdef PICO_SUPPORT_IPV4 00169 # define is_sock_ipv4(x) (x->net == &pico_proto_ipv4) 00170 #else 00171 # define is_sock_ipv4(x) (0) 00172 #endif 00173 00174 #ifdef PICO_SUPPORT_IPV6 00175 # define is_sock_ipv6(x) (x->net == &pico_proto_ipv6) 00176 #else 00177 # define is_sock_ipv6(x) (0) 00178 #endif 00179 00180 #ifdef PICO_SUPPORT_UDP 00181 # define is_sock_udp(x) (x->net == &pico_proto_udp) 00182 #else 00183 # define is_sock_udp(x) (0) 00184 #endif 00185 00186 #ifdef PICO_SUPPORT_TCP 00187 # define is_sock_tcp(x) (x->net == &pico_proto_tcp) 00188 #else 00189 # define is_sock_tcp(x) (0) 00190 #endif 00191 00192 /* Interface towards transport protocol */ 00193 int pico_transport_process_in(struct pico_protocol *self, struct pico_frame *f); 00194 struct pico_socket *pico_socket_clone(struct pico_socket *facsimile); 00195 int pico_socket_add(struct pico_socket *s); 00196 int pico_transport_error(struct pico_frame *f, uint8_t proto, int code); 00197 00198 /* Socket loop */ 00199 int pico_sockets_loop(int loop_score); 00200 00201 /* Port check */ 00202 int pico_is_port_free(uint16_t proto, uint16_t port, void *addr, void *net); 00203 00204 00205 #endif
Generated on Thu Jul 14 2022 08:24:59 by
1.7.2
