Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

AT_CellularStack Class Reference

Class AT_CellularStack. More...

#include <AT_CellularStack.h>

Inherits NetworkStack.

Inherited by GEMALTO_CINTERION_CellularStack, QUECTEL_BC95_CellularStack, QUECTEL_BG96_CellularStack, QUECTEL_M26_CellularStack, RM1000_AT_CellularStack, UBLOX_AT_CellularStack, and UBLOX_N2XX_CellularStack.

Public Types

typedef mbed::Callback< void(nsapi_error_t
result, SocketAddress *address) 
hostbyname_cb_t )
 Hostname translation callback (asynchronous)

Public Member Functions

virtual nsapi_error_t get_ip_address (SocketAddress *address)
 NetworkStack.
void set_cid (int cid)
 Set PDP context ID for this stack.
virtual nsapi_error_t get_ipv6_link_local_address (SocketAddress *address)
 Get the IPv6 link local address.
virtual nsapi_error_t get_ip_address_if (SocketAddress *address, const char *interface_name)
 Get the local IP address on interface name.
virtual nsapi_error_t gethostbyname (const char *host, SocketAddress *address, nsapi_version_t version=NSAPI_UNSPEC, const char *interface_name=NULL)
 Translates a hostname to an IP address with specific version.
virtual nsapi_value_or_error_t gethostbyname_async (const char *host, hostbyname_cb_t callback, nsapi_version_t version=NSAPI_UNSPEC, const char *interface_name=NULL)
 Translates a hostname to an IP address (asynchronous)
virtual nsapi_error_t gethostbyname_async_cancel (int id)
 Cancels asynchronous hostname translation.
virtual nsapi_error_t add_dns_server (const SocketAddress &address, const char *interface_name=NULL)
 Add a domain name server to list of servers to query.
virtual nsapi_error_t get_dns_server (int index, SocketAddress *address, const char *interface_name=NULL)
 Get a domain name server from a list of servers to query.
virtual OnboardNetworkStackonboardNetworkStack ()
 Dynamic downcast to a OnboardNetworkStack.

Protected Member Functions

virtual nsapi_error_t socket_stack_init ()
 Modem specific socket stack initialization.
virtual nsapi_error_t socket_open (nsapi_socket_t *handle, nsapi_protocol_t proto)
 Note: Socket_open does not actually open socket on all drivers, but that's deferred until calling `sendto`.
virtual nsapi_error_t socket_close (nsapi_socket_t handle)
 Close the socket.
virtual nsapi_error_t socket_bind (nsapi_socket_t handle, const SocketAddress &address)
 Bind a specific address to a socket.
virtual nsapi_error_t socket_listen (nsapi_socket_t handle, int backlog)
 Listen for connections on a TCP socket.
virtual nsapi_error_t socket_connect (nsapi_socket_t handle, const SocketAddress &address)
 Connects TCP socket to a remote host.
virtual nsapi_error_t socket_accept (nsapi_socket_t server, nsapi_socket_t *handle, SocketAddress *address=0)
 Accepts a connection on a TCP socket.
virtual nsapi_size_or_error_t socket_send (nsapi_socket_t handle, const void *data, nsapi_size_t size)
 Send data over a TCP socket.
virtual nsapi_size_or_error_t socket_recv (nsapi_socket_t handle, void *data, nsapi_size_t size)
 Receive data over a TCP socket.
virtual nsapi_size_or_error_t socket_sendto (nsapi_socket_t handle, const SocketAddress &address, const void *data, nsapi_size_t size)
 Send a packet over a UDP socket.
virtual nsapi_size_or_error_t socket_recvfrom (nsapi_socket_t handle, SocketAddress *address, void *buffer, nsapi_size_t size)
 Receive a packet over a UDP socket.
virtual void socket_attach (nsapi_socket_t handle, void(*callback)(void *), void *data)
 Register a callback on state change of the socket.
virtual int get_max_socket_count ()=0
 Gets maximum number of sockets modem supports.
virtual bool is_protocol_supported (nsapi_protocol_t protocol)=0
 Checks if modem supports the given protocol.
virtual nsapi_error_t socket_close_impl (int sock_id)=0
 Implements modem specific AT command set for socket closing.
virtual nsapi_error_t create_socket_impl (CellularSocket *socket)=0
 Implements modem specific AT command set for creating socket.
