void nwk_gen_header(buffer_t *buf, nwk_hdr_t *hdr) { U8 nhdr_size = 0; hdr->nwk_fcf = nwk_gen_frm_ctrl(hdr); //lint --e{826} Suppress Info 826: Suspicious pointer-to-pointer conversion (area too small) // ex: *(U16 *)buf->dptr = hdr->nwk_fcf // this removes the lint warning for this block only // Calculate the size of the nwk header nhdr_size = 8; nhdr_size += (hdr->nwk_frm_ctrl.dest_ieee_addr_flag) ? 8 : 0; nhdr_size += (hdr->nwk_frm_ctrl.src_ieee_addr_flag) ? 8 : 0; nhdr_size += (hdr->nwk_frm_ctrl.mcast_flag) ? 1 : 0; // fill in the length and adjust the data pointer buf->dptr -= nhdr_size; buf->len += nhdr_size; // fill in the fields of the nwk header *(U16 *)buf->dptr = hdr->nwk_fcf; buf->dptr += sizeof(U16); *(U16 *)buf->dptr = hdr->dest_addr; buf->dptr += sizeof(U16); *(U16 *)buf->dptr = hdr->src_addr; buf->dptr += sizeof(U16); *buf->dptr++ = hdr->radius; *buf->dptr++ = hdr->seq_num; if (hdr->nwk_frm_ctrl.dest_ieee_addr_flag) { *(U64 *)buf->dptr = hdr->dest_ieee_addr; buf->dptr += sizeof(U64); } if (hdr->nwk_frm_ctrl.src_ieee_addr_flag) { *(U64 *)buf->dptr = hdr->src_ieee_addr; buf->dptr += sizeof(U64); } // roll back the dptr to the beginning of the header buf->dptr -= nhdr_size; }
/* * Generate the NWK header for the frame. This is the main function to * generate the NWK header. The NWK header consists of the following fields: * - Frame Control Field * - Destination Address * - Source Address * - Radius * - Sequence number * - Destination IEEE address (optional) * - Source IEEE address (optional) * - Multicast */ void nwk_gen_header(buffer_t *buf, nwk_hdr_t *hdr) { U8 nhdr_size = 0; hdr->nwk_fcf = nwk_gen_frm_ctrl(hdr); /* * ex: *(U16 *)buf->dptr = hdr->nwk_fcf * this removes the lint warning for this block only */ /* Calculate the size of the nwk header */ nhdr_size = 8; nhdr_size += (hdr->nwk_frm_ctrl.dest_ieee_addr_flag) ? 8 : 0; nhdr_size += (hdr->nwk_frm_ctrl.src_ieee_addr_flag) ? 8 : 0; nhdr_size += (hdr->nwk_frm_ctrl.mcast_flag) ? 1 : 0; /* fill in the length and adjust the data pointer */ buf->dptr -= nhdr_size; buf->len += nhdr_size; /* fill in the fields of the nwk header */ *(U16 *)buf->dptr = hdr->nwk_fcf; buf->dptr += sizeof(U16); *(U16 *)buf->dptr = hdr->dest_addr; buf->dptr += sizeof(U16); *(U16 *)buf->dptr = hdr->src_addr; buf->dptr += sizeof(U16); *buf->dptr++ = hdr->radius; *buf->dptr++ = hdr->seq_num; if (hdr->nwk_frm_ctrl.dest_ieee_addr_flag) { *(U64 *)buf->dptr = hdr->dest_ieee_addr; buf->dptr += sizeof(U64); } if (hdr->nwk_frm_ctrl.src_ieee_addr_flag) { *(U64 *)buf->dptr = hdr->src_ieee_addr; buf->dptr += sizeof(U64); } /* roll back the dptr to the beginning of the header */ buf->dptr -= nhdr_size; }