MAC层之接口子函数文件mac_assoc.c分析

这个文件是向mac.c的函数接口提供子函数,向下连接硬件驱动函数。本分析的目的是要总结出移植需要实现哪些底层驱动函数。

此文件一共向上提供三个函数接口

(一)需要底层硬件驱动提供的函数接口

          (1):mac_set_pan_id(args_in->coord_pan_id);  

           (2):mac_set_channel(args_in->channel) ;    

            (3):mac_tx_handler(buf, &hdr.dest_addr, false, true, hdr.dsn, ZIGBEE_INVALID_HANDLE);

(二)需要子层其他源文件提供的函数接口                

            (1) 来自mac.c      mac_pcb_get(), mac_pcb_get();

            (2) 来自 mac_gen.c     mac_gen_cmd(buf, &cmd), mac_gen_cmd_header(buf, &hdr, true, &src_addr, &args_in->coord_addr);

(三)向上的 函数接口

                (1) void   mac_assoc_req (mac_assoc_req_t *args_in) :发出加入某一路由的命令,此函数负责 generate the mac header and the command header

   {

   mac_pcb_t *pcb = mac_pcb_get();
    mac_pib_t *pib = mac_pib_get();
    buffer_t *buf;
    address_t src_addr;
    mac_cmd_t cmd;
    mac_hdr_t hdr;

    // change the pan id and channel to the specified args
    pib->curr_channel           = args_in->channel;
    memcpy(&pib->coord_addr, &args_in->coord_addr, sizeof(address_t));

    // set the channel and pan id to the one that we're going to join
    mac_set_channel(args_in->channel);
    mac_set_pan_id(args_in->coord_pan_id);

    // generate the association request frame
    BUF_ALLOC(buf, TX);
    cmd.cmd_id = MAC_ASSOC_REQ;
    cmd.assoc_req.cap_info = args_in->capability;
    mac_gen_cmd(buf, &cmd);

    src_addr.mode       = LONG_ADDR;
    src_addr.long_addr  = pib->ext_addr;
    mac_gen_cmd_header(buf, &hdr, true, &src_addr, &args_in->coord_addr);

    // set the state to association request and save some info that we'll use later
    memcpy(&pcb->parent_addr, &args_in->coord_addr, sizeof(address_t));
    pcb->assoc_req_dsn  = hdr.dsn;
    pcb->mac_state      = MLME_ASSOC_REQ;

    mac_tx_handler(buf, &hdr.dest_addr, false, true, hdr.dsn, ZIGBEE_INVALID_HANDLE);

                              }

               (2):void mac_assoc_resp(mac_assoc_resp_t *args)  

                            This function generates the association response command frame and  sends it to the indirect transmission queue for retrieval by the requestor.
                              这个函数的功能是产生一个绑定命令的响应帧,并发到到 indirect transmission queue,由requestor取回

                         {

   mac_cmd_t cmd;
    mac_hdr_t hdr;
    address_t src_addr;
    mac_pib_t *pib = mac_pib_get();
    buffer_t *buf = NULL;

    // generate the association response command frame
    BUF_ALLOC(buf, TX);

    cmd.cmd_id                  = MAC_ASSOC_RESP;
    cmd.assoc_resp.assoc_status = (U8)args->status;
    cmd.assoc_resp.short_addr   = args->assoc_short_addr;

    src_addr.mode               = SHORT_ADDR;
    src_addr.short_addr         = pib->short_addr;

    mac_gen_cmd(buf, &cmd);
    mac_gen_cmd_header(buf, &hdr, true, &src_addr, &args->dev_addr);
    mac_tx_handler(buf, &hdr.dest_addr, true, true, hdr.dsn, ZIGBEE_INVALID_HANDLE);
}

 

 

(3) void mac_orphan_resp(U64 orphan_addr, U16 short_addr)

      This function generates an orphan response and sends it out to the specified address.
      此函数的功能是产生一个孤儿相应,并发送到指定地址

{
    mac_cmd_t cmd;
    mac_hdr_t hdr;
    buffer_t *buf;
    address_t src_addr, dest_addr;
    mac_pib_t *pib = mac_pib_get();

    cmd.cmd_id                          = MAC_COORD_REALIGN;
    cmd.coord_realign.pan_id            = pib->pan_id;
    cmd.coord_realign.coord_short_addr  = pib->short_addr;
    cmd.coord_realign.channel           = pib->curr_channel;
    cmd.coord_realign.short_addr        = short_addr;

    src_addr.mode                       = LONG_ADDR;
    src_addr.long_addr                  = pib->ext_addr;
    dest_addr.mode                      = LONG_ADDR;
    dest_addr.long_addr                 = orphan_addr;

    BUF_ALLOC(buf, TX);
    mac_gen_cmd(buf, &cmd);
    mac_gen_cmd_header(buf, &hdr, true, &src_addr, &dest_addr);
    mac_tx_handler(buf, &hdr.dest_addr, false, true, hdr.dsn, ZIGBEE_INVALID_HANDLE);
}

 

总结,这个文件的三个函数接口,都是往另一个节点,不同的是命令不同,所以这三个函数调用的子函数一致,同时在这里一共使用3个底层硬件驱动函数,所以这三个硬件驱动函数是每个芯片需要移植的

 

 

 


 

你可能感兴趣的:(MAC层之接口子函数文件mac_assoc.c分析)