Mistake on this page?
Report an issue in GitHub or email us
whd_emac.h
1 /*
2  * Copyright (c) 2018-2019 ARM Limited
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef WHD_EMAC_H_
19 #define WHD_EMAC_H_
20 
21 #include "EMAC.h"
22 #include "EMACInterface.h"
23 #include "WiFiInterface.h"
24 #include "whd_int.h"
25 
26 #include "rtos/Semaphore.h"
27 #include "rtos/Mutex.h"
28 
29 class WHD_EMAC : public EMAC {
30 public:
31  WHD_EMAC(whd_interface_role_t itype = WHD_STA_ROLE, const uint8_t *mac_addr = NULL);
32 
33  static WHD_EMAC &get_instance(whd_interface_role_t role = WHD_STA_ROLE, const uint8_t *mac_addr = NULL);
34 
35  /**
36  * Return maximum transmission unit
37  *
38  * @return MTU in bytes
39  */
40  virtual uint32_t get_mtu_size() const;
41 
42  /**
43  * Gets memory buffer alignment preference
44  *
45  * Gets preferred memory buffer alignment of the Emac device. IP stack may or may not
46  * align link out memory buffer chains using the alignment.
47  *
48  * @return Memory alignment requirement in bytes
49  */
50  virtual uint32_t get_align_preference() const;
51 
52  /**
53  * Return interface name
54  *
55  * @param name Pointer to where the name should be written
56  * @param size Maximum number of character to copy
57  */
58  virtual void get_ifname(char *name, uint8_t size) const;
59 
60  /**
61  * Returns size of the underlying interface HW address size.
62  *
63  * @return HW address size in bytes
64  */
65  virtual uint8_t get_hwaddr_size() const;
66 
67  /**
68  * Return interface-supplied HW address
69  *
70  * Copies HW address to provided memory, @param addr has to be of correct size see @a get_hwaddr_size
71  *
72  * HW address need not be provided if this interface does not have its own HW
73  * address configuration; stack will choose address from central system
74  * configuration if the function returns false and does not write to addr.
75  *
76  * @param addr HW address for underlying interface
77  * @return true if HW address is available
78  */
79  virtual bool get_hwaddr(uint8_t *addr) const;
80 
81  /**
82  * Set HW address for interface
83  *
84  * Provided address has to be of correct size, see @a get_hwaddr_size
85  *
86  * Called to set the MAC address to actually use - if @a get_hwaddr is provided
87  * the stack would normally use that, but it could be overridden, eg for test
88  * purposes.
89  *
90  * @param addr Address to be set
91  */
92  virtual void set_hwaddr(const uint8_t *addr);
93 
94  /**
95  * Sends the packet over the link
96  *
97  * That can not be called from an interrupt context.
98  *
99  * @param buf Packet to be send
100  * @return True if the packet was send successfully, False otherwise
101  */
102  virtual bool link_out(emac_mem_buf_t *buf);
103 
104  /**
105  * Initializes the HW
106  *
107  * @return True on success, False in case of an error.
108  */
109  virtual bool power_up();
110 
111  /**
112  * Deinitializes the HW
113  *
114  */
115  virtual void power_down();
116 
117  /**
118  * Sets a callback that needs to be called for packets received for that interface
119  *
120  * @param input_cb Function to be register as a callback
121  */
122  virtual void set_link_input_cb(emac_link_input_cb_t input_cb);
123 
124  /**
125  * Sets a callback that needs to be called on link status changes for given interface
126  *
127  * @param state_cb Function to be register as a callback
128  */
129  virtual void set_link_state_cb(emac_link_state_change_cb_t state_cb);
130 
131  /** Add device to a multicast group
132  *
133  * @param address A multicast group hardware address
134  */
135  virtual void add_multicast_group(const uint8_t *address);
136 
137  /** Remove device from a multicast group
138  *
139  * @param address A multicast group hardware address
140  */
141  virtual void remove_multicast_group(const uint8_t *address);
142 
143  /** Request reception of all multicast packets
144  *
145  * @param all True to receive all multicasts
146  * False to receive only multicasts addressed to specified groups
147  */
148  virtual void set_all_multicast(bool all);
149 
150  /** Sets memory manager that is used to handle memory buffers
151  *
152  * @param mem_mngr Pointer to memory manager
153  */
154  virtual void set_memory_manager(EMACMemoryManager &mem_mngr);
155 
156  /** Set callback to receive EMAC activity events
157  *
158  * @param activity_cb The callback for activity events
159  */
160  virtual void set_activity_cb(mbed::Callback<void(bool is_tx_activity)> activity_cb);
161 
162  emac_link_input_cb_t emac_link_input_cb = NULL; /**< Callback for incoming data */
163  emac_link_state_change_cb_t emac_link_state_cb = NULL;
164  EMACMemoryManager *memory_manager;
165  bool powered_up = false;
166  bool link_state = false;
167  bool ap_sta_concur = false;
168  whd_interface_role_t interface_type;
169  whd_driver_t drvp = NULL;
170  whd_interface_t ifp = NULL;
171  whd_mac_t unicast_addr;
172  whd_mac_t multicast_addr;
173  mbed::Callback<void(bool)> activity_cb;
174 };
175 
176 #endif /* WHD_EMAC_H_ */
virtual void get_ifname(char *name, uint8_t size) const
Return interface name.
virtual uint32_t get_align_preference() const
Gets memory buffer alignment preference.
virtual void set_activity_cb(mbed::Callback< void(bool is_tx_activity)> activity_cb)
Set callback to receive EMAC activity events.
virtual uint8_t get_hwaddr_size() const
Returns size of the underlying interface HW address size.
virtual bool get_hwaddr(uint8_t *addr) const
Return interface-supplied HW address.
virtual void set_all_multicast(bool all)
Request reception of all multicast packets.
virtual uint32_t get_mtu_size() const
Return maximum transmission unit.
virtual bool link_out(emac_mem_buf_t *buf)
Sends the packet over the link.
virtual void add_multicast_group(const uint8_t *address)
Add device to a multicast group.
mbed::Callback< void(emac_mem_buf_t *buf)> emac_link_input_cb_t
Callback to be register with EMAC interface and to be called for received packets.
Definition: EMAC.h:49
virtual void set_hwaddr(const uint8_t *addr)
Set HW address for interface.
virtual void power_down()
Deinitializes the HW.
virtual void set_link_input_cb(emac_link_input_cb_t input_cb)
Sets a callback that needs to be called for packets received for that interface.
virtual void set_memory_manager(EMACMemoryManager &mem_mngr)
Sets memory manager that is used to handle memory buffers.
virtual bool power_up()
Initializes the HW.
This interface should be used to abstract low level access to networking hardware All operations rece...
Definition: EMAC.h:33
virtual void remove_multicast_group(const uint8_t *address)
Remove device from a multicast group.
virtual void set_link_state_cb(emac_link_state_change_cb_t state_cb)
Sets a callback that needs to be called on link status changes for given interface.
emac_link_input_cb_t emac_link_input_cb
Callback for incoming data.
Definition: whd_emac.h:162
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.