Webserver+3d print
cyclone_tcp/drivers/bcm43362_driver.c@0:8918a71cdbe9, 2017-02-04 (annotated)
- Committer:
- Sergunb
- Date:
- Sat Feb 04 18:15:49 2017 +0000
- Revision:
- 0:8918a71cdbe9
nothing else
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sergunb | 0:8918a71cdbe9 | 1 | /** |
Sergunb | 0:8918a71cdbe9 | 2 | * @file bcm43362_driver.c |
Sergunb | 0:8918a71cdbe9 | 3 | * @brief BCM43362 Wi-Fi controller |
Sergunb | 0:8918a71cdbe9 | 4 | * |
Sergunb | 0:8918a71cdbe9 | 5 | * @section License |
Sergunb | 0:8918a71cdbe9 | 6 | * |
Sergunb | 0:8918a71cdbe9 | 7 | * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved. |
Sergunb | 0:8918a71cdbe9 | 8 | * |
Sergunb | 0:8918a71cdbe9 | 9 | * This file is part of CycloneTCP Open. |
Sergunb | 0:8918a71cdbe9 | 10 | * |
Sergunb | 0:8918a71cdbe9 | 11 | * This program is free software; you can redistribute it and/or |
Sergunb | 0:8918a71cdbe9 | 12 | * modify it under the terms of the GNU General Public License |
Sergunb | 0:8918a71cdbe9 | 13 | * as published by the Free Software Foundation; either version 2 |
Sergunb | 0:8918a71cdbe9 | 14 | * of the License, or (at your option) any later version. |
Sergunb | 0:8918a71cdbe9 | 15 | * |
Sergunb | 0:8918a71cdbe9 | 16 | * This program is distributed in the hope that it will be useful, |
Sergunb | 0:8918a71cdbe9 | 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Sergunb | 0:8918a71cdbe9 | 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Sergunb | 0:8918a71cdbe9 | 19 | * GNU General Public License for more details. |
Sergunb | 0:8918a71cdbe9 | 20 | * |
Sergunb | 0:8918a71cdbe9 | 21 | * You should have received a copy of the GNU General Public License |
Sergunb | 0:8918a71cdbe9 | 22 | * along with this program; if not, write to the Free Software Foundation, |
Sergunb | 0:8918a71cdbe9 | 23 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
Sergunb | 0:8918a71cdbe9 | 24 | * |
Sergunb | 0:8918a71cdbe9 | 25 | * @author Oryx Embedded SARL (www.oryx-embedded.com) |
Sergunb | 0:8918a71cdbe9 | 26 | * @version 1.7.6 |
Sergunb | 0:8918a71cdbe9 | 27 | **/ |
Sergunb | 0:8918a71cdbe9 | 28 | |
Sergunb | 0:8918a71cdbe9 | 29 | //Switch to the appropriate trace level |
Sergunb | 0:8918a71cdbe9 | 30 | #define TRACE_LEVEL NIC_TRACE_LEVEL |
Sergunb | 0:8918a71cdbe9 | 31 | |
Sergunb | 0:8918a71cdbe9 | 32 | //Dependencies |
Sergunb | 0:8918a71cdbe9 | 33 | #include "core/net.h" |
Sergunb | 0:8918a71cdbe9 | 34 | #include "bcm43362_driver.h" |
Sergunb | 0:8918a71cdbe9 | 35 | #include "debug.h" |
Sergunb | 0:8918a71cdbe9 | 36 | |
Sergunb | 0:8918a71cdbe9 | 37 | //WICED dependencies |
Sergunb | 0:8918a71cdbe9 | 38 | #include "platform_init.h" |
Sergunb | 0:8918a71cdbe9 | 39 | #include "platform_mcu_peripheral.h" |
Sergunb | 0:8918a71cdbe9 | 40 | #include "wwd_constants.h" |
Sergunb | 0:8918a71cdbe9 | 41 | #include "wwd_structures.h" |
Sergunb | 0:8918a71cdbe9 | 42 | #include "wwd_buffer.h" |
Sergunb | 0:8918a71cdbe9 | 43 | #include "wwd_events.h" |
Sergunb | 0:8918a71cdbe9 | 44 | #include "wwd_management.h" |
Sergunb | 0:8918a71cdbe9 | 45 | #include "wwd_poll.h" |
Sergunb | 0:8918a71cdbe9 | 46 | #include "wwd_wifi.h" |
Sergunb | 0:8918a71cdbe9 | 47 | #include "wwd_buffer_interface.h" |
Sergunb | 0:8918a71cdbe9 | 48 | #include "wwd_bus_protocol_interface.h" |
Sergunb | 0:8918a71cdbe9 | 49 | #include "wwd_network_constants.h" |
Sergunb | 0:8918a71cdbe9 | 50 | #include "wwd_network_interface.h" |
Sergunb | 0:8918a71cdbe9 | 51 | |
Sergunb | 0:8918a71cdbe9 | 52 | //Underlying network interface |
Sergunb | 0:8918a71cdbe9 | 53 | static NetInterface *bcm43362StaInterface = NULL; |
Sergunb | 0:8918a71cdbe9 | 54 | static NetInterface *bcm43362ApInterface = NULL; |
Sergunb | 0:8918a71cdbe9 | 55 | |
Sergunb | 0:8918a71cdbe9 | 56 | //RX queue |
Sergunb | 0:8918a71cdbe9 | 57 | QueueHandle_t wwdRxQueue; |
Sergunb | 0:8918a71cdbe9 | 58 | |
Sergunb | 0:8918a71cdbe9 | 59 | //Regitered Wi-Fi events |
Sergunb | 0:8918a71cdbe9 | 60 | static const wwd_event_num_t app_wifi_events[] = |
Sergunb | 0:8918a71cdbe9 | 61 | { |
Sergunb | 0:8918a71cdbe9 | 62 | WLC_E_IF, |
Sergunb | 0:8918a71cdbe9 | 63 | WLC_E_LINK, |
Sergunb | 0:8918a71cdbe9 | 64 | WLC_E_ASSOC_IND, |
Sergunb | 0:8918a71cdbe9 | 65 | WLC_E_DISASSOC_IND, |
Sergunb | 0:8918a71cdbe9 | 66 | WLC_E_NONE |
Sergunb | 0:8918a71cdbe9 | 67 | }; |
Sergunb | 0:8918a71cdbe9 | 68 | |
Sergunb | 0:8918a71cdbe9 | 69 | //Forward declaration of functions |
Sergunb | 0:8918a71cdbe9 | 70 | void *app_wifi_event_handler(const wwd_event_header_t *event_header, |
Sergunb | 0:8918a71cdbe9 | 71 | const uint8_t *event_data, void *handler_user_data); |
Sergunb | 0:8918a71cdbe9 | 72 | |
Sergunb | 0:8918a71cdbe9 | 73 | |
Sergunb | 0:8918a71cdbe9 | 74 | /** |
Sergunb | 0:8918a71cdbe9 | 75 | * @brief BCM43362 driver (STA mode) |
Sergunb | 0:8918a71cdbe9 | 76 | **/ |
Sergunb | 0:8918a71cdbe9 | 77 | |
Sergunb | 0:8918a71cdbe9 | 78 | const NicDriver bcm43362StaDriver = |
Sergunb | 0:8918a71cdbe9 | 79 | { |
Sergunb | 0:8918a71cdbe9 | 80 | NIC_TYPE_ETHERNET, |
Sergunb | 0:8918a71cdbe9 | 81 | ETH_MTU, |
Sergunb | 0:8918a71cdbe9 | 82 | bcm43362Init, |
Sergunb | 0:8918a71cdbe9 | 83 | bcm43362Tick, |
Sergunb | 0:8918a71cdbe9 | 84 | bcm43362EnableIrq, |
Sergunb | 0:8918a71cdbe9 | 85 | bcm43362DisableIrq, |
Sergunb | 0:8918a71cdbe9 | 86 | bcm43362EventHandler, |
Sergunb | 0:8918a71cdbe9 | 87 | bcm43362SendPacket, |
Sergunb | 0:8918a71cdbe9 | 88 | bcm43362SetMulticastFilter, |
Sergunb | 0:8918a71cdbe9 | 89 | NULL, |
Sergunb | 0:8918a71cdbe9 | 90 | NULL, |
Sergunb | 0:8918a71cdbe9 | 91 | NULL, |
Sergunb | 0:8918a71cdbe9 | 92 | TRUE, |
Sergunb | 0:8918a71cdbe9 | 93 | TRUE, |
Sergunb | 0:8918a71cdbe9 | 94 | TRUE, |
Sergunb | 0:8918a71cdbe9 | 95 | TRUE |
Sergunb | 0:8918a71cdbe9 | 96 | }; |
Sergunb | 0:8918a71cdbe9 | 97 | |
Sergunb | 0:8918a71cdbe9 | 98 | |
Sergunb | 0:8918a71cdbe9 | 99 | /** |
Sergunb | 0:8918a71cdbe9 | 100 | * @brief BCM43362 driver (AP mode) |
Sergunb | 0:8918a71cdbe9 | 101 | **/ |
Sergunb | 0:8918a71cdbe9 | 102 | |
Sergunb | 0:8918a71cdbe9 | 103 | const NicDriver bcm43362ApDriver = |
Sergunb | 0:8918a71cdbe9 | 104 | { |
Sergunb | 0:8918a71cdbe9 | 105 | NIC_TYPE_ETHERNET, |
Sergunb | 0:8918a71cdbe9 | 106 | ETH_MTU, |
Sergunb | 0:8918a71cdbe9 | 107 | bcm43362Init, |
Sergunb | 0:8918a71cdbe9 | 108 | bcm43362Tick, |
Sergunb | 0:8918a71cdbe9 | 109 | bcm43362EnableIrq, |
Sergunb | 0:8918a71cdbe9 | 110 | bcm43362DisableIrq, |
Sergunb | 0:8918a71cdbe9 | 111 | bcm43362EventHandler, |
Sergunb | 0:8918a71cdbe9 | 112 | bcm43362SendPacket, |
Sergunb | 0:8918a71cdbe9 | 113 | bcm43362SetMulticastFilter, |
Sergunb | 0:8918a71cdbe9 | 114 | NULL, |
Sergunb | 0:8918a71cdbe9 | 115 | NULL, |
Sergunb | 0:8918a71cdbe9 | 116 | NULL, |
Sergunb | 0:8918a71cdbe9 | 117 | TRUE, |
Sergunb | 0:8918a71cdbe9 | 118 | TRUE, |
Sergunb | 0:8918a71cdbe9 | 119 | TRUE, |
Sergunb | 0:8918a71cdbe9 | 120 | TRUE |
Sergunb | 0:8918a71cdbe9 | 121 | }; |
Sergunb | 0:8918a71cdbe9 | 122 | |
Sergunb | 0:8918a71cdbe9 | 123 | |
Sergunb | 0:8918a71cdbe9 | 124 | /** |
Sergunb | 0:8918a71cdbe9 | 125 | * @brief BCM43362 initialization |
Sergunb | 0:8918a71cdbe9 | 126 | * @param[in] interface Underlying network interface |
Sergunb | 0:8918a71cdbe9 | 127 | * @return Error code |
Sergunb | 0:8918a71cdbe9 | 128 | **/ |
Sergunb | 0:8918a71cdbe9 | 129 | |
Sergunb | 0:8918a71cdbe9 | 130 | error_t bcm43362Init(NetInterface *interface) |
Sergunb | 0:8918a71cdbe9 | 131 | { |
Sergunb | 0:8918a71cdbe9 | 132 | wwd_result_t ret; |
Sergunb | 0:8918a71cdbe9 | 133 | //MacAddr macAddr; |
Sergunb | 0:8918a71cdbe9 | 134 | |
Sergunb | 0:8918a71cdbe9 | 135 | //STA or AP mode? |
Sergunb | 0:8918a71cdbe9 | 136 | if(interface->nicDriver == &bcm43362StaDriver) |
Sergunb | 0:8918a71cdbe9 | 137 | { |
Sergunb | 0:8918a71cdbe9 | 138 | //Debug message |
Sergunb | 0:8918a71cdbe9 | 139 | TRACE_INFO("Initializing BCM43362 (STA mode)...\r\n"); |
Sergunb | 0:8918a71cdbe9 | 140 | } |
Sergunb | 0:8918a71cdbe9 | 141 | else |
Sergunb | 0:8918a71cdbe9 | 142 | { |
Sergunb | 0:8918a71cdbe9 | 143 | //Debug message |
Sergunb | 0:8918a71cdbe9 | 144 | TRACE_INFO("Initializing BCM43362 (AP mode)...\r\n"); |
Sergunb | 0:8918a71cdbe9 | 145 | } |
Sergunb | 0:8918a71cdbe9 | 146 | |
Sergunb | 0:8918a71cdbe9 | 147 | //Start of exception handling block |
Sergunb | 0:8918a71cdbe9 | 148 | do |
Sergunb | 0:8918a71cdbe9 | 149 | { |
Sergunb | 0:8918a71cdbe9 | 150 | //Initialization sequence is performed once at startup |
Sergunb | 0:8918a71cdbe9 | 151 | if(bcm43362StaInterface == NULL && bcm43362ApInterface == NULL) |
Sergunb | 0:8918a71cdbe9 | 152 | { |
Sergunb | 0:8918a71cdbe9 | 153 | platform_init_mcu_infrastructure(); |
Sergunb | 0:8918a71cdbe9 | 154 | wwd_buffer_init(NULL); |
Sergunb | 0:8918a71cdbe9 | 155 | |
Sergunb | 0:8918a71cdbe9 | 156 | //Create TX queue |
Sergunb | 0:8918a71cdbe9 | 157 | wwdRxQueue = xQueueCreate(16, sizeof(wiced_buffer_t)); |
Sergunb | 0:8918a71cdbe9 | 158 | |
Sergunb | 0:8918a71cdbe9 | 159 | //Initialize Wi-Fi controller |
Sergunb | 0:8918a71cdbe9 | 160 | ret = wwd_management_wifi_on(WICED_COUNTRY_FRANCE); |
Sergunb | 0:8918a71cdbe9 | 161 | TRACE_INFO("wwd_management_wifi_on=%d (0x%04X)\r\n", ret, ret); |
Sergunb | 0:8918a71cdbe9 | 162 | |
Sergunb | 0:8918a71cdbe9 | 163 | ret = wwd_management_set_event_handler(app_wifi_events, app_wifi_event_handler, NULL, WWD_AP_INTERFACE); |
Sergunb | 0:8918a71cdbe9 | 164 | TRACE_INFO("wwd_management_set_event_handler=%d (0x%04X)\r\n", ret, ret); |
Sergunb | 0:8918a71cdbe9 | 165 | } |
Sergunb | 0:8918a71cdbe9 | 166 | else |
Sergunb | 0:8918a71cdbe9 | 167 | { |
Sergunb | 0:8918a71cdbe9 | 168 | //Initialization was already done |
Sergunb | 0:8918a71cdbe9 | 169 | ret = WWD_SUCCESS; |
Sergunb | 0:8918a71cdbe9 | 170 | } |
Sergunb | 0:8918a71cdbe9 | 171 | |
Sergunb | 0:8918a71cdbe9 | 172 | //STA or AP mode? |
Sergunb | 0:8918a71cdbe9 | 173 | if(interface->nicDriver == &bcm43362StaDriver) |
Sergunb | 0:8918a71cdbe9 | 174 | { |
Sergunb | 0:8918a71cdbe9 | 175 | //Save underlying network interface (STA mode) |
Sergunb | 0:8918a71cdbe9 | 176 | bcm43362StaInterface = interface; |
Sergunb | 0:8918a71cdbe9 | 177 | |
Sergunb | 0:8918a71cdbe9 | 178 | //Optionally set the station MAC address |
Sergunb | 0:8918a71cdbe9 | 179 | //if(macCompAddr(&interface->macAddr, &MAC_UNSPECIFIED_ADDR)) |
Sergunb | 0:8918a71cdbe9 | 180 | { |
Sergunb | 0:8918a71cdbe9 | 181 | //Use the factory preprogrammed station address |
Sergunb | 0:8918a71cdbe9 | 182 | ret = wwd_wifi_get_mac_address((wiced_mac_t *) &interface->macAddr, WWD_STA_INTERFACE); |
Sergunb | 0:8918a71cdbe9 | 183 | TRACE_INFO("wwd_wifi_get_mac_address=%d (0x%04X)\r\n", ret, ret); |
Sergunb | 0:8918a71cdbe9 | 184 | TRACE_INFO("MAC=%s\r\n", macAddrToString(&interface->macAddr, NULL)); |
Sergunb | 0:8918a71cdbe9 | 185 | |
Sergunb | 0:8918a71cdbe9 | 186 | //Generate the 64-bit interface identifier |
Sergunb | 0:8918a71cdbe9 | 187 | macAddrToEui64(&interface->macAddr, &interface->eui64); |
Sergunb | 0:8918a71cdbe9 | 188 | } |
Sergunb | 0:8918a71cdbe9 | 189 | } |
Sergunb | 0:8918a71cdbe9 | 190 | else |
Sergunb | 0:8918a71cdbe9 | 191 | { |
Sergunb | 0:8918a71cdbe9 | 192 | //Save underlying network interface (AP mode) |
Sergunb | 0:8918a71cdbe9 | 193 | bcm43362ApInterface = interface; |
Sergunb | 0:8918a71cdbe9 | 194 | |
Sergunb | 0:8918a71cdbe9 | 195 | //Optionally set the station MAC address |
Sergunb | 0:8918a71cdbe9 | 196 | //if(macCompAddr(&interface->macAddr, &MAC_UNSPECIFIED_ADDR)) |
Sergunb | 0:8918a71cdbe9 | 197 | { |
Sergunb | 0:8918a71cdbe9 | 198 | //Use the factory preprogrammed station address |
Sergunb | 0:8918a71cdbe9 | 199 | ret = wwd_wifi_get_mac_address((wiced_mac_t *) &interface->macAddr, WWD_STA_INTERFACE); |
Sergunb | 0:8918a71cdbe9 | 200 | TRACE_INFO("wwd_wifi_get_mac_address=%d (0x%04X)\r\n", ret, ret); |
Sergunb | 0:8918a71cdbe9 | 201 | TRACE_INFO("MAC=%s\r\n", macAddrToString(&interface->macAddr, NULL)); |
Sergunb | 0:8918a71cdbe9 | 202 | |
Sergunb | 0:8918a71cdbe9 | 203 | //Generate the 64-bit interface identifier |
Sergunb | 0:8918a71cdbe9 | 204 | macAddrToEui64(&interface->macAddr, &interface->eui64); |
Sergunb | 0:8918a71cdbe9 | 205 | } |
Sergunb | 0:8918a71cdbe9 | 206 | } |
Sergunb | 0:8918a71cdbe9 | 207 | |
Sergunb | 0:8918a71cdbe9 | 208 | //End of exception handling block |
Sergunb | 0:8918a71cdbe9 | 209 | } while(0); |
Sergunb | 0:8918a71cdbe9 | 210 | |
Sergunb | 0:8918a71cdbe9 | 211 | //BCM43362 is now ready to send |
Sergunb | 0:8918a71cdbe9 | 212 | osSetEvent(&interface->nicTxEvent); |
Sergunb | 0:8918a71cdbe9 | 213 | |
Sergunb | 0:8918a71cdbe9 | 214 | //Successful initialization |
Sergunb | 0:8918a71cdbe9 | 215 | return NO_ERROR; |
Sergunb | 0:8918a71cdbe9 | 216 | } |
Sergunb | 0:8918a71cdbe9 | 217 | |
Sergunb | 0:8918a71cdbe9 | 218 | |
Sergunb | 0:8918a71cdbe9 | 219 | /** |
Sergunb | 0:8918a71cdbe9 | 220 | * @brief BCM43362 timer handler |
Sergunb | 0:8918a71cdbe9 | 221 | * |
Sergunb | 0:8918a71cdbe9 | 222 | * This routine is periodically called by the TCP/IP stack to |
Sergunb | 0:8918a71cdbe9 | 223 | * handle periodic operations such as polling the link state |
Sergunb | 0:8918a71cdbe9 | 224 | * |
Sergunb | 0:8918a71cdbe9 | 225 | * @param[in] interface Underlying network interface |
Sergunb | 0:8918a71cdbe9 | 226 | **/ |
Sergunb | 0:8918a71cdbe9 | 227 | |
Sergunb | 0:8918a71cdbe9 | 228 | void bcm43362Tick(NetInterface *interface) |
Sergunb | 0:8918a71cdbe9 | 229 | { |
Sergunb | 0:8918a71cdbe9 | 230 | } |
Sergunb | 0:8918a71cdbe9 | 231 | |
Sergunb | 0:8918a71cdbe9 | 232 | |
Sergunb | 0:8918a71cdbe9 | 233 | /** |
Sergunb | 0:8918a71cdbe9 | 234 | * @brief Enable interrupts |
Sergunb | 0:8918a71cdbe9 | 235 | * @param[in] interface Underlying network interface |
Sergunb | 0:8918a71cdbe9 | 236 | **/ |
Sergunb | 0:8918a71cdbe9 | 237 | |
Sergunb | 0:8918a71cdbe9 | 238 | void bcm43362EnableIrq(NetInterface *interface) |
Sergunb | 0:8918a71cdbe9 | 239 | { |
Sergunb | 0:8918a71cdbe9 | 240 | } |
Sergunb | 0:8918a71cdbe9 | 241 | |
Sergunb | 0:8918a71cdbe9 | 242 | |
Sergunb | 0:8918a71cdbe9 | 243 | /** |
Sergunb | 0:8918a71cdbe9 | 244 | * @brief Disable interrupts |
Sergunb | 0:8918a71cdbe9 | 245 | * @param[in] interface Underlying network interface |
Sergunb | 0:8918a71cdbe9 | 246 | **/ |
Sergunb | 0:8918a71cdbe9 | 247 | |
Sergunb | 0:8918a71cdbe9 | 248 | void bcm43362DisableIrq(NetInterface *interface) |
Sergunb | 0:8918a71cdbe9 | 249 | { |
Sergunb | 0:8918a71cdbe9 | 250 | } |
Sergunb | 0:8918a71cdbe9 | 251 | |
Sergunb | 0:8918a71cdbe9 | 252 | |
Sergunb | 0:8918a71cdbe9 | 253 | /** |
Sergunb | 0:8918a71cdbe9 | 254 | * @brief BCM43362 interrupt service routine |
Sergunb | 0:8918a71cdbe9 | 255 | * @return TRUE if a higher priority task must be woken. Else FALSE is returned |
Sergunb | 0:8918a71cdbe9 | 256 | **/ |
Sergunb | 0:8918a71cdbe9 | 257 | |
Sergunb | 0:8918a71cdbe9 | 258 | bool_t bcm43362IrqHandler(void) |
Sergunb | 0:8918a71cdbe9 | 259 | { |
Sergunb | 0:8918a71cdbe9 | 260 | bool_t flag; |
Sergunb | 0:8918a71cdbe9 | 261 | |
Sergunb | 0:8918a71cdbe9 | 262 | //This flag will be set if a higher priority task must be woken |
Sergunb | 0:8918a71cdbe9 | 263 | flag = FALSE; |
Sergunb | 0:8918a71cdbe9 | 264 | |
Sergunb | 0:8918a71cdbe9 | 265 | //STA and/or AP mode? |
Sergunb | 0:8918a71cdbe9 | 266 | if(bcm43362StaInterface != NULL) |
Sergunb | 0:8918a71cdbe9 | 267 | bcm43362StaInterface->nicEvent = TRUE; |
Sergunb | 0:8918a71cdbe9 | 268 | else if(bcm43362ApInterface != NULL) |
Sergunb | 0:8918a71cdbe9 | 269 | bcm43362ApInterface->nicEvent = TRUE; |
Sergunb | 0:8918a71cdbe9 | 270 | |
Sergunb | 0:8918a71cdbe9 | 271 | //Notify the TCP/IP stack of the event |
Sergunb | 0:8918a71cdbe9 | 272 | flag = osSetEventFromIsr(&netEvent); |
Sergunb | 0:8918a71cdbe9 | 273 | |
Sergunb | 0:8918a71cdbe9 | 274 | //A higher priority task must be woken? |
Sergunb | 0:8918a71cdbe9 | 275 | return flag; |
Sergunb | 0:8918a71cdbe9 | 276 | } |
Sergunb | 0:8918a71cdbe9 | 277 | |
Sergunb | 0:8918a71cdbe9 | 278 | |
Sergunb | 0:8918a71cdbe9 | 279 | /** |
Sergunb | 0:8918a71cdbe9 | 280 | * @brief BCM43362 event handler |
Sergunb | 0:8918a71cdbe9 | 281 | * @param[in] interface Underlying network interface |
Sergunb | 0:8918a71cdbe9 | 282 | **/ |
Sergunb | 0:8918a71cdbe9 | 283 | |
Sergunb | 0:8918a71cdbe9 | 284 | void bcm43362EventHandler(NetInterface *interface) |
Sergunb | 0:8918a71cdbe9 | 285 | { |
Sergunb | 0:8918a71cdbe9 | 286 | } |
Sergunb | 0:8918a71cdbe9 | 287 | |
Sergunb | 0:8918a71cdbe9 | 288 | |
Sergunb | 0:8918a71cdbe9 | 289 | /** |
Sergunb | 0:8918a71cdbe9 | 290 | * @brief Send a packet |
Sergunb | 0:8918a71cdbe9 | 291 | * @param[in] interface Underlying network interface |
Sergunb | 0:8918a71cdbe9 | 292 | * @param[in] buffer Multi-part buffer containing the data to send |
Sergunb | 0:8918a71cdbe9 | 293 | * @param[in] offset Offset to the first data byte |
Sergunb | 0:8918a71cdbe9 | 294 | * @return Error code |
Sergunb | 0:8918a71cdbe9 | 295 | **/ |
Sergunb | 0:8918a71cdbe9 | 296 | |
Sergunb | 0:8918a71cdbe9 | 297 | error_t bcm43362SendPacket(NetInterface *interface, |
Sergunb | 0:8918a71cdbe9 | 298 | const NetBuffer *buffer, size_t offset) |
Sergunb | 0:8918a71cdbe9 | 299 | { |
Sergunb | 0:8918a71cdbe9 | 300 | wwd_result_t ret; |
Sergunb | 0:8918a71cdbe9 | 301 | wiced_buffer_t packet; |
Sergunb | 0:8918a71cdbe9 | 302 | size_t length; |
Sergunb | 0:8918a71cdbe9 | 303 | uint8_t *p; |
Sergunb | 0:8918a71cdbe9 | 304 | |
Sergunb | 0:8918a71cdbe9 | 305 | //Retrieve the length of the packet |
Sergunb | 0:8918a71cdbe9 | 306 | length = netBufferGetLength(buffer) - offset; |
Sergunb | 0:8918a71cdbe9 | 307 | |
Sergunb | 0:8918a71cdbe9 | 308 | //Allocate a network buffer |
Sergunb | 0:8918a71cdbe9 | 309 | ret = host_buffer_get(&packet, WWD_NETWORK_TX, length + WICED_LINK_OVERHEAD_BELOW_ETHERNET_FRAME_MAX, FALSE); |
Sergunb | 0:8918a71cdbe9 | 310 | |
Sergunb | 0:8918a71cdbe9 | 311 | //Check status code |
Sergunb | 0:8918a71cdbe9 | 312 | if(ret == WWD_SUCCESS) |
Sergunb | 0:8918a71cdbe9 | 313 | { |
Sergunb | 0:8918a71cdbe9 | 314 | //Make room for additional headers |
Sergunb | 0:8918a71cdbe9 | 315 | host_buffer_add_remove_at_front(&packet, WICED_LINK_OVERHEAD_BELOW_ETHERNET_FRAME_MAX); |
Sergunb | 0:8918a71cdbe9 | 316 | |
Sergunb | 0:8918a71cdbe9 | 317 | //Point to the data payload |
Sergunb | 0:8918a71cdbe9 | 318 | p = host_buffer_get_current_piece_data_pointer(packet); |
Sergunb | 0:8918a71cdbe9 | 319 | |
Sergunb | 0:8918a71cdbe9 | 320 | //Copy user data |
Sergunb | 0:8918a71cdbe9 | 321 | netBufferRead(p, buffer, offset, length); |
Sergunb | 0:8918a71cdbe9 | 322 | |
Sergunb | 0:8918a71cdbe9 | 323 | //Adjust the length of the buffer |
Sergunb | 0:8918a71cdbe9 | 324 | host_buffer_set_size(packet, length); |
Sergunb | 0:8918a71cdbe9 | 325 | |
Sergunb | 0:8918a71cdbe9 | 326 | //STA or AP mode? |
Sergunb | 0:8918a71cdbe9 | 327 | if(interface == bcm43362StaInterface) |
Sergunb | 0:8918a71cdbe9 | 328 | { |
Sergunb | 0:8918a71cdbe9 | 329 | //Send packet |
Sergunb | 0:8918a71cdbe9 | 330 | wwd_network_send_ethernet_data(packet, WWD_STA_INTERFACE); |
Sergunb | 0:8918a71cdbe9 | 331 | } |
Sergunb | 0:8918a71cdbe9 | 332 | else |
Sergunb | 0:8918a71cdbe9 | 333 | { |
Sergunb | 0:8918a71cdbe9 | 334 | //Send packet |
Sergunb | 0:8918a71cdbe9 | 335 | wwd_network_send_ethernet_data(packet, WWD_AP_INTERFACE); |
Sergunb | 0:8918a71cdbe9 | 336 | } |
Sergunb | 0:8918a71cdbe9 | 337 | } |
Sergunb | 0:8918a71cdbe9 | 338 | else |
Sergunb | 0:8918a71cdbe9 | 339 | { |
Sergunb | 0:8918a71cdbe9 | 340 | TRACE_ERROR("##### bcm43362SendPacket ALLOC FAILED ####\r\n"); |
Sergunb | 0:8918a71cdbe9 | 341 | } |
Sergunb | 0:8918a71cdbe9 | 342 | |
Sergunb | 0:8918a71cdbe9 | 343 | //The transmitter can accept another packet |
Sergunb | 0:8918a71cdbe9 | 344 | osSetEvent(&interface->nicTxEvent); |
Sergunb | 0:8918a71cdbe9 | 345 | |
Sergunb | 0:8918a71cdbe9 | 346 | //Return status code |
Sergunb | 0:8918a71cdbe9 | 347 | if(ret == WWD_SUCCESS) |
Sergunb | 0:8918a71cdbe9 | 348 | return NO_ERROR; |
Sergunb | 0:8918a71cdbe9 | 349 | else |
Sergunb | 0:8918a71cdbe9 | 350 | return ERROR_FAILURE; |
Sergunb | 0:8918a71cdbe9 | 351 | } |
Sergunb | 0:8918a71cdbe9 | 352 | |
Sergunb | 0:8918a71cdbe9 | 353 | |
Sergunb | 0:8918a71cdbe9 | 354 | /** |
Sergunb | 0:8918a71cdbe9 | 355 | * @brief Configure multicast MAC address filtering |
Sergunb | 0:8918a71cdbe9 | 356 | * @param[in] interface Underlying network interface |
Sergunb | 0:8918a71cdbe9 | 357 | * @return Error code |
Sergunb | 0:8918a71cdbe9 | 358 | **/ |
Sergunb | 0:8918a71cdbe9 | 359 | |
Sergunb | 0:8918a71cdbe9 | 360 | error_t bcm43362SetMulticastFilter(NetInterface *interface) |
Sergunb | 0:8918a71cdbe9 | 361 | { |
Sergunb | 0:8918a71cdbe9 | 362 | uint_t i; |
Sergunb | 0:8918a71cdbe9 | 363 | wwd_result_t ret; |
Sergunb | 0:8918a71cdbe9 | 364 | MacFilterEntry *entry; |
Sergunb | 0:8918a71cdbe9 | 365 | |
Sergunb | 0:8918a71cdbe9 | 366 | //Debug message |
Sergunb | 0:8918a71cdbe9 | 367 | TRACE_INFO("Updating BCM43362 multicast filter...\r\n"); |
Sergunb | 0:8918a71cdbe9 | 368 | |
Sergunb | 0:8918a71cdbe9 | 369 | //STA interface? |
Sergunb | 0:8918a71cdbe9 | 370 | if(interface == bcm43362StaInterface) |
Sergunb | 0:8918a71cdbe9 | 371 | { |
Sergunb | 0:8918a71cdbe9 | 372 | //The MAC filter table contains the multicast MAC addresses |
Sergunb | 0:8918a71cdbe9 | 373 | //to accept when receiving an Ethernet frame |
Sergunb | 0:8918a71cdbe9 | 374 | for(i = 0; i < MAC_MULTICAST_FILTER_SIZE; i++) |
Sergunb | 0:8918a71cdbe9 | 375 | { |
Sergunb | 0:8918a71cdbe9 | 376 | //Point to the current entry |
Sergunb | 0:8918a71cdbe9 | 377 | entry = &interface->macMulticastFilter[i]; |
Sergunb | 0:8918a71cdbe9 | 378 | |
Sergunb | 0:8918a71cdbe9 | 379 | //Check whether the MAC filter table should be updated for the |
Sergunb | 0:8918a71cdbe9 | 380 | //current multicast address |
Sergunb | 0:8918a71cdbe9 | 381 | if(!macCompAddr(&entry->addr, &MAC_UNSPECIFIED_ADDR)) |
Sergunb | 0:8918a71cdbe9 | 382 | { |
Sergunb | 0:8918a71cdbe9 | 383 | if(entry->addFlag) |
Sergunb | 0:8918a71cdbe9 | 384 | { |
Sergunb | 0:8918a71cdbe9 | 385 | //Add a new entry to the MAC filter table |
Sergunb | 0:8918a71cdbe9 | 386 | //ret = wwd_wifi_register_multicast_address((wiced_mac_t *) entry->addr.b); |
Sergunb | 0:8918a71cdbe9 | 387 | //TRACE_ERROR("wwd_wifi_register_multicast_address=%d (0x%04X)\r\n", ret, ret); |
Sergunb | 0:8918a71cdbe9 | 388 | } |
Sergunb | 0:8918a71cdbe9 | 389 | else if(entry->deleteFlag) |
Sergunb | 0:8918a71cdbe9 | 390 | { |
Sergunb | 0:8918a71cdbe9 | 391 | //Remove the current entry from the MAC filter table |
Sergunb | 0:8918a71cdbe9 | 392 | //ret = wwd_wifi_unregister_multicast_address((wiced_mac_t *) entry->addr.b); |
Sergunb | 0:8918a71cdbe9 | 393 | //TRACE_ERROR("wwd_wifi_unregister_multicast_address=%d (0x%04X)\r\n", ret, ret); |
Sergunb | 0:8918a71cdbe9 | 394 | } |
Sergunb | 0:8918a71cdbe9 | 395 | } |
Sergunb | 0:8918a71cdbe9 | 396 | } |
Sergunb | 0:8918a71cdbe9 | 397 | } |
Sergunb | 0:8918a71cdbe9 | 398 | |
Sergunb | 0:8918a71cdbe9 | 399 | //Successful processing |
Sergunb | 0:8918a71cdbe9 | 400 | return NO_ERROR; |
Sergunb | 0:8918a71cdbe9 | 401 | } |
Sergunb | 0:8918a71cdbe9 | 402 | |
Sergunb | 0:8918a71cdbe9 | 403 | |
Sergunb | 0:8918a71cdbe9 | 404 | /** |
Sergunb | 0:8918a71cdbe9 | 405 | * @brief Callback function that handles Wi-Fi events |
Sergunb | 0:8918a71cdbe9 | 406 | **/ |
Sergunb | 0:8918a71cdbe9 | 407 | |
Sergunb | 0:8918a71cdbe9 | 408 | void *app_wifi_event_handler(const wwd_event_header_t *event_header, const uint8_t *event_data, void *handler_user_data) |
Sergunb | 0:8918a71cdbe9 | 409 | { |
Sergunb | 0:8918a71cdbe9 | 410 | //Check event type |
Sergunb | 0:8918a71cdbe9 | 411 | switch(event_header->event_type) |
Sergunb | 0:8918a71cdbe9 | 412 | { |
Sergunb | 0:8918a71cdbe9 | 413 | //I/F change? |
Sergunb | 0:8918a71cdbe9 | 414 | case WLC_E_IF: |
Sergunb | 0:8918a71cdbe9 | 415 | TRACE_INFO("### app_wifi_event_handler: WLC_E_IF\r\n"); |
Sergunb | 0:8918a71cdbe9 | 416 | break; |
Sergunb | 0:8918a71cdbe9 | 417 | |
Sergunb | 0:8918a71cdbe9 | 418 | //802.11 ASSOC indication? |
Sergunb | 0:8918a71cdbe9 | 419 | case WLC_E_ASSOC_IND: |
Sergunb | 0:8918a71cdbe9 | 420 | TRACE_INFO("### app_wifi_event_handler: WLC_E_ASSOC_IND\r\n"); |
Sergunb | 0:8918a71cdbe9 | 421 | break; |
Sergunb | 0:8918a71cdbe9 | 422 | |
Sergunb | 0:8918a71cdbe9 | 423 | //802.11 DISASSOC indication? |
Sergunb | 0:8918a71cdbe9 | 424 | case WLC_E_DISASSOC_IND: |
Sergunb | 0:8918a71cdbe9 | 425 | TRACE_INFO("### app_wifi_event_handler: WLC_E_DISASSOC_IND\r\n"); |
Sergunb | 0:8918a71cdbe9 | 426 | break; |
Sergunb | 0:8918a71cdbe9 | 427 | |
Sergunb | 0:8918a71cdbe9 | 428 | //Generic link indication? |
Sergunb | 0:8918a71cdbe9 | 429 | case WLC_E_LINK: |
Sergunb | 0:8918a71cdbe9 | 430 | //Debug message |
Sergunb | 0:8918a71cdbe9 | 431 | TRACE_INFO("### app_wifi_event_handler: WLC_E_LINK\r\n"); |
Sergunb | 0:8918a71cdbe9 | 432 | |
Sergunb | 0:8918a71cdbe9 | 433 | //STA interface? |
Sergunb | 0:8918a71cdbe9 | 434 | if(event_header->interface == WWD_STA_INTERFACE) |
Sergunb | 0:8918a71cdbe9 | 435 | { |
Sergunb | 0:8918a71cdbe9 | 436 | if(bcm43362StaInterface != NULL) |
Sergunb | 0:8918a71cdbe9 | 437 | { |
Sergunb | 0:8918a71cdbe9 | 438 | //Check link state |
Sergunb | 0:8918a71cdbe9 | 439 | if(event_header->flags & 0x01) |
Sergunb | 0:8918a71cdbe9 | 440 | bcm43362StaInterface->linkState = TRUE; |
Sergunb | 0:8918a71cdbe9 | 441 | else |
Sergunb | 0:8918a71cdbe9 | 442 | bcm43362StaInterface->linkState = FALSE; |
Sergunb | 0:8918a71cdbe9 | 443 | |
Sergunb | 0:8918a71cdbe9 | 444 | //Get exclusive access |
Sergunb | 0:8918a71cdbe9 | 445 | osAcquireMutex(&netMutex); |
Sergunb | 0:8918a71cdbe9 | 446 | //Process link state change event |
Sergunb | 0:8918a71cdbe9 | 447 | nicNotifyLinkChange(bcm43362StaInterface); |
Sergunb | 0:8918a71cdbe9 | 448 | //Release exclusive access |
Sergunb | 0:8918a71cdbe9 | 449 | osReleaseMutex(&netMutex); |
Sergunb | 0:8918a71cdbe9 | 450 | } |
Sergunb | 0:8918a71cdbe9 | 451 | } |
Sergunb | 0:8918a71cdbe9 | 452 | //AP interface? |
Sergunb | 0:8918a71cdbe9 | 453 | else if(event_header->interface == WWD_AP_INTERFACE) |
Sergunb | 0:8918a71cdbe9 | 454 | { |
Sergunb | 0:8918a71cdbe9 | 455 | if(bcm43362ApInterface != NULL) |
Sergunb | 0:8918a71cdbe9 | 456 | { |
Sergunb | 0:8918a71cdbe9 | 457 | //Check link state |
Sergunb | 0:8918a71cdbe9 | 458 | if(event_header->flags & 0x01) |
Sergunb | 0:8918a71cdbe9 | 459 | bcm43362ApInterface->linkState = TRUE; |
Sergunb | 0:8918a71cdbe9 | 460 | else |
Sergunb | 0:8918a71cdbe9 | 461 | bcm43362ApInterface->linkState = FALSE; |
Sergunb | 0:8918a71cdbe9 | 462 | |
Sergunb | 0:8918a71cdbe9 | 463 | //Get exclusive access |
Sergunb | 0:8918a71cdbe9 | 464 | osAcquireMutex(&netMutex); |
Sergunb | 0:8918a71cdbe9 | 465 | //Process link state change event |
Sergunb | 0:8918a71cdbe9 | 466 | nicNotifyLinkChange(bcm43362ApInterface); |
Sergunb | 0:8918a71cdbe9 | 467 | //Release exclusive access |
Sergunb | 0:8918a71cdbe9 | 468 | osReleaseMutex(&netMutex); |
Sergunb | 0:8918a71cdbe9 | 469 | } |
Sergunb | 0:8918a71cdbe9 | 470 | } |
Sergunb | 0:8918a71cdbe9 | 471 | |
Sergunb | 0:8918a71cdbe9 | 472 | break; |
Sergunb | 0:8918a71cdbe9 | 473 | |
Sergunb | 0:8918a71cdbe9 | 474 | //Unknown event? |
Sergunb | 0:8918a71cdbe9 | 475 | default: |
Sergunb | 0:8918a71cdbe9 | 476 | TRACE_INFO("### app_wifi_event_handler: Unknown event\r\n"); |
Sergunb | 0:8918a71cdbe9 | 477 | break; |
Sergunb | 0:8918a71cdbe9 | 478 | } |
Sergunb | 0:8918a71cdbe9 | 479 | |
Sergunb | 0:8918a71cdbe9 | 480 | return handler_user_data; |
Sergunb | 0:8918a71cdbe9 | 481 | } |
Sergunb | 0:8918a71cdbe9 | 482 | |
Sergunb | 0:8918a71cdbe9 | 483 | |
Sergunb | 0:8918a71cdbe9 | 484 | /** |
Sergunb | 0:8918a71cdbe9 | 485 | * @brief Callback function that handles incoming packets |
Sergunb | 0:8918a71cdbe9 | 486 | **/ |
Sergunb | 0:8918a71cdbe9 | 487 | |
Sergunb | 0:8918a71cdbe9 | 488 | void host_network_process_ethernet_data(wiced_buffer_t buffer, wwd_interface_t interface) |
Sergunb | 0:8918a71cdbe9 | 489 | { |
Sergunb | 0:8918a71cdbe9 | 490 | size_t n; |
Sergunb | 0:8918a71cdbe9 | 491 | uint8_t *p; |
Sergunb | 0:8918a71cdbe9 | 492 | |
Sergunb | 0:8918a71cdbe9 | 493 | //Point to the incoming packet |
Sergunb | 0:8918a71cdbe9 | 494 | p = host_buffer_get_current_piece_data_pointer(buffer); |
Sergunb | 0:8918a71cdbe9 | 495 | //Retrieve the length of the packet |
Sergunb | 0:8918a71cdbe9 | 496 | n = host_buffer_get_current_piece_size(buffer); |
Sergunb | 0:8918a71cdbe9 | 497 | |
Sergunb | 0:8918a71cdbe9 | 498 | //Valid packet received? |
Sergunb | 0:8918a71cdbe9 | 499 | if(p != NULL && n > 0) |
Sergunb | 0:8918a71cdbe9 | 500 | { |
Sergunb | 0:8918a71cdbe9 | 501 | if(interface == WWD_STA_INTERFACE) |
Sergunb | 0:8918a71cdbe9 | 502 | { |
Sergunb | 0:8918a71cdbe9 | 503 | if(bcm43362StaInterface != NULL) |
Sergunb | 0:8918a71cdbe9 | 504 | { |
Sergunb | 0:8918a71cdbe9 | 505 | //Get exclusive access |
Sergunb | 0:8918a71cdbe9 | 506 | osAcquireMutex(&netMutex); |
Sergunb | 0:8918a71cdbe9 | 507 | //Process link state change event |
Sergunb | 0:8918a71cdbe9 | 508 | nicProcessPacket(bcm43362StaInterface, p, n); |
Sergunb | 0:8918a71cdbe9 | 509 | //Release exclusive access |
Sergunb | 0:8918a71cdbe9 | 510 | osReleaseMutex(&netMutex); |
Sergunb | 0:8918a71cdbe9 | 511 | } |
Sergunb | 0:8918a71cdbe9 | 512 | } |
Sergunb | 0:8918a71cdbe9 | 513 | else if(interface == WWD_AP_INTERFACE) |
Sergunb | 0:8918a71cdbe9 | 514 | { |
Sergunb | 0:8918a71cdbe9 | 515 | if(bcm43362ApInterface != NULL) |
Sergunb | 0:8918a71cdbe9 | 516 | { |
Sergunb | 0:8918a71cdbe9 | 517 | //Get exclusive access |
Sergunb | 0:8918a71cdbe9 | 518 | osAcquireMutex(&netMutex); |
Sergunb | 0:8918a71cdbe9 | 519 | //Process link state change event |
Sergunb | 0:8918a71cdbe9 | 520 | nicProcessPacket(bcm43362ApInterface, p, n); |
Sergunb | 0:8918a71cdbe9 | 521 | //Release exclusive access |
Sergunb | 0:8918a71cdbe9 | 522 | osReleaseMutex(&netMutex); |
Sergunb | 0:8918a71cdbe9 | 523 | } |
Sergunb | 0:8918a71cdbe9 | 524 | } |
Sergunb | 0:8918a71cdbe9 | 525 | } |
Sergunb | 0:8918a71cdbe9 | 526 | |
Sergunb | 0:8918a71cdbe9 | 527 | //Release network buffer |
Sergunb | 0:8918a71cdbe9 | 528 | host_buffer_release(buffer, WWD_NETWORK_RX); |
Sergunb | 0:8918a71cdbe9 | 529 | } |
Sergunb | 0:8918a71cdbe9 | 530 | |
Sergunb | 0:8918a71cdbe9 | 531 | |
Sergunb | 0:8918a71cdbe9 | 532 | //Miscellaneous WICED dependencies |
Sergunb | 0:8918a71cdbe9 | 533 | signed int xTaskIsTaskFinished(void *xTask) |
Sergunb | 0:8918a71cdbe9 | 534 | { |
Sergunb | 0:8918a71cdbe9 | 535 | TRACE_INFO("### xTaskIsTaskFinished\r\n"); |
Sergunb | 0:8918a71cdbe9 | 536 | return pdTRUE; |
Sergunb | 0:8918a71cdbe9 | 537 | } |
Sergunb | 0:8918a71cdbe9 | 538 | |
Sergunb | 0:8918a71cdbe9 | 539 | portBASE_TYPE vTaskFreeTerminated(TaskHandle_t xTask) |
Sergunb | 0:8918a71cdbe9 | 540 | { |
Sergunb | 0:8918a71cdbe9 | 541 | TRACE_INFO("### vTaskFreeTerminated\r\n"); |
Sergunb | 0:8918a71cdbe9 | 542 | return pdTRUE; |
Sergunb | 0:8918a71cdbe9 | 543 | } |
Sergunb | 0:8918a71cdbe9 | 544 |