⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mac.h

📁 wimax BS simulation code,implemented under linux.
💻 H
📖 第 1 页 / 共 4 页
字号:
/* * This piece of code is totally free. If any pitfalls found,  * please feel free to contact me at jetmotor@21cn.com * THANKS A LOT! */#ifndef _MAC_H#define _MAC_H#include <netinet/in.h>#include <pthread.h>#include "types.h"#include "list.h"#include "que.h"#include "wxtimer.h"/* ********************************************************** *		MAC Header Data Structures * ********************************************************** */typedef struct genmachdr_s{	uint8_t type    :6,		ec      :1,		ht      :1;	uint8_t len_h3  :3,		rsv2    :1,		eks     :2,		ci      :1,		esf     :1;//not in 16d	uint8_t len_l8  :8;	uint16_t cid __attribute__ ((packed)) ;	uint8_t hcs __attribute__ ((packed)) ;}genmachdr_t;#define genmachdr_get_len(p)            (uint16_t)((p)->len_h3 << 8 | (p)->len_l8)#define genmachdr_set_len(p, len)       do{ \        (p)->len_h3 = ((len) & 0x0700) >> 8; \        (p)->len_l8 = (len) & 0xff; \}while (0)#define genmachdr_get_cid(p)            ntohs((p)->cid)#define genmachdr_set_cid(p, _cid)       do{ \        (p)->cid = htons(_cid); \}while (0)#define genmachdr_set(p, _ht, _ec, _type, _esf, _ci, _eks, len, cid) do{ \	(p)->ht = (_ht); \	(p)->ec = (_ec); \	(p)->type = (_type); \	(p)->esf = (_esf); \	(p)->ci = (_ci); \	(p)->eks = (_eks); \	genmachdr_set_len(p, len); \	genmachdr_set_cid(p, cid); \}while (0)#define MK_FRAGMENT_ARQ_SUBHDR(subhdr, fc, bsn)\do\{\	(subhdr)[0] = (((fc) << 6) & 0xc0) | (((bsn) >> 5) & 0x3f);\	(subhdr)[1] = ((bsn) << 3) & 0xf8;\} while (0)\#define MK_FRAGMENT_EXT_SUBHDR(subhdr, fc, fsn)  MK_FRAGMENT_ARQ_SUBHDR((subhdr), (fc), (fsn))#define MK_FRAGMENT_NONEXT_SUBHDR(subhdr, fc, fsn)\do\{\	(subhdr)[0] = (((fc) << 6) & 0xc0) | (((fsn) << 3) & 0x38);\} while (0)\#define MK_PACKING_ARQ_SUBHDR(subhdr, fc, bsn, len)\do\{\	(subhdr)[0] = (((fc) << 6) & 0xc0) | (((bsn) >> 5) & 0x3f);\	(subhdr)[1] = (((bsn) << 3) & 0xf8) | (((len) >> 8) & 0x07);\	(subhdr)[2] = (len) & 0xff;\} while (0)\#define MK_PACKING_EXT_SUBHDR(subhdr, fc, fsn, len)  MK_PACKING_ARQ_SUBHDR((subhdr), (fc), (fsn), (len))#define MK_PACKING_NONEXT_SUBHDR(subhdr, fc, fsn, len)\do\{\	(subhdr)[0] = (((fc) << 6) & 0xc0) | (((fsn) << 3) & 0x38) | (((len) >> 8) & 0x07);\	(subhdr)[1] = (len) & 0xff;\} while (0)\#define BR_INCREMENTAL				0#define BR_AGGREGATE				1#define PHY_CHANNEL_REPORT			2#define BR_WITH_UL_TX_POWER_REPORT		3#define BANDWIDTH_REQUEST_AND_CINR_REPORT	4#define BR_WITH_UL_SLEEP_CONTROL		5#define SN_REPORT				6#define CQICH_ALLOCATION_REQUEST		7typedef struct bwrmachdr_s{	uint8_t bwr_h3  :3,		type    :3,		ec      :1,		ht      :1;	uint8_t bwr_m8;	uint8_t bwr_l8;         /* aggregate or incremental */	uint16_t cid __attribute__ ((packed)) ;	uint8_t hcs __attribute__ ((packed)) ;}bwrmachdr_t;#define bwrmachdr_get_bwr(p)            (uint32_t)((p)->bwr_h3 << 16 | (p)->bwr_m8 << 8 | (p)->bwr_l8)#define bwrmachdr_set_bwr(p, bwr)       do{ \        (p)->bwr_h3 = (bwr) & 0x70000; \        (p)->bwr_m8 = (bwr) & 0xff00; \        (p)->bwr_l8 = (bwr) & 0xff; \}while (0)#define bwrmachdr_get_cid(p)            genmachdr_get_cid(p)#define bwrmachdr_set_cid(p, cid)       genmachdr_set_cid(p, cid)typedef struct phychnrphdr_s{	uint8_t pdiuc_h3	:3,		type		:3,		ec		:1,		ht		:1;	uint8_t ultxpw_h7	:7,		pdiuc_l1	:1;	uint8_t rsv		:1,		ul_headroom	:6,		ultxpw_l1	:1;	uint16_t cid __attribute__ ((packed)) ;		uint8_t hcs __attribute__ ((packed)) ;}phychnrphdr_t;#define phychnrphdr_get_pdiuc(p)	(uint8_t)((p)->pdiuc_h3<<1 | (p)->pdiuc_l1)#define physhnrphdr_set_pdiuc(p, pduiuc) do{ \	(p)->pdiuc_h3 = ((pdiuc) & 0xe) >> 1; \	(p)->pdiuc_l1 = (pdiuc) & 0x1; \}while (0)#define phychnrphdr_get_ultxpw(p)	(uint8_t)((p)->ultxpw_h7<<1 |(p)->ultxpw_l1)#define phychnrphdr_set_ultxpw(p, ultxpw) do{ \	(p)->ultxpw_h7 = ((ultxpw) & 0xe7) >> 1; \	(p)->ultxpw_l1 = (ultxpw) & 0x1; \}while (0)#define phychnrphdr_get_cid(p)		genmachdr_get_cid(p)#define phychnrphdr_set_cid(p, cid)	genmachdr_set_cid(p, cid)typedef struct bwrultxpwrphdr_s{	uint8_t bwr_h3  :3,		type    :3,		ec      :1,		ht      :1;	uint8_t bwr_l8;         /* incremental only */	uint8_t ultxpw;	uint16_t cid __attribute__ ((packed)) ;	uint8_t hcs __attribute__ ((packed)) ;}bwrultxpwrphdr_t;#define bwrultxpwrphdr_get_bwr(p)        (uint16_t)((p)->bwr_h3 << 8 | (p)->bwr_l8)#define bwrultxpwrphdr_set_bwr(p, bwr)   do { \        (p)->bwr_h3 = bwr & 0x700; \        (p)->bwr_l8 = bwr & 0xff; \}while ( 0 )#define bwrultxpwrphdr_get_cid(p)        genmachdr_get_cid(p)#define bwrultxpwrphdr_set_cid(p, cid)   genmachdr_set_cid(p, cid)typedef struct bwrcinrrphdr_s{	uint8_t bwr_h3  :3,		type    :3,		ec      :1,		ht      :1;	uint8_t bwr_l8;         /* incremental only */	uint8_t dcdchgind       :1,		cinr            :7;	uint16_t cid __attribute__ ((packed)) ;	uint8_t hcs __attribute__ ((packed)) ;}bwrcinrrphdr_t;#define bwrcinrrphdr_get_bwr(p)          bwrultxpwrphdr_get_bwr(p)#define bwrcinrrphdr_set_bwr(p, bwr)     bwrultxpwrphdr_set_bwr(p, bwr)#define bwrcinrrphdr_get_cid(p)          genmachdr_get_cid(p)#define bwrcinrrphdr_set_cid(p, cid)     genmachdr_set_cid(p, cid)typedef struct bwruschdr_s{	uint8_t bwr_h3	:3,		type	:3,		ec	:1,		ht	:1;	uint8_t bwr_l8;		uint8_t rsv		:1,		op		:1,		pwsvclsid	:6;	uint16_t cid __attribute__ ((packed)) ;	uint8_t hcs __attribute__ ((packed)) ;}bwruschdr_t;#define bwruschdr_get_bwr(p)		bwrultxpwrphdr_get_bwr(p)#define bwruschdr_set_bwr(p, bwr)	bwrultxpwrphdr_set_bwr(p, bwr)#define bwruschdr_get_cid(p)		genmachdr_get_cid(p)#define bwruschdr_set_cid(p, cid)	genmachdr_set_cid(p, cid)typedef struct snrphdr_s{	uint8_t sn1_h2	:2,		last	:1,		type	:3,		ec	:1,		ht	:1;	uint8_t sn2_h4	:4,		sn1_l4	:4;	uint8_t sn3	:6,		sn2_l2	:2;	uint16_t cid __attribute__ ((packed)) ;		uint8_t hcs __attribute__ ((packed)) ;}snrphdr_t;#define snrphdr_get_sn1(p)		(uint8_t)((p)->sn1_h2<<4 | (p)->sn1_h4)#define snrphdr_set_sn1(p, sn1)	do{ \	(p)->sn1_h2 = ((sn1) & 0x30) >> 4; \	(p)->sn1_l4 = (sn1) & 0xf; \}while (0)#define snrphdr_get_sn2(p)		(uint8_t)((p)->sn2_h4<<2 | (p)->sn2_l2)#define snrphdr_set_sn2(p, sn2)	do{ \	(p)->sn2_h4 = ((sn2) & 0x3c) >> 2; \	(p)->sn2_l2 = (sn2) & 0x3; \}while (0)#define snrphdr_get_cid(p)		genmachdr_get_cid(p)#define snrphdr_set_cid(p, cid)		genmachdr_set_cid(p, cid)typedef struct cqicharqhdr_s{        uint8_t fbtype  :3,		type    :3,		ec      :1,		ht      :1;        uint8_t rsv     :4,		pp      :3,		fbssi   :1;        uint8_t rsv2;        uint16_t cid __attribute__ ((packed)) ;        uint8_t hcs __attribute__ ((packed)) ;}cqicharqhdr_t;#define cqicharqhdr_get_cid(p)           genmachdr_get_cid(p)#define cqicharqhdr_set_cid(p, cid)      genmachdr_set_cid(p, cid)#define FAST_FEEDBACK_ALLOCATION_SUBHDR_MASK	0x1#define GRANT_MANAGEMENT_SUBHDR_MASK		0x1#define PACKING_SUBHDR_MASK			0x2#define FRAGMENTATION_SUBHDR_MASK		0x4#define EXTENDED_TYPE_MASK			0x8#define ARQ_FEEDBACK_PAYLOAD_MASK		0x10#define MESH_SUBHDR_MASK			0x20typedef struct grantmngshdr_s{	union {		struct {			uint8_t rsv     :1,				fl      :4,//Frame latency,not in 16d				fli     :1,//Frame latency indication				pm      :1,				si      :1;						uint8_t rsv2;		}ugs;				struct {			uint8_t extpbr_h8;						uint8_t fl		:4,				fli		:1,				extpbr_l3	:3;		}ertps;				struct {			uint16_t pbr;///16 bits		}none;	};}grantmngshdr_t;typedef struct fragshdr_s{        uint8_t rsv     :3,		fsn     :3,		fc      :2;}fragshdr_t;#define fragshdr_set(p, _fc, _fsn) do { \	(p)->fc = (_fc); \	(p)->fsn = (_fsn); \}while (0)typedef struct extfragshdr_s{        uint8_t fsn_h6  :6,		fc      :2;        uint8_t rsv     :3,		fsn_l5  :5;}extfragshdr_t;#define extfragshdr_get_fsn(p)		(uint16_t)(((p)->fsn_h6<<5) | (p)->fsn_l5)#define extfragshdr_set_fsn(p, fsn) do { \        (p)->fsn_h6 = (fsn & 0x7e0) >> 5; \        (p)->fsn_l5 = fsn & 0x1f; \}while (0)#define extfragshdr_set(p, _fc, fsn) do { \	(p)->fc = (_fc); \	extfragshdr_set_fsn(p, fsn); \}while (0)typedef struct packshdr_s{	uint8_t len_h3	:3,		fsn	:3,		fc	:2;			uint8_t len_l8;}packshdr_t;#define packshdr_get_len(p)		(uint16_t)((p)->len_h3 << 8 | (p)->len_l8)#define packshdr_set_len(p, len) do { \	(p)->len_h3 = (len & 0x700) >> 8; \	(p)->len_l8 = (len & 0xff); \}while (0)#define packshdr_set(p, _fc, _fsn, len) do { \	(p)->fc = (_fc); \	(p)->fsn = (_fsn); \	packshdr_set_len(p, len); \}while (0)typedef struct extpackshdr_s{	uint8_t fsn_h6	:6,		fc	:2;	uint8_t len_h3	:3,		fsn_l5	:5;	uint8_t len_l8;}extpackshdr_t;#define extpackshdr_get_fsn(p)		extfragshdr_get_fsn(p)#define extpackshdr_set_fsn(p, fsn)	extfragshdr_set_fsn(p, fsn)#define extpackshdr_get_len(p)		packshdr_get_len(p)#define extpackshdr_set_len(p, len)	packshdr_set_len(p, len)#define extpackshdr_set(p, _fc, fsn, len) do { \	(p)->fc = (_fc); \	extpackshdr_set_fsn(p, fsn); \	extpackshdr_set_len(p, len); \}while (0)#define NO_FRAG		0#define LAST_FRAG	1#define FIRST_FRAG	2#define MIDDLE_FRAG	3/* ********************************************************* *		MAC Message Data Structures * ********************************************************* */typedef enum _MAC_MANAGEMENT_MSG_ENUM{        UCD = 0,        DCD,        DL_MAP,        UL_MAP,        RNG_REQ,        RNG_RSP = 5,        REG_REQ,        REG_RSP = 7,        PKM_REQ = 9,        PKM_RSP = 10,        DSA_REQ,        DSA_RSP,        DSA_ACK,        DSC_REQ,        DSC_RSP = 15,        DSC_ACK,        DSD_REQ,        DSD_RSP = 18,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -