Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

api.h File Reference

api.h File Reference

netconn API (to be used from non-TCPIP threads) More...

Go to the source code of this file.

Data Structures

struct  netconn
 A netconn descriptor. More...
struct  netvector
 This vector type is passed to netconn_write_vectors_partly to send multiple buffers at once. More...

Typedefs

typedef void(* netconn_callback )(struct netconn *, enum netconn_evt, u16_t len)
 A callback prototype to inform about events for a netconn.

Enumerations

enum  netconn_type { ,
  NETCONN_TCP = 0x10, NETCONN_TCP_IPV6 = NETCONN_TCP | NETCONN_TYPE_IPV6, NETCONN_UDP = 0x20, NETCONN_UDPLITE = 0x21,
  NETCONN_UDPNOCHKSUM = 0x22, NETCONN_UDP_IPV6 = NETCONN_UDP | NETCONN_TYPE_IPV6, NETCONN_UDPLITE_IPV6 = NETCONN_UDPLITE | NETCONN_TYPE_IPV6, NETCONN_UDPNOCHKSUM_IPV6 = NETCONN_UDPNOCHKSUM | NETCONN_TYPE_IPV6,
  NETCONN_RAW
}
 

Protocol family and type of the netconn.

More...
enum  netconn_state
 

Current state of the netconn.

More...
enum  netconn_evt
 

Used to inform the callback function about changes.

More...
enum  netconn_igmp
 

Used for netconn_join_leave_group()

More...

Functions

struct netconnnetconn_new_with_proto_and_callback (enum netconn_type t, u8_t proto, netconn_callback callback)
 Create a new netconn (of a specific type) that has a callback function.
err_t netconn_prepare_delete (struct netconn *conn)
 Close a netconn 'connection' and free all its resources but not the netconn itself.
err_t netconn_delete (struct netconn *conn)
 Close a netconn 'connection' and free its resources.
err_t netconn_getaddr (struct netconn *conn, ip_addr_t *addr, u16_t *port, u8_t local)
 Get the local or remote IP address and port of a netconn.
err_t netconn_bind (struct netconn *conn, const ip_addr_t *addr, u16_t port)
 Bind a netconn to a specific local IP address and port.
err_t netconn_bind_if (struct netconn *conn, u8_t if_idx)
 Bind a netconn to a specific interface and port.
err_t netconn_connect (struct netconn *conn, const ip_addr_t *addr, u16_t port)
 Connect a netconn to a specific remote IP address and port.
err_t netconn_disconnect (struct netconn *conn)
 Disconnect a netconn from its current peer (only valid for UDP netconns).
err_t netconn_listen_with_backlog (struct netconn *conn, u8_t backlog)
 Set a TCP netconn into listen mode.
err_t netconn_accept (struct netconn *conn, struct netconn **new_conn)
 Accept a new connection on a TCP listening netconn.
err_t netconn_recv (struct netconn *conn, struct netbuf **new_buf)
 Receive data (in form of a netbuf containing a packet buffer) from a netconn.
err_t netconn_recv_udp_raw_netbuf (struct netconn *conn, struct netbuf **new_buf)
 Receive data (in form of a netbuf) from a UDP or RAW netconn.
err_t netconn_recv_udp_raw_netbuf_flags (struct netconn *conn, struct netbuf **new_buf, u8_t apiflags)
 Receive data (in form of a netbuf) from a UDP or RAW netconn.
err_t netconn_recv_tcp_pbuf (struct netconn *conn, struct pbuf **new_buf)
 Receive data (in form of a pbuf) from a TCP netconn.
err_t netconn_recv_tcp_pbuf_flags (struct netconn *conn, struct pbuf **new_buf, u8_t apiflags)
 Receive data (in form of a pbuf) from a TCP netconn.
err_t netconn_sendto (struct netconn *conn, struct netbuf *buf, const ip_addr_t *addr, u16_t port)
 Send data (in form of a netbuf) to a specific remote IP address and port.
err_t netconn_send (struct netconn *conn, struct netbuf *buf)
 Send data over a UDP or RAW netconn (that is already connected).
err_t netconn_write_partly (struct netconn *conn, const void *dataptr, size_t size, u8_t apiflags, size_t *bytes_written)
 Send data over a TCP netconn.
err_t netconn_write_vectors_partly (struct netconn *conn, struct netvector *vectors, u16_t vectorcnt, u8_t apiflags, size_t *bytes_written)
 Send vectorized data atomically over a TCP netconn.
