Mistake on this page?
Report an issue in GitHub or email us
OnboardNetworkStack.h
1 /* mbed OS IP stack API
2  * Copyright (c) 2015-2017 ARM Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MBED_IPSTACK_H
18 #define MBED_IPSTACK_H
19 
20 #include "nsapi.h"
21 
22 #include "NetworkStack.h"
23 #include "EMAC.h"
24 #include "L3IP.h"
25 #include "PPP.h"
26 
27 /**
28  * mbed OS API for onboard IP stack abstraction
29  *
30  * This interface should be used by targets to initialize IP stack, create, bring up and bring down network interfaces.
31  *
32  * An onboard network stack has the potential ability to register interfaces
33  * such as through EMAC, and has its own interface identifiers.
34  */
36 public:
37  /** Return the default on-board network stack
38  *
39  * Returns the default on-board network stack, as configured by
40  * JSON option nsapi.default-stack.
41  */
43 
44  /** Representation of a stack's view of an interface.
45  *
46  * Provides facilities required by a driver to implement the application
47  * NetworkInterface API.
48  */
49  class Interface {
50  public:
51  virtual ~Interface() {}
52 
53  /** Connect the interface to the network
54  *
55  * Sets up a connection on specified network interface, using DHCP or provided network details. If the @a dhcp is set to
56  * true all the remaining parameters are ignored.
57  *
58  * @param dhcp true if the network details should be acquired using DHCP
59  * @param ip IP address to be used for the interface as "W:X:Y:Z" or NULL
60  * @param netmask Net mask to be used for the interface as "W:X:Y:Z" or NULL
61  * @param gw Gateway address to be used for the interface as "W:X:Y:Z" or NULL
62  * @param stack Allow manual selection of IPv4 and/or IPv6.
63  * @param blocking Specify whether bringup blocks for connection completion.
64  * @return NSAPI_ERROR_OK on success, or error code
65  */
66  virtual nsapi_error_t bringup(bool dhcp, const char *ip,
67  const char *netmask, const char *gw,
68  nsapi_ip_stack_t stack = DEFAULT_STACK,
69  bool blocking = true) = 0;
70 
71  /** Disconnect interface from the network
72  *
73  * After this call the network interface is inactive, to use it again user needs to call @n bringup again.
74  *
75  * @return NSAPI_ERROR_OK on success, or error code
76  */
77  virtual nsapi_error_t bringdown() = 0;
78 
79  /** Register callback for status reporting
80  *
81  * The specified status callback function will be called on status changes
82  * on the network. The parameters on the callback are the event type and
83  * event-type dependent reason parameter.
84  *
85  * @param status_cb The callback for status changes
86  */
87  virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb) = 0;
88 
89  /** Get the connection status
90  *
91  * @return The connection status according to ConnectionStatusType
92  */
93 
94  virtual nsapi_connection_status_t get_connection_status() const = 0;
95 
96  /** Returns interface name
97  *
98  * @return string containing name of network interface for example "en0"
99  */
100 
101  virtual char *get_interface_name(char *buf)
102  {
103  return NULL;
104  };
105  /** Return MAC address of the network interface
106  *
107  * @return MAC address as "V:W:X:Y:Z"
108  */
109 
110  virtual char *get_mac_address(char *buf, nsapi_size_t buflen) = 0;
111 
112  /** @copydoc NetworkStack::get_ip_address */
113  virtual nsapi_error_t get_ip_address(SocketAddress *address) = 0;
114 
115  MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
116  virtual char *get_ip_address(char *buf, nsapi_size_t buflen) = 0;
117 
118  /** @copydoc NetworkStack::get_ipv6_link_local_address */
120  {
122  }
123 
124  /** @copydoc NetworkStack::get_ip_address_if */
125  virtual nsapi_error_t get_ip_address_if(SocketAddress *address, const char *interface_name)
126  {
128  }
129 
130  MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
131  virtual char *get_ip_address_if(char *buf, nsapi_size_t buflen, const char *interface_name)
132  {
133  return NULL;
134  };
135 
136  /** @copydoc NetworkStack::get_netmask */
137  virtual nsapi_error_t get_netmask(SocketAddress *address) = 0;
138 
139  MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
140  virtual char *get_netmask(char *buf, nsapi_size_t buflen) = 0;
141 
142  /** @copydoc NetworkStack::get_gateway */
143  virtual nsapi_error_t get_gateway(SocketAddress *address) = 0;
144 
145  MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
146  virtual char *get_gateway(char *buf, nsapi_size_t buflen) = 0;
147  };
148 
149  /** Register a network interface with the IP stack
150  *
151  * Connects EMAC layer with the IP stack and initializes all the required infrastructure.
152  * This function should be called only once for each available interface. EMAC memory
153  * manager is available to EMAC after this function call.
154  *
155  * @param emac EMAC HAL implementation for this network interface
156  * @param default_if true if the interface should be treated as the default one
157  * @param[out] interface_out pointer to stack interface object controlling the EMAC
158  * @return NSAPI_ERROR_OK on success, or error code
159  */
160  virtual nsapi_error_t add_ethernet_interface(EMAC &emac, bool default_if, Interface **interface_out) = 0;
161 
162  virtual nsapi_error_t add_l3ip_interface(L3IP &l3ip, bool default_if, Interface **interface_out)
163  {
164  return NSAPI_ERROR_OK;
165  };
166 
167  virtual nsapi_error_t add_ppp_interface(PPP &ppp, bool default_if, Interface **interface_out)
168  {
170  };
171 
172  virtual nsapi_error_t remove_ethernet_interface(Interface **interface_out)
173  {
174  return NSAPI_ERROR_OK;
175  };
176 
177  virtual nsapi_error_t remove_l3ip_interface(Interface **interface_out)
178  {
179  return NSAPI_ERROR_OK;
180  };
181 
182  virtual nsapi_error_t remove_ppp_interface(Interface **interface_out)
183  {
185  };
186 
187  virtual void set_default_interface(OnboardNetworkStack::Interface *interface)
188  {
189  }
190 
191 };
192 
193 #endif /* MBED_IPSTACK_H */
virtual char * get_interface_name(char *buf)
Returns interface name.
NetworkStack class.
Definition: NetworkStack.h:40
virtual nsapi_error_t get_netmask(SocketAddress *address)=0
Representation of a stack&#39;s view of an interface.
signed int nsapi_error_t
Type used to represent error codes.
Definition: nsapi_types.h:95
virtual nsapi_error_t get_gateway(SocketAddress *address)=0
virtual void attach(mbed::Callback< void(nsapi_event_t, intptr_t)> status_cb)=0
Register callback for status reporting.
mbed OS API for onboard IP stack abstraction
virtual nsapi_error_t add_ethernet_interface(EMAC &emac, bool default_if, Interface **interface_out)=0
Register a network interface with the IP stack.
virtual nsapi_error_t bringup(bool dhcp, const char *ip, const char *netmask, const char *gw, nsapi_ip_stack_t stack=DEFAULT_STACK, bool blocking=true)=0
Connect the interface to the network.
Definition: PPP.h:26
This interface should be used to abstract low level access to networking hardware All operations rece...
Definition: L3IP.h:31
SocketAddress class.
Definition: SocketAddress.h:35
virtual nsapi_error_t bringdown()=0
Disconnect interface from the network.
virtual nsapi_error_t get_ip_address(SocketAddress *address)=0
Get the local IP address.
unsigned int nsapi_size_t
Type used to represent the size of data passed through sockets.
Definition: nsapi_types.h:99
This interface should be used to abstract low level access to networking hardware All operations rece...
Definition: EMAC.h:32
NetworkStack class.
virtual nsapi_error_t get_ipv6_link_local_address(SocketAddress *address)
Get the IPv6 link local address.
virtual char * get_mac_address(char *buf, nsapi_size_t buflen)=0
Return MAC address of the network interface.
static OnboardNetworkStack & get_default_instance()
Return the default on-board network stack.
virtual nsapi_connection_status_t get_connection_status() const =0
Get the connection status.
Callback class based on template specialization.
Definition: Callback.h:39
virtual nsapi_error_t get_ip_address_if(SocketAddress *address, const char *interface_name)
Get the local IP address on interface name.
#define MBED_DEPRECATED_SINCE(D, M)
MBED_DEPRECATED("message string") Mark a function declaration as deprecated, if it used then a warnin...
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.