Mistake on this page?
Report an issue in GitHub or email us
MeshInterfaceNanostack.h
1 /*
2  * Copyright (c) 2016-2019 ARM Limited. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  * Licensed under the Apache License, Version 2.0 (the License); you may
5  * 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, WITHOUT
12  * 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 MESHINTERFACENANOSTACK_H
18 #define MESHINTERFACENANOSTACK_H
19 
20 #include "Semaphore.h"
21 #include "MeshInterface.h"
22 #include "NanostackRfPhy.h"
23 #include "Nanostack.h"
24 #include "mesh_interface_types.h"
25 
26 class Nanostack::Interface : public OnboardNetworkStack::Interface, private mbed::NonCopyable<Nanostack::Interface> {
27 public:
28  virtual nsapi_error_t get_ip_address(SocketAddress *address);
29  MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
30  virtual char *get_ip_address(char *buf, nsapi_size_t buflen);
31  virtual char *get_mac_address(char *buf, nsapi_size_t buflen);
32  virtual nsapi_error_t get_netmask(SocketAddress *address);
33  MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
34  virtual char *get_netmask(char *buf, nsapi_size_t buflen);
35  virtual nsapi_error_t get_gateway(SocketAddress *address);
36  MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
37  virtual char *get_gateway(char *buf, nsapi_size_t buflen);
38  virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
39  virtual nsapi_connection_status_t get_connection_status() const;
40 
41  void get_mac_address(uint8_t *buf) const
42  {
43  NanostackMACPhy *phy = interface_phy.nanostack_mac_phy();
44  if (phy) {
45  phy->get_mac_address(buf);
46  }
47  }
48 
49  /**
50  * \brief Callback from C-layer
51  * \param status state of the network
52  * */
53  void network_handler(mesh_connection_status_t status);
54 
55  int8_t get_interface_id() const
56  {
57  return interface_id;
58  }
59  int8_t get_driver_id() const
60  {
61  return _device_id;
62  }
63 
64 private:
65  NanostackPhy &interface_phy;
66 protected:
67  Interface(NanostackPhy &phy);
68  virtual nsapi_error_t register_phy();
69  NanostackPhy &get_phy() const
70  {
71  return interface_phy;
72  }
73  int8_t interface_id;
74  int8_t _device_id;
75  rtos::Semaphore connect_semaphore;
76  rtos::Semaphore disconnect_semaphore;
77 
79  nsapi_connection_status_t _connect_status;
80  nsapi_connection_status_t _previous_connection_status;
81  bool _blocking;
82 };
83 
85 public:
86  char *get_interface_name(char *buf);
87 protected:
88  MeshInterface(NanostackRfPhy &phy) : Interface(phy) { }
89  NanostackRfPhy &get_phy() const
90  {
91  return static_cast<NanostackRfPhy &>(Interface::get_phy());
92  }
93 };
94 
95 
96 class InterfaceNanostack : public virtual NetworkInterface {
97 public:
98  /** Start the interface
99  *
100  * @return 0 on success, negative error code on failure
101  */
102  virtual nsapi_error_t connect();
103 
104  /** Stop the interface
105  *
106  * @return 0 on success, negative error code on failure
107  */
108  virtual nsapi_error_t disconnect();
109 
110  /** @copydoc NetworkInterface::get_ip_address */
111  virtual nsapi_error_t get_ip_address(SocketAddress *address);
112 
113  MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
114  virtual const char *get_ip_address();
115 
116  /** Get the internally stored MAC address
117  /return MAC address of the interface
118  */
119  virtual const char *get_mac_address();
120 
121  /** Register callback for status reporting
122  *
123  * The specified status callback function will be called on status changes
124  * on the network. The parameters on the callback are the event type and
125  * event-type dependent reason parameter.
126  *
127  * @param status_cb The callback for status changes
128  */
129  virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
130 
131  /** Get the connection status
132  *
133  * @return The connection status according to ConnectionStatusType
134  */
135  virtual nsapi_connection_status_t get_connection_status() const;
136 
137  /** Set blocking status of connect() which by default should be blocking
138  *
139  * @param blocking true if connect is blocking
140  * @return 0 on success, negative error code on failure
141  */
142  virtual nsapi_error_t set_blocking(bool blocking);
143 
144  /** Set file system root path.
145  *
146  * Set file system root path that stack will use to write and read its data.
147  * Setting root_path to NULL will disable file system usage.
148  *
149  * @param root_path Address to NUL-terminated root-path string or NULL to disable file system usage.
150  * @return MESH_ERROR_NONE on success, MESH_ERROR_MEMORY in case of memory failure, MESH_ERROR_UNKNOWN in case of other error.
151  */
152  virtual nsapi_error_t set_file_system_root_path(const char *root_path);
153 
154  /** Get the interface ID
155  * @return Interface identifier
156  */
157  int8_t get_interface_id() const
158  {
159  return _interface->get_interface_id();
160  }
161 
162 protected:
164  virtual Nanostack *get_stack(void);
165  Nanostack::Interface *get_interface() const
166  {
167  return _interface;
168  }
169  virtual nsapi_error_t do_initialize() = 0;
170 
171  Nanostack::Interface *_interface;
172 
173  SocketAddress ip_addr;
174  char mac_addr_str[24];
175  mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
176  bool _blocking;
177  bool _configured = false;
178 };
179 
180 class MeshInterfaceNanostack : public InterfaceNanostack, public MeshInterface, private mbed::NonCopyable<MeshInterfaceNanostack> {
181 public:
182 
183  /** Attach phy and initialize the mesh
184  *
185  * Initializes a mesh interface on the given phy. Not needed if
186  * the phy is passed to the mesh's constructor.
187  *
188  * @return 0 on success, negative on failure
189  */
190  nsapi_error_t initialize(NanostackRfPhy *phy);
191 
192 protected:
193  MeshInterfaceNanostack() : _phy(NULL) { }
194  MeshInterfaceNanostack(NanostackRfPhy *phy) : _phy(phy) { }
195  Nanostack::MeshInterface *get_interface() const
196  {
197  return static_cast<Nanostack::MeshInterface *>(_interface);
198  }
199  NanostackRfPhy *_phy;
200 };
201 
202 #endif /* MESHINTERFACENANOSTACK_H */
Radio PHY driver class for Nanostack.
virtual char * get_interface_name(char *buf)
Returns interface name.
The Semaphore class is used to manage and protect access to a set of shared resources.
Definition: Semaphore.h:47
Representation of a stack&#39;s view of an interface.
virtual void get_mac_address(uint8_t *mac)=0
Read the mac address of this physical interface.
signed int nsapi_error_t
Type used to represent error codes.
Definition: nsapi_types.h:95
virtual void attach(mbed::Callback< void(nsapi_event_t, intptr_t)> status_cb)
Register callback for status reporting.
Common interface that is shared between mesh hardware.
Definition: MeshInterface.h:29
Prevents generation of copy constructor and copy assignment operator in derived classes.
Definition: NonCopyable.h:169
virtual char * get_mac_address(char *buf, nsapi_size_t buflen)
Return MAC address of the network interface.
virtual nsapi_error_t get_netmask(SocketAddress *address)
SocketAddress class.
Definition: SocketAddress.h:35
Common interface that is shared between network devices.
virtual nsapi_error_t get_ip_address(SocketAddress *address)
Get the local IP address.
virtual nsapi_error_t get_gateway(SocketAddress *address)
PHY driver class for Nanostack.
Definition: NanostackPhy.h:25
unsigned int nsapi_size_t
Type used to represent the size of data passed through sockets.
Definition: nsapi_types.h:99
MAC PHY driver class for Nanostack.
void network_handler(mesh_connection_status_t status)
Callback from C-layer.
virtual NanostackMACPhy * nanostack_mac_phy()
Return pointer to a NanostackMACPhy.
Definition: NanostackPhy.h:40
Callback class based on template specialization.
Definition: Callback.h:39
virtual nsapi_connection_status_t get_connection_status() const
Get the connection status.
#define MBED_DEPRECATED_SINCE(D, M)
MBED_DEPRECATED("message string") Mark a function declaration as deprecated, if it used then a warnin...
int8_t get_interface_id() const
Get the interface ID.
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.