virtual nsapi_size_or_error_t socket_sendto_impl (CellularSocket *socket, const SocketAddress &address, const void *data, nsapi_size_t size)=0
 Implements modem specific AT command set for sending data.
virtual nsapi_size_or_error_t socket_recvfrom_impl (CellularSocket *socket, SocketAddress *address, void *buffer, nsapi_size_t size)=0
 Implements modem specific AT command set for receiving data.
CellularSocket * find_socket (int index)
 Find the socket handle based on the index of the socket construct in the socket container.
int find_socket_index (nsapi_socket_t handle)
 Find the index of the given CellularSocket handle.
bool is_addr_stack_compatible (const SocketAddress &addr)
 Checks if send to address is valid and if current stack type supports sending to that address type.
virtual nsapi_error_t setsockopt (nsapi_socket_t handle, int level, int optname, const void *optval, unsigned optlen)
 Set stack-specific socket options.
virtual nsapi_error_t getsockopt (nsapi_socket_t handle, int level, int optname, void *optval, unsigned *optlen)
 Get stack-specific socket options.

Friends

class InternetSocket
class InternetDatagramSocket
class TCPSocket
class TCPServer

Detailed Description

Class AT_CellularStack.

Implements NetworkStack and introduces interface for modem specific stack implementations.

Definition at line 39 of file AT_CellularStack.h.


Member Typedef Documentation

typedef mbed::Callback<void (nsapi_error_t result, SocketAddress *address) hostbyname_cb_t) [inherited]

Hostname translation callback (asynchronous)

Callback will be called after DNS resolution completes or a failure occurs.

Callback should not take more than 10ms to execute, otherwise it might prevent underlying thread processing. A portable user of the callback should not make calls to network operations due to stack size limitations. The callback should not perform expensive operations such as socket recv/send calls or blocking operations.

Parameters:
statusNSAPI_ERROR_OK on success, negative error code on failure
addressOn success, destination for the host SocketAddress

Reimplemented from DNS.

Definition at line 114 of file NetworkStack.h.


Member Function Documentation

nsapi_error_t add_dns_server ( const SocketAddress address,
const char *  interface_name = NULL 
) [virtual, inherited]

Add a domain name server to list of servers to query.

Parameters:
addressDestination for the host address
interface_nameNetwork interface name
Returns:
NSAPI_ERROR_OK on success, negative error code on failure

Implements DNS.

Definition at line 116 of file NetworkStack.cpp.

virtual nsapi_error_t create_socket_impl ( CellularSocket *  socket ) [protected, pure virtual]

Implements modem specific AT command set for creating socket.

Parameters:
socketCellular socket handle
AT_CellularStack::CellularSocket * find_socket ( int  index ) [protected]

Find the socket handle based on the index of the socket construct in the socket container.

Please note that this index may or may not be the socket id. The actual meaning of this index depends upon the modem being used.

Parameters:
indexIndex of the socket construct in the container
Returns:
Socket handle, NULL on error

Definition at line 447 of file AT_CellularStack.cpp.

int find_socket_index ( nsapi_socket_t  handle ) [protected]

Find the index of the given CellularSocket handle.

This index may or may not be the socket id. The actual meaning of this index depends upon the modem being used.

Definition at line 48 of file AT_CellularStack.cpp.

nsapi_error_t get_dns_server ( int  index,
SocketAddress address,
const char *  interface_name = NULL 
) [virtual, inherited]

Get a domain name server from a list of servers to query.

Returns a DNS server address for a index. If returns error no more DNS servers to read.

Parameters:
indexIndex of the DNS server, starts from zero
addressDestination for the host address
interface_nameNetwork interface name
Returns:
NSAPI_ERROR_OK on success, negative error code on failure

Definition at line 121 of file NetworkStack.cpp.

nsapi_error_t get_ip_address ( SocketAddress address ) [virtual]

NetworkStack.

Reimplemented from NetworkStack.

Definition at line 61 of file AT_CellularStack.cpp.

nsapi_error_t get_ip_address_if ( SocketAddress address,
const char *  interface_name 
) [virtual, inherited]

Get the local IP address on interface name.

