wlan.c (10491B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 * 7 * File: bcmx/wlan.c 8 * Purpose: BCMX Wireless LAN APIs 9 */ 10 11 #ifdef INCLUDE_L3 12 13 #include <bcm/types.h> 14 15 #include <bcmx/lport.h> 16 #include <bcmx/wlan.h> 17 #include "bcmx_int.h" 18 19 #define BCMX_WLAN_INIT_CHECK BCMX_READY_CHECK 20 21 #define BCMX_WLAN_ERROR_CHECK(_unit, _check, _rv) \ 22 BCMX_ERROR_CHECK(_unit, _check, _rv) 23 24 #define BCMX_WLAN_SET_ERROR_CHECK(_unit, _check, _rv) \ 25 BCMX_SET_ERROR_CHECK(_unit, _check, _rv) 26 27 #define BCMX_WLAN_DELETE_ERROR_CHECK(_unit, _check, _rv) \ 28 BCMX_DELETE_ERROR_CHECK(_unit, _check, _rv) 29 30 #define BCMX_WLAN_GET_IS_VALID(_unit, _rv) \ 31 BCMX_ERROR_IS_VALID(_unit, _rv) 32 33 34 #define BCMX_WLAN_PORT_T_PTR_TO_BCM(_port) \ 35 ((bcm_wlan_port_t *)(_port)) 36 37 #define BCMX_WLAN_CLIENT_T_PTR_TO_BCM(_client) \ 38 ((bcm_wlan_client_t *)(_client)) 39 40 #define BCMX_TUNNEL_INITIATOR_T_PTR_TO_BCM(_tunnel) \ 41 ((bcm_tunnel_initiator_t *)(_tunnel)) 42 43 44 /* 45 * Function: 46 * bcmx_wlan_port_t_init 47 */ 48 void 49 bcmx_wlan_port_t_init(bcmx_wlan_port_t *wlan_port) 50 { 51 if (wlan_port != NULL) { 52 bcm_wlan_port_t_init(BCMX_WLAN_PORT_T_PTR_TO_BCM(wlan_port)); 53 } 54 } 55 56 /* 57 * Function: 58 * bcmx_wlan_client_t_init 59 */ 60 void 61 bcmx_wlan_client_t_init(bcmx_wlan_client_t *wlan_client) 62 { 63 if (wlan_client != NULL) { 64 bcm_wlan_client_t_init(BCMX_WLAN_CLIENT_T_PTR_TO_BCM(wlan_client)); 65 } 66 } 67 68 69 /* 70 * Function: 71 * bcmx_wlan_init 72 * Purpose: 73 * Initialize the Wireless LAN module. 74 * Parameters: 75 * None 76 * Returns: 77 * BCM_E_XXX 78 * Notes: 79 */ 80 int 81 bcmx_wlan_init(void) 82 { 83 int rv = BCM_E_UNAVAIL, tmp_rv; 84 int i, bcm_unit; 85 86 BCMX_WLAN_INIT_CHECK; 87 88 BCMX_UNIT_ITER(bcm_unit, i) { 89 tmp_rv = bcm_wlan_init(bcm_unit); 90 BCM_IF_ERROR_RETURN(BCMX_WLAN_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 91 } 92 93 return rv; 94 } 95 96 /* 97 * Function: 98 * bcmx_wlan_detach 99 * Purpose: 100 * Detach the Wireless LAN software module. 101 * Parameters: 102 * None 103 * Returns: 104 * BCM_E_XXX 105 * Notes: 106 */ 107 int 108 bcmx_wlan_detach(void) 109 { 110 int rv = BCM_E_UNAVAIL, tmp_rv; 111 int i, bcm_unit; 112 113 BCMX_WLAN_INIT_CHECK; 114 115 BCMX_UNIT_ITER(bcm_unit, i) { 116 tmp_rv = bcm_wlan_detach(bcm_unit); 117 BCM_IF_ERROR_RETURN(BCMX_WLAN_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 118 } 119 120 return rv; 121 } 122 123 /* 124 * Function: 125 * bcmx_wlan_port_add 126 * Purpose: 127 * Create or replace a WLAN port. 128 * Parameters: 129 * info - (IN/OUT) WLAN port configuration info 130 * Returns: 131 * BCM_E_XXX 132 * Notes: 133 * WLAN port is a global entity, apply to all units. 134 */ 135 int 136 bcmx_wlan_port_add(bcmx_wlan_port_t *info) 137 { 138 int rv = BCM_E_UNAVAIL, tmp_rv; 139 int i, bcm_unit; 140 uint32 flags_orig; 141 142 BCMX_WLAN_INIT_CHECK; 143 144 BCMX_PARAM_NULL_CHECK(info); 145 146 /* Store original 'xxx_WITH_ID' flag bit */ 147 flags_orig = info->flags & BCM_WLAN_PORT_WITH_ID; 148 149 BCMX_UNIT_ITER(bcm_unit, i) { 150 tmp_rv = bcm_wlan_port_add(bcm_unit, 151 BCMX_WLAN_PORT_T_PTR_TO_BCM(info)); 152 if (BCM_FAILURE(BCMX_WLAN_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv))) { 153 break; 154 } 155 156 /* 157 * Use the ID from first successful 'create' if WLAN port ID 158 * is not specified. 159 */ 160 if (!(info->flags & BCM_WLAN_PORT_WITH_ID)) { 161 if (BCM_SUCCESS(tmp_rv)) { 162 info->flags |= BCM_WLAN_PORT_WITH_ID; 163 } 164 } 165 } 166 167 /* Restore 'xxx_WITH_ID' flag bit */ 168 info->flags &= ~BCM_WLAN_PORT_WITH_ID; 169 info->flags |= flags_orig; 170 171 172 return rv; 173 } 174 175 /* 176 * Function: 177 * bcmx_wlan_port_delete 178 * Purpose: 179 * Delete a WLAN port. 180 * Parameters: 181 * wlan_port_id - WLAN port id to delete 182 * Returns: 183 * BCM_E_XXX 184 */ 185 int 186 bcmx_wlan_port_delete(bcm_gport_t wlan_port_id) 187 { 188 int rv = BCM_E_UNAVAIL, tmp_rv; 189 int i, bcm_unit; 190 191 BCMX_WLAN_INIT_CHECK; 192 193 BCMX_UNIT_ITER(bcm_unit, i) { 194 tmp_rv = bcm_wlan_port_delete(bcm_unit, wlan_port_id); 195 BCM_IF_ERROR_RETURN 196 (BCMX_WLAN_DELETE_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 197 } 198 199 return rv; 200 } 201 202 /* 203 * Function: 204 * bcmx_wlan_port_delete_all 205 * Purpose: 206 * Delete all WLAN ports. 207 * Parameters: 208 * None 209 * Returns: 210 * BCM_E_XXX 211 */ 212 int 213 bcmx_wlan_port_delete_all(void) 214 { 215 int rv = BCM_E_UNAVAIL, tmp_rv; 216 int i, bcm_unit; 217 218 BCMX_WLAN_INIT_CHECK; 219 220 BCMX_UNIT_ITER(bcm_unit, i) { 221 tmp_rv = bcm_wlan_port_delete_all(bcm_unit); 222 BCM_IF_ERROR_RETURN 223 (BCMX_WLAN_DELETE_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 224 } 225 226 return rv; 227 } 228 229 /* 230 * Function: 231 * bcmx_wlan_port_get 232 * Purpose: 233 * Get WLAN port information for given ID. 234 * Parameters: 235 * wlan_port_id - WLAN port id 236 * info - (IN/OUT) WLAN port configuration info 237 * Returns: 238 * BCM_E_XXX 239 */ 240 int 241 bcmx_wlan_port_get(bcm_gport_t wlan_port_id, bcmx_wlan_port_t *info) 242 { 243 int rv; 244 int i, bcm_unit; 245 246 BCMX_WLAN_INIT_CHECK; 247 248 BCMX_PARAM_NULL_CHECK(info); 249 250 BCMX_UNIT_ITER(bcm_unit, i) { 251 rv = bcm_wlan_port_get(bcm_unit, wlan_port_id, 252 BCMX_WLAN_PORT_T_PTR_TO_BCM(info)); 253 if (BCMX_WLAN_GET_IS_VALID(bcm_unit, rv)) { 254 return rv; 255 } 256 } 257 258 return BCM_E_UNAVAIL; 259 } 260 261 /* 262 * Function: 263 * bcmx_wlan_client_add 264 * Purpose: 265 * Add a wireless client to the database. 266 * Parameters: 267 * info - (IN/OUT) Wireless client structure 268 * Returns: 269 * BCM_E_XXX 270 * Notes: 271 * WLAN client is a global entity, apply to all units. 272 */ 273 int 274 bcmx_wlan_client_add(bcmx_wlan_client_t *info) 275 { 276 int rv = BCM_E_UNAVAIL, tmp_rv; 277 int i, bcm_unit; 278 279 BCMX_WLAN_INIT_CHECK; 280 281 BCMX_PARAM_NULL_CHECK(info); 282 283 BCMX_UNIT_ITER(bcm_unit, i) { 284 tmp_rv = bcm_wlan_client_add(bcm_unit, 285 BCMX_WLAN_CLIENT_T_PTR_TO_BCM(info)); 286 BCM_IF_ERROR_RETURN(BCMX_WLAN_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 287 } 288 289 return rv; 290 } 291 292 /* 293 * Function: 294 * bcmx_wlan_client_delete 295 * Purpose: 296 * Delete a wireless client from the database. 297 * Parameters: 298 * mac - MAC address of client (lookup key) 299 * Returns: 300 * BCM_E_XXX 301 */ 302 int 303 bcmx_wlan_client_delete(bcm_mac_t mac) 304 { 305 int rv = BCM_E_UNAVAIL, tmp_rv; 306 int i, bcm_unit; 307 308 BCMX_WLAN_INIT_CHECK; 309 310 BCMX_UNIT_ITER(bcm_unit, i) { 311 tmp_rv = bcm_wlan_client_delete(bcm_unit, mac); 312 BCM_IF_ERROR_RETURN 313 (BCMX_WLAN_DELETE_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 314 } 315 316 return rv; 317 } 318 319 /* 320 * Function: 321 * bcmx_wlan_client_delete_all 322 * Purpose: 323 * Delete all wireless clients from the database. 324 * Parameters: 325 * None 326 * Returns: 327 * BCM_E_XXX 328 */ 329 int 330 bcmx_wlan_client_delete_all(void) 331 { 332 int rv = BCM_E_UNAVAIL, tmp_rv; 333 int i, bcm_unit; 334 335 BCMX_WLAN_INIT_CHECK; 336 337 BCMX_UNIT_ITER(bcm_unit, i) { 338 tmp_rv = bcm_wlan_client_delete_all(bcm_unit); 339 BCM_IF_ERROR_RETURN 340 (BCMX_WLAN_DELETE_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 341 } 342 343 return rv; 344 } 345 346 /* 347 * Function: 348 * bcmx_wlan_client_get 349 * Purpose: 350 * Get a wireless client information for given MAC. 351 * Parameters: 352 * mac - MAC address of client (lookup key) 353 * info - (IN/OUT) Wireless client info 354 * Returns: 355 * BCM_E_XXX 356 */ 357 int 358 bcmx_wlan_client_get(bcm_mac_t mac, bcmx_wlan_client_t *info) 359 { 360 int rv; 361 int i, bcm_unit; 362 363 BCMX_WLAN_INIT_CHECK; 364 365 BCMX_PARAM_NULL_CHECK(info); 366 367 BCMX_UNIT_ITER(bcm_unit, i) { 368 rv = bcm_wlan_client_get(bcm_unit, mac, 369 BCMX_WLAN_CLIENT_T_PTR_TO_BCM(info)); 370 if (BCMX_WLAN_GET_IS_VALID(bcm_unit, rv)) { 371 return rv; 372 } 373 } 374 375 return BCM_E_UNAVAIL; 376 } 377 378 /* 379 * Function: 380 * bcmx_wlan_tunnel_initiator_create 381 * Purpose: 382 * Create an outgoing CAPWAP tunnel. 383 * Parameters: 384 * info - (IN/OUT) Tunnel initiator structure 385 * Returns: 386 * BCM_E_XXX 387 */ 388 int 389 bcmx_wlan_tunnel_initiator_create(bcmx_tunnel_initiator_t *info) 390 { 391 int rv = BCM_E_UNAVAIL, tmp_rv; 392 int i, bcm_unit; 393 uint32 flags_orig; 394 395 BCMX_WLAN_INIT_CHECK; 396 397 BCMX_PARAM_NULL_CHECK(info); 398 399 /* Store original 'xxx_WITH_ID' flag bit */ 400 flags_orig = info->flags & BCM_TUNNEL_INIT_WLAN_TUNNEL_WITH_ID; 401 402 BCMX_UNIT_ITER(bcm_unit, i) { 403 tmp_rv = bcm_wlan_tunnel_initiator_create 404 (bcm_unit, 405 BCMX_TUNNEL_INITIATOR_T_PTR_TO_BCM(info)); 406 if (BCM_FAILURE(BCMX_WLAN_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv))) { 407 break; 408 } 409 410 /* 411 * Use the ID from first successful 'create' if ID 412 * is not specified. 413 */ 414 if (!(info->flags & BCM_TUNNEL_INIT_WLAN_TUNNEL_WITH_ID)) { 415 if (BCM_SUCCESS(tmp_rv)) { 416 info->flags |= BCM_TUNNEL_INIT_WLAN_TUNNEL_WITH_ID; 417 } 418 } 419 } 420 421 /* Restore 'xxx_WITH_ID' flag bit */ 422 info->flags &= ~BCM_TUNNEL_INIT_WLAN_TUNNEL_WITH_ID; 423 info->flags |= flags_orig; 424 425 return rv; 426 } 427 428 /* 429 * Function: 430 * bcmx_wlan_tunnel_initiator_destroy 431 * Purpose: 432 * Destroy an outgoing CAPWAP tunnel. 433 * Parameters: 434 * wlan_tunnel_id - Tunnel ID (gport) 435 * Returns: 436 * BCM_E_XXX 437 */ 438 int 439 bcmx_wlan_tunnel_initiator_destroy(bcm_gport_t wlan_tunnel_id) 440 { 441 int rv = BCM_E_UNAVAIL, tmp_rv; 442 int i, bcm_unit; 443 444 BCMX_WLAN_INIT_CHECK; 445 446 BCMX_UNIT_ITER(bcm_unit, i) { 447 tmp_rv = bcm_wlan_tunnel_initiator_destroy(bcm_unit, wlan_tunnel_id); 448 BCM_IF_ERROR_RETURN 449 (BCMX_WLAN_DELETE_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 450 } 451 452 return rv; 453 } 454 455 /* 456 * Function: 457 * bcmx_wlan_tunnel_initiator_get 458 * Purpose: 459 * Get an outgoing CAPWAP tunnel. 460 * Parameters: 461 * info - (IN/OUT) Tunnel initiator structure 462 * Returns: 463 * BCM_E_XXX 464 */ 465 int 466 bcmx_wlan_tunnel_initiator_get(bcmx_tunnel_initiator_t *info) 467 { 468 int rv; 469 int i, bcm_unit; 470 471 BCMX_WLAN_INIT_CHECK; 472 473 BCMX_PARAM_NULL_CHECK(info); 474 475 BCMX_UNIT_ITER(bcm_unit, i) { 476 rv = bcm_wlan_tunnel_initiator_get(bcm_unit, 477 BCMX_TUNNEL_INITIATOR_T_PTR_TO_BCM 478 (info)); 479 if (BCMX_WLAN_GET_IS_VALID(bcm_unit, rv)) { 480 return rv; 481 } 482 } 483 484 return BCM_E_UNAVAIL; 485 } 486 487 #endif /* INCLUDE_L3 */