err_t netconn_close (struct netconn *conn)
 Close a TCP netconn (doesn't delete it).
err_t netconn_shutdown (struct netconn *conn, u8_t shut_rx, u8_t shut_tx)
 Shut down one or both sides of a TCP netconn (doesn't delete it).
err_t netconn_join_leave_group (struct netconn *conn, const ip_addr_t *multiaddr, const ip_addr_t *netif_addr, enum netconn_igmp join_or_leave)
 Join multicast groups for UDP netconns.
err_t netconn_join_leave_group_netif (struct netconn *conn, const ip_addr_t *multiaddr, u8_t if_idx, enum netconn_igmp join_or_leave)
 Join multicast groups for UDP netconns.
err_t netconn_err (struct netconn *conn)
 Get and reset pending error on a netconn.

Detailed Description

netconn API (to be used from non-TCPIP threads)

Definition in file api.h.


Typedef Documentation

typedef void(* netconn_callback)(struct netconn *, enum netconn_evt, u16_t len)

A callback prototype to inform about events for a netconn.

Definition at line 215 of file api.h.


Enumeration Type Documentation

Used to inform the callback function about changes.

Event explanation:

In the netconn implementation, there are three ways to block a client:

  • accept mbox (sys_arch_mbox_fetch(&conn->acceptmbox, &accept_ptr, 0); in netconn_accept())
  • receive mbox (sys_arch_mbox_fetch(&conn->recvmbox, &buf, 0); in netconn_recv_data())
  • send queue is full (sys_arch_sem_wait(LWIP_API_MSG_SEM(msg), 0); in lwip_netconn_do_write())

The events have to be seen as events signaling the state of these mboxes/semaphores. For non-blocking connections, you need to know in advance whether a call to a netconn function call would block or not, and these events tell you about that.

RCVPLUS events say: Safe to perform a potentially blocking call call once more. They are counted in sockets - three RCVPLUS events for accept mbox means you are safe to call netconn_accept 3 times without being blocked. Same thing for receive mbox.

RCVMINUS events say: Your call to to a possibly blocking function is "acknowledged". Socket implementation decrements the counter.

For TX, there is no need to count, its merely a flag. SENDPLUS means you may send something. SENDPLUS occurs when enough data was delivered to peer so netconn_send() can be called again. A SENDMINUS event occurs when the next call to a netconn_send() would be blocking.

Definition at line 181 of file api.h.

Used for netconn_join_leave_group()

Definition at line 191 of file api.h.

Current state of the netconn.

Non-TCP netconns are always in state NETCONN_NONE!

Definition at line 147 of file api.h.


Function Documentation

err_t netconn_getaddr ( struct netconn conn,
ip_addr_t addr,
u16_t *  port,
u8_t  local 
)

Get the local or remote IP address and port of a netconn.

For RAW netconns, this returns the protocol instead of a port!

Parameters:
connthe netconn to query
addra pointer to which to save the IP address
porta pointer to which to save the port (or protocol for RAW)
local1 to get the local IP address, 0 to get the remote one
Returns:
ERR_CONN for invalid connections ERR_OK if the information was retrieved

Definition at line 276 of file lwip_api_lib.c.

struct netconn* netconn_new_with_proto_and_callback ( enum netconn_type  t,
u8_t  proto,
netconn_callback  callback 
) [read]

Create a new netconn (of a specific type) that has a callback function.

The corresponding pcb is also created.

Parameters:
tthe type of 'connection' to create (
See also:
enum netconn_type)
Parameters:
protothe IP protocol for RAW IP pcbs
callbacka function to call on status changes (RX available, TX'ed)
Returns:
a newly allocated struct netconn or NULL on memory error

Definition at line 156 of file lwip_api_lib.c.

err_t netconn_recv_udp_raw_netbuf ( struct netconn conn,
struct netbuf **  new_buf 
)

Receive data (in form of a netbuf) from a UDP or RAW netconn.

Parameters:
connthe netconn from which to receive data
new_bufpointer where a new netbuf is stored when received data
Returns:
ERR_OK if data has been received, an error code otherwise (timeout, memory error or another error) ERR_ARG if conn is not a UDP/RAW netconn

Definition at line 829 of file lwip_api_lib.c.

err_t netconn_recv_udp_raw_netbuf_flags ( struct netconn conn,
struct netbuf **  new_buf,
u8_t  apiflags 
)

Receive data (in form of a netbuf) from a UDP or RAW netconn.

Parameters:
connthe netconn from which to receive data
new_bufpointer where a new netbuf is stored when received data
apiflagsflags that control function behaviour. For now only:

  • NETCONN_DONTBLOCK: only read data that is available now, don't wait for more data
Returns:
ERR_OK if data has been received, an error code otherwise (timeout, memory error or another error) ERR_ARG if conn is not a UDP/RAW netconn

Definition at line 849 of file lwip_api_lib.c.

err_t netconn_write_vectors_partly ( struct netconn conn,
struct netvector vectors,
u16_t  vectorcnt,
u8_t  apiflags,
size_t *  bytes_written 
)

Send vectorized data atomically over a TCP netconn.

Parameters:
connthe TCP netconn over which to send data
vectorsarray of vectors containing data to send
vectorcntnumber of vectors in the array
apiflagscombination of following flags :

  • NETCONN_COPY: data will be copied into memory belonging to the stack
  • NETCONN_MORE: for TCP connection, PSH flag will be set on last segment sent
  • NETCONN_DONTBLOCK: only write the data if all data can be written at once
bytes_writtenpointer to a location that receives the number of written bytes
Returns:
ERR_OK if data was sent, any other err_t on error

Definition at line 1004 of file lwip_api_lib.c.