Parameters:
addressSocketAddress representation of the link local IPv6 address
interface_nameNetwork interface_name
Return values:
NSAPI_ERROR_OKon success
NSAPI_ERROR_UNSUPPORTEDif this feature is not supported
NSAPI_ERROR_PARAMETERif the provided pointer is invalid
NSAPI_ERROR_NO_ADDRESSif the address cannot be obtained from stack

Definition at line 42 of file NetworkStack.cpp.

nsapi_error_t get_ipv6_link_local_address ( SocketAddress address ) [virtual, inherited]

Get the IPv6 link local address.

Parameters:
addressSocketAddress representation of the link local IPv6 address
Return values:
NSAPI_ERROR_OKon success
NSAPI_ERROR_UNSUPPORTEDif this feature is not supported
NSAPI_ERROR_PARAMETERif the provided pointer is invalid

Definition at line 37 of file NetworkStack.cpp.

virtual int get_max_socket_count (  ) [protected, pure virtual]

Gets maximum number of sockets modem supports.

nsapi_error_t gethostbyname ( const char *  host,
SocketAddress address,
nsapi_version_t  version = NSAPI_UNSPEC,
const char *  interface_name = NULL 
) [virtual, inherited]

Translates a hostname to an IP address with specific version.

The hostname may be either a domain name or an IP address. If the hostname is an IP address, no network transactions will be performed.

If no stack-specific DNS resolution is provided, the hostname will be resolve using a UDP socket on the stack.

Parameters:
hostHostname to resolve
addressPointer to a SocketAddress to store the result.
versionIP version of address to resolve, NSAPI_UNSPEC indicates version is chosen by the stack (defaults to NSAPI_UNSPEC)
interface_nameNetwork interface_name
Return values:
NSAPI_ERROR_OKon success
NSAPI_ERROR_PARAMETERif invalid (null) name is provided
NSAPI_ERROR_DNS_FAILUREif DNS resolution fails
intother negative errors, see nsapi_dns_query

Implements DNS.

Definition at line 52 of file NetworkStack.cpp.

nsapi_value_or_error_t gethostbyname_async ( const char *  host,
hostbyname_cb_t  callback,
nsapi_version_t  version = NSAPI_UNSPEC,
const char *  interface_name = NULL 
) [virtual, inherited]

Translates a hostname to an IP address (asynchronous)

The hostname may be either a domain name or an IP address. If the hostname is an IP address, no network transactions will be performed.

If no stack-specific DNS resolution is provided, the hostname will be resolve using a UDP socket on the stack.

Call is non-blocking. Result of the DNS operation is returned by the callback. If this function returns failure, callback will not be called. In case result is success (IP address was found from DNS cache), callback will be called before function returns.

Parameters:
hostHostname to resolve
callbackCallback that is called for result
versionIP version of address to resolve, NSAPI_UNSPEC indicates version is chosen by the stack (defaults to NSAPI_UNSPEC)
interface_nameNetwork interface_name
Returns:
0 on immediate success, negative error code on immediate failure or a positive unique id that represents the hostname translation operation and can be passed to cancel

Implements DNS.

Definition at line 79 of file NetworkStack.cpp.

nsapi_error_t gethostbyname_async_cancel ( int  id ) [virtual, inherited]

Cancels asynchronous hostname translation.

When translation is cancelled, callback will not be called.

Parameters:
idUnique id of the hostname translation operation
Returns:
NSAPI_ERROR_OK on success, negative error code on failure

Implements DNS.

Definition at line 111 of file NetworkStack.cpp.

virtual nsapi_error_t getsockopt ( nsapi_socket_t  handle,
int  level,
int  optname,
void *  optval,
unsigned *  optlen 
) [protected, virtual, inherited]

Get stack-specific socket options.

The getstackopt allow an application to retrieve stack-specific hints from the underlying stack. For unsupported options, NSAPI_ERROR_UNSUPPORTED is returned and optval is unmodified.

Parameters:
handleSocket handle.
levelStack-specific protocol level.
optnameStack-specific option identifier.
optvalDestination for option value.
optlenLength of the option value.
Returns:
NSAPI_ERROR_OK on success, negative error code on failure.

Reimplemented in ESP8266Interface.

bool is_addr_stack_compatible ( const SocketAddress addr ) [protected]

Checks if send to address is valid and if current stack type supports sending to that address type.

Definition at line 462 of file AT_CellularStack.cpp.

