openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

auth.c (4199B)


      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/auth.c
      8  * Purpose:	BCMX 802.1x support
      9  */
     10 
     11 #include <bcm/types.h>
     12 
     13 #include <bcmx/auth.h>
     14 #include <bcmx/lport.h>
     15 #include <bcmx/bcmx.h>
     16 
     17 #include "bcmx_int.h"
     18 
     19 #define BCMX_AUTH_INIT_CHECK    BCMX_READY_CHECK
     20 
     21 #define BCMX_AUTH_SET_ERROR_CHECK(_unit, _check, _rv)    \
     22     BCMX_SET_ERROR_CHECK(_unit, _check, _rv)
     23 
     24 int
     25 bcmx_auth_mode_set(bcmx_lport_t port, uint32 mode)
     26 {
     27     int         bcm_unit;
     28     bcm_port_t  bcm_port;
     29 
     30     BCMX_AUTH_INIT_CHECK;
     31 
     32     BCM_IF_ERROR_RETURN
     33         (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port,
     34                                  BCMX_DEST_CONVERT_DEFAULT));
     35 
     36     return bcm_auth_mode_set(bcm_unit, bcm_port, mode);
     37 }
     38 
     39 int
     40 bcmx_auth_mode_get(bcmx_lport_t port, uint32 *mode)
     41 {
     42     int         bcm_unit;
     43     bcm_port_t  bcm_port;
     44 
     45     BCMX_AUTH_INIT_CHECK;
     46 
     47     BCM_IF_ERROR_RETURN
     48         (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port,
     49                                  BCMX_DEST_CONVERT_DEFAULT));
     50 
     51     return bcm_auth_mode_get(bcm_unit, bcm_port, mode);
     52 }
     53 
     54 /* Currently, only one auth_unauth callback is supported
     55  * at the BCMX layer.
     56  */
     57 
     58 STATIC bcmx_auth_cb_t ap_auth_cb_fn = NULL;
     59 STATIC void *ap_auth_cookie = NULL;
     60 
     61 STATIC void
     62 _bcmx_auth_cb(void *cookie, int unit, int port, int reason)
     63 {
     64     bcmx_lport_t lport;
     65 
     66     if (BCM_FAILURE(_bcmx_dest_from_unit_port(&lport,
     67                                               unit, (bcm_port_t)port,
     68                                               BCMX_DEST_CONVERT_DEFAULT))) {
     69         return;
     70     }
     71 
     72     if (ap_auth_cb_fn != NULL) {
     73         (*ap_auth_cb_fn)(ap_auth_cookie, lport, reason);
     74     }
     75 }
     76 
     77 
     78 /*
     79  * This routine registers through rlink to get remote device's
     80  * calls.
     81  */
     82 
     83 int
     84 bcmx_auth_unauth_callback(bcmx_auth_cb_t func, void *cookie)
     85 {
     86     int rv = BCM_E_UNAVAIL, tmp_rv;
     87     int i, bcm_unit;
     88     bcm_auth_cb_t cb_f = NULL;
     89 
     90     BCMX_AUTH_INIT_CHECK;
     91 
     92     ap_auth_cb_fn = func;
     93     ap_auth_cookie = cookie;
     94     if (func != NULL) {
     95         /* If ap function is non-NULL, register with BCMX's callback */
     96         cb_f = _bcmx_auth_cb;
     97     }
     98 
     99     BCMX_UNIT_ITER(bcm_unit, i) {
    100         tmp_rv = bcm_auth_unauth_callback(bcm_unit, cb_f, cookie);
    101         BCM_IF_ERROR_RETURN(BCMX_AUTH_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv));
    102     }
    103 
    104     return rv;
    105 }
    106 
    107 int
    108 bcmx_auth_egress_set(bcmx_lport_t port, int enable)
    109 {
    110     int         bcm_unit;
    111     bcm_port_t  bcm_port;
    112 
    113     BCMX_AUTH_INIT_CHECK;
    114 
    115     BCM_IF_ERROR_RETURN
    116         (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port,
    117                                  BCMX_DEST_CONVERT_DEFAULT));
    118 
    119     return bcm_auth_egress_set(bcm_unit, bcm_port, enable);
    120 }
    121 
    122 int
    123 bcmx_auth_egress_get(bcmx_lport_t port, int *enable)
    124 {
    125     int         bcm_unit;
    126     bcm_port_t  bcm_port;
    127 
    128     BCMX_AUTH_INIT_CHECK;
    129 
    130     BCM_IF_ERROR_RETURN
    131         (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port,
    132                                  BCMX_DEST_CONVERT_DEFAULT));
    133 
    134     return bcm_auth_egress_get(bcm_unit, bcm_port, enable);
    135 }
    136 
    137 int
    138 bcmx_auth_mac_add(bcmx_lport_t port, bcm_mac_t mac)
    139 {
    140     int         bcm_unit;
    141     bcm_port_t  bcm_port;
    142 
    143     BCMX_AUTH_INIT_CHECK;
    144 
    145     BCM_IF_ERROR_RETURN
    146         (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port,
    147                                  BCMX_DEST_CONVERT_DEFAULT));
    148 
    149     return bcm_auth_mac_add(bcm_unit, bcm_port, mac);
    150 }
    151 
    152 int
    153 bcmx_auth_mac_delete(bcmx_lport_t port, bcm_mac_t mac)
    154 {
    155     int         bcm_unit;
    156     bcm_port_t  bcm_port;
    157 
    158     BCMX_AUTH_INIT_CHECK;
    159 
    160     BCM_IF_ERROR_RETURN
    161         (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port,
    162                                  BCMX_DEST_CONVERT_DEFAULT));
    163 
    164     return bcm_auth_mac_delete(bcm_unit, bcm_port, mac);
    165 }
    166 
    167 int
    168 bcmx_auth_mac_delete_all(bcmx_lport_t port)
    169 {
    170     int         bcm_unit;
    171     bcm_port_t  bcm_port;
    172 
    173     BCMX_AUTH_INIT_CHECK;
    174 
    175     BCM_IF_ERROR_RETURN
    176         (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port,
    177                                  BCMX_DEST_CONVERT_DEFAULT));
    178 
    179     return bcm_auth_mac_delete_all(bcm_unit, bcm_port);
    180 }