NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
IEEE802_11_PhyFrame.c
1/************************************************************************************
2 * Copyright (C) 2023 *
3 * TETCOS, Bangalore. India *
4 * *
5 * Tetcos owns the intellectual property rights in the Product and its content. *
6 * The copying, redistribution, reselling or publication of any or all of the *
7 * Product or its content without express prior written consent of Tetcos is *
8 * prohibited. Ownership and / or any other right relating to the software and all *
9 * intellectual property rights therein shall remain at all times with Tetcos. *
10 * *
11 * Author: Shashi Kant Suman *
12 * *
13 * ---------------------------------------------------------------------------------*/
14#include "main.h"
15#include "IEEE802_11.h"
16#include "IEEE802_11_Phy.h"
17#include "IEEE802_11_PhyFrame.h"
18
19int get_ofdm_rate(int rate)
20{
21 switch(rate)
22 {
23 case 6: return 0xD;
24 case 9: return 0xF;
25 case 12: return 0x5;
26 case 18: return 0x7;
27 case 24: return 0x9;
28 case 36: return 0xB;
29 case 48: return 0x1;
30 case 54: return 0x3;
31 default: return 0xD;
32 }
33}
34
35/**
36This function is called in the fn_NetSim_WLAN_PhysicalOut() function.
37Add the PHY header pstruPacket->pstruPhyData->Packet_PhyData to the packet.
38*/
39void fn_NetSim_IEEE802_11_Add_Phy_Header(NetSim_PACKET* packet, UINT64* transmissionId)
40{
41 /*Adding phy layer overhead does not affect result in netsim.*/
42 PIEEE802_11_PHY_VAR phy = IEEE802_11_CURR_PHY;
43 ptrIEEE802_11_PHY_HDR hdr = calloc(1, sizeof* hdr);
44 if (*transmissionId == 0)
45 hdr->transmissionId = ++phy->transmissionId;
46 else hdr->transmissionId = *transmissionId;
47 *transmissionId = hdr->transmissionId;
48 PACKET_PHYPROTOCOLDATA(packet) = hdr;
49 return;
50
51
52 //PIEEE802_11_DSSS_PLCP_FRAME dsssPlcp;
53 //PIEEE802_11_OFDM_PLCP_FRAME ofdmPlcp;
54 //PIEEE802_11_HT_PLCP_FRAME htPlcp;
55 //
56 //switch(phy->PhyProtocol)
57 //{
58 //case IEEE_802_11b:
59 // dsssPlcp = (PIEEE802_11_DSSS_PLCP_FRAME)calloc(1, sizeof *dsssPlcp);
60 // dsssPlcp->nSIGNAL = phy->PHY_TYPE.dsssPhy.dsssrate;
61 // packet->pstruPhyData->Packet_PhyData = dsssPlcp;
62 // break;
63 //case IEEE_802_11a:
64 //case IEEE_802_11g:
65 //case IEEE_802_11p:
66 // ofdmPlcp = (PIEEE802_11_OFDM_PLCP_FRAME)calloc(1, sizeof *ofdmPlcp);
67 // ofdmPlcp->nRATE = get_ofdm_rate((int)phy->PHY_TYPE.ofdmPhy.dDataRate);
68 // packet->pstruPhyData->Packet_PhyData = ofdmPlcp;
69 // break;
70 //case IEEE_802_11n:
71 //case IEEE_802_11ac:
72 // htPlcp = (PIEEE802_11_HT_PLCP_FRAME)calloc(1,sizeof* htPlcp);
73 // // Assign the relevant values of sig field
74 // htPlcp->nMCS = phy->MCS;
75 // if(phy->PHY_TYPE.ofdmPhy_11n.nCH_BANDWIDTH == HT_CBW40)
76 // htPlcp->bCBW_20_40 = 1;
77 //
78 // if(phy->PHY_TYPE.ofdmPhy_11n.nAGGREGATION == AGGREGATED)
79 // htPlcp->bAggregation = 1;
80 //
81 // if(phy->PHY_TYPE.ofdmPhy_11n.nSOUNDING == NOT_SOUNDING)
82 // htPlcp->bNot_Sounding = 1;
83 //
84 // if(phy->PHY_TYPE.ofdmPhy_11n.nSMOOTHING == SMOOTHING_REC)
85 // htPlcp->bSmoothing = 1;
86 //
87 // if(phy->nGuardInterval == 400)
88 // htPlcp->bShort_GI = 1;
89 //
90 // if(phy->PHY_TYPE.ofdmPhy_11n.nFEC_CODING == LDPC_CODING)
91 // htPlcp->bFEC_coding = 1;
92 // packet->pstruPhyData->Packet_PhyData = htPlcp;
93 // break;
94 //default:
95 // fnNetSimError("Unknown phy protocol %d in %s.",phy->PhyProtocol,__FUNCTION__);
96 // break;
97 //}
98}
99
100void free_ieee802_11_phy_header(NetSim_PACKET* packet)
101{
102 ptrIEEE802_11_PHY_HDR hdr = PACKET_PHYPROTOCOLDATA(packet);
103 free(hdr);
104 PACKET_PHYPROTOCOLDATA(packet) = NULL;
105}
106
107void copy_ieee802_11_phy_header(NetSim_PACKET* d, NetSim_PACKET* s)
108{
109 ptrIEEE802_11_PHY_HDR sh = PACKET_PHYPROTOCOLDATA(s);
110 if (sh)
111 {
112 ptrIEEE802_11_PHY_HDR dh = calloc(1, sizeof* dh);
113 memcpy(dh, sh, sizeof* dh);
114 PACKET_PHYPROTOCOLDATA(d) = dh;
115 }
116}