virtual bool is_protocol_supported ( nsapi_protocol_t  protocol ) [protected, pure virtual]

Checks if modem supports the given protocol.

Parameters:
protocolProtocol type
virtual OnboardNetworkStack* onboardNetworkStack (  ) [virtual, inherited]

Dynamic downcast to a OnboardNetworkStack.

Definition at line 203 of file NetworkStack.h.

void set_cid ( int  cid )

Set PDP context ID for this stack.

Parameters:
cidvalue from AT+CGDCONT, where -1 is undefined

Definition at line 149 of file AT_CellularStack.cpp.

virtual nsapi_error_t setsockopt ( nsapi_socket_t  handle,
int  level,
int  optname,
const void *  optval,
unsigned  optlen 
) [protected, virtual, inherited]

Set stack-specific socket options.

The setsockopt allow an application to pass stack-specific hints to the underlying stack. For unsupported options, NSAPI_ERROR_UNSUPPORTED is returned and the socket is unmodified.

Parameters:
handleSocket handle.
levelStack-specific protocol level.
optnameStack-specific option identifier.
optvalOption value.
optlenLength of the option value.
Returns:
NSAPI_ERROR_OK on success, negative error code on failure.

Reimplemented in ESP8266Interface.

virtual nsapi_error_t socket_accept ( nsapi_socket_t  server,
nsapi_socket_t handle,
SocketAddress address = 0 
) [protected, virtual]

Accepts a connection on a TCP socket.

The server socket must be bound and set to listen for connections. On a new connection, creates a network socket and stores it in the specified handle. The handle must be passed to following calls on the socket.

A stack may have a finite number of sockets, in this case NSAPI_ERROR_NO_SOCKET is returned if no socket is available.

This call is non-blocking. If accept would block, NSAPI_ERROR_WOULD_BLOCK is returned immediately.

Parameters:
serverSocket handle to server to accept from
handleDestination for a handle to the newly created socket
addressDestination for the remote address or NULL
Returns:
NSAPI_ERROR_OK on success, negative error code on failure

Implements NetworkStack.

void socket_attach ( nsapi_socket_t  handle,
void(*)(void *)  callback,
void *  data 
) [protected, virtual]

Register a callback on state change of the socket.

The specified callback will be called on state changes such as when the socket can recv/send/accept successfully and on when an error occurs. The callback may also be called spuriously without reason.

The callback may be called in an interrupt context and should not perform expensive operations such as recv/send calls.

Parameters:
handleSocket handle
callbackFunction to call on state change
dataArgument to pass to callback

Implements NetworkStack.

Definition at line 426 of file AT_CellularStack.cpp.

nsapi_error_t socket_bind ( nsapi_socket_t  handle,
const SocketAddress address 
) [protected, virtual]

Bind a specific address to a socket.

Binding a socket specifies the address and port on which to receive data. If the IP address is zeroed, only the port is bound.

Parameters:
handleSocket handle
addressLocal address to bind
Returns:
NSAPI_ERROR_OK on success, negative error code on failure.

Implements NetworkStack.

Definition at line 246 of file AT_CellularStack.cpp.

nsapi_error_t socket_close ( nsapi_socket_t  handle ) [protected, virtual]

Close the socket.

Closes any open connection and deallocates any memory associated with the socket.

Parameters:
handleSocket handle
Returns:
NSAPI_ERROR_OK on success, negative error code on failure

Implements NetworkStack.

Definition at line 206 of file AT_CellularStack.cpp.

virtual nsapi_error_t socket_close_impl ( int  sock_id ) [protected, pure virtual]

Implements modem specific AT command set for socket closing.

Parameters:
sock_idSocket id
nsapi_error_t socket_connect ( nsapi_socket_t  handle,
const SocketAddress address 
) [protected, virtual]

Connects TCP socket to a remote host.

Initiates a connection to a remote server specified by the indicated address.

Parameters:
handleSocket handle
addressThe SocketAddress of the remote host
Returns:
NSAPI_ERROR_OK on success, negative error code on failure

Implements NetworkStack.

Definition at line 281 of file AT_CellularStack.cpp.

nsapi_error_t socket_listen ( nsapi_socket_t  handle,
int  backlog 
) [protected, virtual]

Listen for connections on a TCP socket.

Marks the socket as a passive socket that can be used to accept incoming connections.

