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

bfd_pack.c (14880B)


      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:        bfd_pack.c
      8  * Purpose:     BFD pack and unpack routines for:
      9  *              - BFD Control messages
     10  *              - Network Packet headers (PDUs)
     11  *
     12  *
     13  * BFD control messages
     14  *
     15  * BFD messages between the Host CPU and uController are sent
     16  * using the uc_message module which allows short messages
     17  * to be passed (see include/soc/shared/mos_msg_common.h)
     18  *
     19  * Additional information for a given message (a long message) is passed
     20  * using DMA.  The BFD control message types defines the format
     21  * for these long messages.
     22  *
     23  * This file is shared between SDK and uKernel.
     24  */
     25 
     26 #include <shared/pack.h>
     27 #include <shared/bfd.h>
     28 #include <soc/shared/bfd_msg.h>
     29 #include <soc/shared/bfd_pkt.h>
     30 #include <soc/shared/bfd_pack.h>
     31 
     32 
     33 uint8 *
     34 shr_bfd_msg_ctrl_sess_set_pack(uint8 *buf,
     35                                shr_bfd_msg_ctrl_sess_set_t *msg)
     36 {
     37     uint16 i;
     38 
     39     _SHR_PACK_U32(buf, msg->sess_id);             
     40     _SHR_PACK_U32(buf, msg->flags);
     41     _SHR_PACK_U8(buf, msg->passive);
     42     _SHR_PACK_U8(buf, msg->local_demand);
     43     _SHR_PACK_U8(buf, msg->local_diag);
     44     _SHR_PACK_U8(buf, msg->local_detect_mult);
     45     _SHR_PACK_U32(buf, msg->local_discriminator);
     46     _SHR_PACK_U32(buf, msg->remote_discriminator);
     47     _SHR_PACK_U32(buf, msg->local_min_tx);
     48     _SHR_PACK_U32(buf, msg->local_min_rx);
     49     _SHR_PACK_U32(buf, msg->local_min_echo_rx);
     50     _SHR_PACK_U8(buf, msg->auth_type);
     51     _SHR_PACK_U32(buf, msg->auth_key);
     52     _SHR_PACK_U32(buf, msg->xmt_auth_seq);
     53     _SHR_PACK_U8(buf, msg->encap_type);
     54     _SHR_PACK_U32(buf, msg->encap_length);
     55     for (i = 0; i < SHR_BFD_MAX_ENCAP_LENGTH; i++) {
     56         _SHR_PACK_U8(buf, msg->encap_data[i]);
     57     }
     58     _SHR_PACK_U16(buf, msg->lkey_etype);
     59     _SHR_PACK_U16(buf, msg->lkey_offset);
     60     _SHR_PACK_U16(buf, msg->lkey_length);
     61     _SHR_PACK_U32(buf, msg->mep_id_length);
     62     for (i = 0; i < _SHR_BFD_ENDPOINT_MAX_MEP_ID_LENGTH; i++) {
     63         _SHR_PACK_U8(buf, msg->mep_id[i]);
     64     }
     65     for (i = 0; i < SHR_BFD_MPLS_LABEL_LENGTH; i++) {
     66         _SHR_PACK_U8(buf, msg->mpls_label[i]);
     67     }
     68     _SHR_PACK_U32(buf, msg->tx_port);
     69     _SHR_PACK_U32(buf, msg->tx_cos);
     70     _SHR_PACK_U32(buf, msg->tx_pri);
     71     _SHR_PACK_U32(buf, msg->tx_qnum);
     72 #ifdef SDK_45223_DISABLED
     73     _SHR_PACK_U32(buf, msg->remote_mep_id_length);
     74     for (i = 0; i < _SHR_BFD_ENDPOINT_MAX_MEP_ID_LENGTH; i++) {
     75         _SHR_PACK_U8(buf, msg->remote_mep_id[i]);
     76     }
     77 #endif
     78 
     79     return buf;
     80 }
     81 
     82 uint8 *
     83 shr_bfd_msg_ctrl_sess_set_unpack(uint8 *buf,
     84                                  shr_bfd_msg_ctrl_sess_set_t *msg)
     85 {
     86     uint16 i;
     87 
     88     _SHR_UNPACK_U32(buf, msg->sess_id);             
     89     _SHR_UNPACK_U32(buf, msg->flags);
     90     _SHR_UNPACK_U8(buf, msg->passive);
     91     _SHR_UNPACK_U8(buf, msg->local_demand);
     92     _SHR_UNPACK_U8(buf, msg->local_diag);
     93     _SHR_UNPACK_U8(buf, msg->local_detect_mult);
     94     _SHR_UNPACK_U32(buf, msg->local_discriminator);
     95     _SHR_UNPACK_U32(buf, msg->remote_discriminator);
     96     _SHR_UNPACK_U32(buf, msg->local_min_tx);
     97     _SHR_UNPACK_U32(buf, msg->local_min_rx);
     98     _SHR_UNPACK_U32(buf, msg->local_min_echo_rx);
     99     _SHR_UNPACK_U8(buf, msg->auth_type);
    100     _SHR_UNPACK_U32(buf, msg->auth_key);
    101     _SHR_UNPACK_U32(buf, msg->xmt_auth_seq);
    102     _SHR_UNPACK_U8(buf, msg->encap_type);
    103     _SHR_UNPACK_U32(buf, msg->encap_length);
    104     for (i = 0; i < SHR_BFD_MAX_ENCAP_LENGTH; i++) {
    105         _SHR_UNPACK_U8(buf, msg->encap_data[i]);
    106     }
    107     _SHR_UNPACK_U16(buf, msg->lkey_etype);
    108     _SHR_UNPACK_U16(buf, msg->lkey_offset);
    109     _SHR_UNPACK_U16(buf, msg->lkey_length);
    110     _SHR_UNPACK_U32(buf, msg->mep_id_length);
    111     for (i = 0; i < _SHR_BFD_ENDPOINT_MAX_MEP_ID_LENGTH; i++) {
    112         _SHR_UNPACK_U8(buf, msg->mep_id[i]);
    113     }
    114     for (i = 0; i < SHR_BFD_MPLS_LABEL_LENGTH; i++) {
    115         _SHR_UNPACK_U8(buf, msg->mpls_label[i]);
    116     }
    117     _SHR_UNPACK_U32(buf, msg->tx_port);
    118     _SHR_UNPACK_U32(buf, msg->tx_cos);
    119     _SHR_UNPACK_U32(buf, msg->tx_pri);
    120     _SHR_UNPACK_U32(buf, msg->tx_qnum);
    121 #ifdef SDK_45223_DISABLED
    122     _SHR_UNPACK_U32(buf, msg->remote_mep_id_length);
    123     for (i = 0; i < _SHR_BFD_ENDPOINT_MAX_MEP_ID_LENGTH; i++) {
    124         _SHR_UNPACK_U8(buf, msg->remote_mep_id[i]);
    125     }
    126 #endif
    127 
    128     return buf;
    129 }
    130 
    131 uint8 *
    132 shr_bfd_msg_ctrl_sess_get_pack(uint8 *buf,
    133                                shr_bfd_msg_ctrl_sess_get_t *msg)
    134 {
    135     uint16 i;
    136 
    137     _SHR_PACK_U32(buf, msg->sess_id);
    138     _SHR_PACK_U8(buf, msg->enable);
    139     _SHR_PACK_U8(buf, msg->passive);
    140     _SHR_PACK_U8(buf, msg->local_demand);
    141     _SHR_PACK_U8(buf, msg->remote_demand);
    142     _SHR_PACK_U8(buf, msg->local_diag);
    143     _SHR_PACK_U8(buf, msg->remote_diag);
    144     _SHR_PACK_U8(buf, msg->local_sess_state);
    145     _SHR_PACK_U8(buf, msg->remote_sess_state);
    146     _SHR_PACK_U8(buf, msg->local_detect_mult);
    147     _SHR_PACK_U8(buf, msg->remote_detect_mult);
    148     _SHR_PACK_U32(buf, msg->local_discriminator);
    149     _SHR_PACK_U32(buf, msg->remote_discriminator); 
    150     _SHR_PACK_U32(buf, msg->local_min_tx);
    151     _SHR_PACK_U32(buf, msg->remote_min_tx);
    152     _SHR_PACK_U32(buf, msg->local_min_rx);
    153     _SHR_PACK_U32(buf, msg->remote_min_rx);
    154     _SHR_PACK_U32(buf, msg->local_min_echo_rx);
    155     _SHR_PACK_U32(buf, msg->remote_min_echo_rx);
    156     _SHR_PACK_U8(buf, msg->auth_type);
    157     _SHR_PACK_U32(buf, msg->auth_key);
    158     _SHR_PACK_U32(buf, msg->xmt_auth_seq);
    159     _SHR_PACK_U32(buf, msg->rcv_auth_seq);
    160     _SHR_PACK_U8(buf, msg->encap_type);
    161     _SHR_PACK_U32(buf, msg->encap_length); 
    162     for (i = 0; i < SHR_BFD_MAX_ENCAP_LENGTH; i++) {
    163         _SHR_PACK_U8(buf, msg->encap_data[i]);
    164     }
    165     _SHR_PACK_U16(buf, msg->lkey_etype);
    166     _SHR_PACK_U16(buf, msg->lkey_offset);
    167     _SHR_PACK_U16(buf, msg->lkey_length);
    168     _SHR_PACK_U32(buf, msg->mep_id_length);
    169     for (i = 0; i < _SHR_BFD_ENDPOINT_MAX_MEP_ID_LENGTH; i++) {
    170         _SHR_PACK_U8(buf, msg->mep_id[i]);
    171     }
    172     for (i = 0; i < SHR_BFD_MPLS_LABEL_LENGTH; i++) {
    173         _SHR_PACK_U8(buf, msg->mpls_label[i]);
    174     }
    175     _SHR_PACK_U32(buf, msg->tx_port);
    176     _SHR_PACK_U32(buf, msg->tx_cos);
    177     _SHR_PACK_U32(buf, msg->tx_pri);
    178     _SHR_PACK_U32(buf, msg->tx_qnum);
    179 #ifdef SDK_45223_DISABLED
    180     _SHR_PACK_U32(buf, msg->remote_mep_id_length);
    181     for (i = 0; i < _SHR_BFD_ENDPOINT_MAX_MEP_ID_LENGTH; i++) {
    182         _SHR_PACK_U8(buf, msg->remote_mep_id[i]);
    183     }
    184     _SHR_PACK_U32(buf, msg->mis_conn_mep_id_length);
    185     for (i = 0; i < _SHR_BFD_ENDPOINT_MAX_MEP_ID_LENGTH; i++) {
    186         _SHR_PACK_U8(buf, msg->mis_conn_mep_id[i]);
    187     }
    188 #endif
    189 
    190     return buf;
    191 }
    192 
    193 uint8 *
    194 shr_bfd_msg_ctrl_sess_get_unpack(uint8 *buf,
    195                                  shr_bfd_msg_ctrl_sess_get_t *msg)
    196 {
    197     uint16 i;
    198 
    199     _SHR_UNPACK_U32(buf, msg->sess_id);
    200     _SHR_UNPACK_U8(buf, msg->enable);
    201     _SHR_UNPACK_U8(buf, msg->passive);
    202     _SHR_UNPACK_U8(buf, msg->local_demand);
    203     _SHR_UNPACK_U8(buf, msg->remote_demand);
    204     _SHR_UNPACK_U8(buf, msg->local_diag);
    205     _SHR_UNPACK_U8(buf, msg->remote_diag);
    206     _SHR_UNPACK_U8(buf, msg->local_sess_state);
    207     _SHR_UNPACK_U8(buf, msg->remote_sess_state);
    208     _SHR_UNPACK_U8(buf, msg->local_detect_mult);
    209     _SHR_UNPACK_U8(buf, msg->remote_detect_mult);
    210     _SHR_UNPACK_U32(buf, msg->local_discriminator);
    211     _SHR_UNPACK_U32(buf, msg->remote_discriminator); 
    212     _SHR_UNPACK_U32(buf, msg->local_min_tx);
    213     _SHR_UNPACK_U32(buf, msg->remote_min_tx);
    214     _SHR_UNPACK_U32(buf, msg->local_min_rx);
    215     _SHR_UNPACK_U32(buf, msg->remote_min_rx);
    216     _SHR_UNPACK_U32(buf, msg->local_min_echo_rx);
    217     _SHR_UNPACK_U32(buf, msg->remote_min_echo_rx);
    218     _SHR_UNPACK_U8(buf, msg->auth_type);
    219     _SHR_UNPACK_U32(buf, msg->auth_key);
    220     _SHR_UNPACK_U32(buf, msg->xmt_auth_seq);
    221     _SHR_UNPACK_U32(buf, msg->rcv_auth_seq);
    222     _SHR_UNPACK_U8(buf, msg->encap_type);
    223     _SHR_UNPACK_U32(buf, msg->encap_length); 
    224     for (i = 0; i < SHR_BFD_MAX_ENCAP_LENGTH; i++) {
    225         _SHR_UNPACK_U8(buf, msg->encap_data[i]);
    226     }
    227     _SHR_UNPACK_U16(buf, msg->lkey_etype);
    228     _SHR_UNPACK_U16(buf, msg->lkey_offset);
    229     _SHR_UNPACK_U16(buf, msg->lkey_length);
    230     _SHR_UNPACK_U32(buf, msg->mep_id_length);
    231     for (i = 0; i < _SHR_BFD_ENDPOINT_MAX_MEP_ID_LENGTH; i++) {
    232         _SHR_UNPACK_U8(buf, msg->mep_id[i]);
    233     }
    234     for (i = 0; i < SHR_BFD_MPLS_LABEL_LENGTH; i++) {
    235         _SHR_UNPACK_U8(buf, msg->mpls_label[i]);
    236     }
    237     _SHR_UNPACK_U32(buf, msg->tx_port);
    238     _SHR_UNPACK_U32(buf, msg->tx_cos);
    239     _SHR_UNPACK_U32(buf, msg->tx_pri);
    240     _SHR_UNPACK_U32(buf, msg->tx_qnum);
    241 #ifdef SDK_45223_DISABLED
    242     _SHR_UNPACK_U32(buf, msg->remote_mep_id_length);
    243     for (i = 0; i < _SHR_BFD_ENDPOINT_MAX_MEP_ID_LENGTH; i++) {
    244         _SHR_UNPACK_U8(buf, msg->remote_mep_id[i]);
    245     }
    246     _SHR_UNPACK_U32(buf, msg->mis_conn_mep_id_length);
    247     for (i = 0; i < _SHR_BFD_ENDPOINT_MAX_MEP_ID_LENGTH; i++) {
    248         _SHR_UNPACK_U8(buf, msg->mis_conn_mep_id[i]);
    249     }
    250 #endif
    251 
    252     return buf;
    253 }
    254 
    255 uint8 *
    256 shr_bfd_msg_ctrl_auth_sha1_pack(uint8 *buf,
    257                                 shr_bfd_msg_ctrl_auth_sha1_t *msg)
    258 {
    259     uint16 i;
    260 
    261     _SHR_PACK_U32(buf, msg->index);
    262     _SHR_PACK_U8(buf, msg->enable);
    263     _SHR_PACK_U32(buf, msg->sequence);
    264     for (i = 0; i < _SHR_BFD_AUTH_SHA1_KEY_LENGTH; i++) {
    265         _SHR_PACK_U8(buf, msg->key[i]);
    266     }
    267 
    268     return buf;
    269 }
    270 
    271 uint8 *
    272 shr_bfd_msg_ctrl_auth_sha1_unpack(uint8 *buf,
    273                                   shr_bfd_msg_ctrl_auth_sha1_t *msg)
    274 {
    275     uint16 i;
    276 
    277     _SHR_UNPACK_U32(buf, msg->index);
    278     _SHR_UNPACK_U8(buf, msg->enable);
    279     _SHR_UNPACK_U32(buf, msg->sequence);
    280     for (i = 0; i < _SHR_BFD_AUTH_SHA1_KEY_LENGTH; i++) {
    281         _SHR_UNPACK_U8(buf, msg->key[i]);
    282     }
    283 
    284     return buf;
    285 }
    286 
    287 uint8 *
    288 shr_bfd_msg_ctrl_auth_sp_pack(uint8 *buf, shr_bfd_msg_ctrl_auth_sp_t *msg)
    289 {
    290     uint16 i;
    291 
    292     _SHR_PACK_U32(buf, msg->index);
    293     _SHR_PACK_U8(buf, msg->length);
    294     for (i = 0; i < _SHR_BFD_AUTH_SIMPLE_PASSWORD_KEY_LENGTH; i++) {
    295         _SHR_PACK_U8(buf, msg->password[i]);
    296     }
    297 
    298     return buf;
    299 }
    300 
    301 uint8 *
    302 shr_bfd_msg_ctrl_auth_sp_unpack(uint8 *buf, shr_bfd_msg_ctrl_auth_sp_t *msg)
    303 {
    304     uint16 i;
    305 
    306     _SHR_UNPACK_U32(buf, msg->index);
    307     _SHR_UNPACK_U8(buf, msg->length);
    308     for (i = 0; i < _SHR_BFD_AUTH_SIMPLE_PASSWORD_KEY_LENGTH; i++) {
    309         _SHR_UNPACK_U8(buf, msg->password[i]);
    310     }
    311 
    312     return buf;
    313 }
    314 
    315 uint8 *
    316 shr_bfd_msg_ctrl_stat_req_pack(uint8 *buf,
    317                                shr_bfd_msg_ctrl_stat_req_t *msg)
    318 {
    319     _SHR_PACK_U32(buf, msg->sess_id);
    320     _SHR_PACK_U32(buf, msg->clear);
    321 
    322     return buf;
    323 }
    324 
    325 uint8 *
    326 shr_bfd_msg_ctrl_stat_req_unpack(uint8 *buf,
    327                                  shr_bfd_msg_ctrl_stat_req_t *msg)
    328 {
    329     _SHR_UNPACK_U32(buf, msg->sess_id);
    330     _SHR_UNPACK_U32(buf, msg->clear);
    331 
    332     return buf;
    333 }
    334 
    335 uint8 *
    336 shr_bfd_msg_ctrl_stat_reply_pack(uint8 *buf,
    337                                  shr_bfd_msg_ctrl_stat_reply_t *msg)
    338 {
    339     _SHR_PACK_U32(buf, msg->sess_id);
    340     _SHR_PACK_U32(buf, msg->packets_in);
    341     _SHR_PACK_U32(buf, msg->packets_out);
    342     _SHR_PACK_U32(buf, msg->packets_drop);
    343     _SHR_PACK_U32(buf, msg->packets_auth_drop);
    344 
    345     return buf;
    346 }
    347 
    348 uint8 *
    349 shr_bfd_msg_ctrl_stat_reply_unpack(uint8 *buf,
    350                                    shr_bfd_msg_ctrl_stat_reply_t *msg)
    351 {
    352     _SHR_UNPACK_U32(buf, msg->sess_id);
    353     _SHR_UNPACK_U32(buf, msg->packets_in);
    354     _SHR_UNPACK_U32(buf, msg->packets_out);
    355     _SHR_UNPACK_U32(buf, msg->packets_drop);
    356     _SHR_UNPACK_U32(buf, msg->packets_auth_drop);
    357 
    358     return buf;
    359 }
    360 
    361 
    362 /*********************************************************
    363  * BFD Network Packet Header Pack/Unpack
    364  *
    365  * Functions:
    366  *      shr_bfd_<header>_pack/unpack
    367  * Purpose:
    368  *      The following set of routines pack/unpack specified
    369  *      network packet header to/from given buffer.
    370  * Parameters:
    371  *   _pack()
    372  *      buffer   - (OUT) Buffer where to pack header.
    373  *      <header> - (IN)  Header to pack.
    374  *   _unpack()
    375  *      buffer   - (IN)  Buffer with data to unpack.
    376  *      <header> - (OUT) Returns unpack header.
    377  * Returns:
    378  *      Pointer to next position in buffer.
    379  * Notes:
    380  *      Assumes pointers are valid and contain enough memory space.
    381  */
    382 uint8 *
    383 shr_bfd_header_pack(uint8 *buf, shr_bfd_header_t *bfd)
    384 {
    385     uint32 *word;
    386 
    387     word = (uint32 *)bfd;
    388 
    389     _SHR_PACK_U32(buf, word[0]);
    390     _SHR_PACK_U32(buf, bfd->my_discriminator);
    391     _SHR_PACK_U32(buf, bfd->your_discriminator);
    392     _SHR_PACK_U32(buf, bfd->desired_min_tx_interval);
    393     _SHR_PACK_U32(buf, bfd->required_min_rx_interval);
    394     _SHR_PACK_U32(buf, bfd->required_min_echo_rx_interval);
    395 
    396     return buf;
    397 }
    398 
    399 uint8 *
    400 shr_bfd_header_unpack(uint8 *buf, shr_bfd_header_t *bfd)
    401 {
    402     uint32 *word;
    403 
    404     word = (uint32 *)bfd;
    405 
    406     _SHR_UNPACK_U32(buf, word[0]);
    407     _SHR_UNPACK_U32(buf, bfd->my_discriminator);
    408     _SHR_UNPACK_U32(buf, bfd->your_discriminator);
    409     _SHR_UNPACK_U32(buf, bfd->desired_min_tx_interval);
    410     _SHR_UNPACK_U32(buf, bfd->required_min_rx_interval);
    411     _SHR_UNPACK_U32(buf, bfd->required_min_echo_rx_interval);
    412 
    413     return buf;
    414 }
    415 
    416 uint8 *
    417 shr_bfd_auth_header_pack(uint8 *buf, shr_bfd_auth_header_t *auth)
    418 {
    419     int i;
    420 
    421     _SHR_PACK_U8(buf, auth->type);
    422     _SHR_PACK_U8(buf, auth->length);
    423 
    424     if (auth->type == _SHR_BFD_AUTH_TYPE_SIMPLE_PASSWORD) {
    425         _SHR_PACK_U8(buf, auth->data.sp.key_id);
    426         for (i = 0;
    427              i < (auth->length - SHR_BFD_AUTH_SP_HEADER_START_LENGTH); i++) {
    428             _SHR_PACK_U8(buf, auth->data.sp.password[i]);
    429         }
    430 
    431     } else if ((auth->type == _SHR_BFD_AUTH_TYPE_KEYED_SHA1) ||
    432                (auth->type == _SHR_BFD_AUTH_TYPE_METICULOUS_KEYED_SHA1)) {
    433         _SHR_PACK_U8(buf, auth->data.sha1.key_id);
    434         _SHR_PACK_U8(buf, auth->data.sha1.reserved);
    435         _SHR_PACK_U32(buf, auth->data.sha1.sequence);
    436         for (i = 0; i < _SHR_BFD_AUTH_SHA1_KEY_LENGTH; i++) {
    437             _SHR_PACK_U8(buf, auth->data.sha1.key[i]);
    438         }
    439     }
    440 
    441     return buf;
    442 }
    443 
    444 uint8 *
    445 shr_bfd_auth_header_unpack(uint8 *buf, shr_bfd_auth_header_t *auth)
    446 {
    447     int i;
    448 
    449     _SHR_UNPACK_U8(buf, auth->type);
    450     _SHR_UNPACK_U8(buf, auth->length);
    451 
    452     if (auth->type == _SHR_BFD_AUTH_TYPE_SIMPLE_PASSWORD) {
    453         _SHR_UNPACK_U8(buf, auth->data.sp.key_id);
    454         for (i = 0;
    455              i < (auth->length - SHR_BFD_AUTH_SP_HEADER_START_LENGTH); i++) {
    456             _SHR_UNPACK_U8(buf, auth->data.sp.password[i]);
    457         }
    458 
    459     } else if ((auth->type == _SHR_BFD_AUTH_TYPE_KEYED_SHA1) ||
    460                (auth->type == _SHR_BFD_AUTH_TYPE_METICULOUS_KEYED_SHA1)) {
    461         _SHR_UNPACK_U8(buf, auth->data.sha1.key_id);
    462         _SHR_UNPACK_U8(buf, auth->data.sha1.reserved);
    463         _SHR_UNPACK_U32(buf, auth->data.sha1.sequence);
    464         for (i = 0; i < _SHR_BFD_AUTH_SHA1_KEY_LENGTH; i++) {
    465             _SHR_UNPACK_U8(buf, auth->data.sha1.key[i]);
    466         }
    467     }
    468 
    469     return buf;
    470 }
    471