Parameters:
handleSocket handle
backlogNumber of pending connections that can be queued simultaneously
Returns:
NSAPI_ERROR_OK on success, negative error code on failure

Implements NetworkStack.

Definition at line 276 of file AT_CellularStack.cpp.

nsapi_error_t socket_open ( nsapi_socket_t handle,
nsapi_protocol_t  proto 
) [protected, virtual]

Note: Socket_open does not actually open socket on all drivers, but that's deferred until calling `sendto`.

The reason is that IP stack implementations are very much modem specific and it's quite common that when a socket is created (via AT commands) it must also be given remote IP address, and that is usually known only when calling `sendto`.

Implements NetworkStack.

Definition at line 159 of file AT_CellularStack.cpp.

virtual nsapi_size_or_error_t socket_recv ( nsapi_socket_t  handle,
void *  data,
nsapi_size_t  size 
) [protected, virtual]

Receive data over a TCP socket.

The socket must be connected to a remote host. Returns the number of bytes received into the buffer.

This call is non-blocking. If recv would block, NSAPI_ERROR_WOULD_BLOCK is returned immediately.

Parameters:
handleSocket handle
dataDestination buffer for data received from the host
sizeSize of the buffer in bytes
Returns:
Number of received bytes on success, negative error code on failure

Implements NetworkStack.

virtual nsapi_size_or_error_t socket_recvfrom ( nsapi_socket_t  handle,
SocketAddress address,
void *  buffer,
nsapi_size_t  size 
) [protected, virtual]

Receive a packet over a UDP socket.

Receives data and stores the source address in address if address is not NULL. Returns the number of bytes received into the buffer.

This call is non-blocking. If recvfrom would block, NSAPI_ERROR_WOULD_BLOCK is returned immediately.

Parameters:
handleSocket handle
addressDestination for the source address or NULL
bufferDestination buffer for data received from the host
sizeSize of the buffer in bytes
Returns:
Number of received bytes on success, negative error code on failure

Implements NetworkStack.

virtual nsapi_size_or_error_t socket_recvfrom_impl ( CellularSocket *  socket,
SocketAddress address,
void *  buffer,
nsapi_size_t  size 
) [protected, pure virtual]

Implements modem specific AT command set for receiving data.

Parameters:
socketSocket handle
addressDestination for the source address or NULL
bufferDestination buffer for data received from the host
sizeSize of the buffer in bytes
Returns:
Number of received bytes on success, negative error code on failure
virtual nsapi_size_or_error_t socket_send ( nsapi_socket_t  handle,
const void *  data,
nsapi_size_t  size 
) [protected, virtual]

Send data over a TCP socket.

The socket must be connected to a remote host. Returns the number of bytes sent from the buffer.

This call is non-blocking. If send would block, NSAPI_ERROR_WOULD_BLOCK is returned immediately.

Parameters:
handleSocket handle
dataBuffer of data to send to the host
sizeSize of the buffer in bytes
Returns:
Number of sent bytes on success, negative error code on failure

Implements NetworkStack.

virtual nsapi_size_or_error_t socket_sendto ( nsapi_socket_t  handle,
const SocketAddress address,
const void *  data,
nsapi_size_t  size 
) [protected, virtual]

Send a packet over a UDP socket.

Sends data to the specified address. Returns the number of bytes sent from the buffer.

This call is non-blocking. If sendto would block, NSAPI_ERROR_WOULD_BLOCK is returned immediately.

Parameters:
handleSocket handle
addressThe SocketAddress of the remote host
dataBuffer of data to send to the host
sizeSize of the buffer in bytes
Returns:
Number of sent bytes on success, negative error code on failure

Implements NetworkStack.

virtual nsapi_size_or_error_t socket_sendto_impl ( CellularSocket *  socket,
const SocketAddress address,
const void *  data,
nsapi_size_t  size 
) [protected, pure virtual]

Implements modem specific AT command set for sending data.

Parameters:
socketCellular socket handle
addressThe SocketAddress of the remote host
dataBuffer of data to send to the host
sizeSize of the buffer in bytes
Returns:
Number of sent bytes on success, negative error code on failure
nsapi_error_t socket_stack_init (  ) [protected, virtual]

Modem specific socket stack initialization.

Returns:
0 on success

Definition at line 154 of file AT_CellularStack.cpp.