📄 znwk.h
字号:
/*********************************************************************
* Macro: BYTE NWKGet(void)
*
* PreCondition: NWKIsGetReady() = TRUE
*
* Input: None
*
* Output: A data byte
*
* Side Effects: None
*
* Overview: This is a wrapper on MAC function to provide a
* level of abstraction.
* It fetches one data byte from current receive buffer
*
* Note: None
********************************************************************/
//du 直接从NWKPayLoad中取数据
BYTE NWKGet(void);
/*********************************************************************
* Macro: BYTE NWKGetArray(BYTE *v, BYTE n)
*
* PreCondition: NWKIsGetReady() = TRUE
*
* Input: None
*
* Output: v - Buffer containing received data bytes
* n - Number of bytes to get
*
* Side Effects: None
*
* Overview: This is a wrapper on MAC function to provide a
* level of abstraction.
* It fetches given number of data bytes from current receive buffer
*
* Note: None
********************************************************************/
//du 直接从NWKPayLoad中取数据
BYTE NWKGetArray(BYTE *v, BYTE n);
/*********************************************************************
* Macro: void NWKDiscardRx(void)
*
* PreCondition: NWKIsGetReady() = TRUE
*
* Input: None
*
* Output: None
*
* Side Effects: None
*
* Overview: This macro reclaims current receive frame buffer space.
*
* Note: This macro must be called for evey frame recieved
* to reclaim receive buffer space.
********************************************************************/
#define NWKDiscardRx() nwkCurrentFrame.Flags.bits.bIsInProcess = FALSE; MACDiscardRx()
/*********************************************************************
* Macro: void NWKDisable(void)
*
* PreCondition: None
*
* Input: None
*
* Output: None
*
* Side Effects: None
*
* Overview: This macro disables NWK module state machine.
*
* Note: This macro is called in conjunction with MACDisable
* to enter into low power mode.
********************************************************************/
#define NWKDisable() {nwkCurrentFrame.Flags.bits.bIsInProcess = FALSE; MACDisable();}
//路由
#define NWK_CMD_ROUTE_REQUEST 0x01
#define NWK_CMD_ROUTE_REPLY 0x02
#define NWK_CMD_ROUTE_ERROR 0x03
#define NWK_CMD_ROUTE_ACK 0x05
//aodv message
//////////////////////////////////////////////////////////////////////////////////////////////////////
#define AODV_RREQ 101
#define AODV_RREP 102
#define AODV_RERR 103
#define AODV_RREP_ACK 104
/*RREQ包格式
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type |J|R|G|D|U| Reserved | Hop Count |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| RREQ ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Destination IP Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Destination Sequence Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Originator IP Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Originator Sequence Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
typedef struct _RREQ
{
BYTE type;
union
{
struct
{
BYTE :3;
BYTE u:1;
BYTE d:1;
BYTE g:1;
BYTE r:1;
BYTE j:1;
}bit;
BYTE val;
}flag;
BYTE reserved;
BYTE hopCount;
WORD req_id;
WORD dest_ip;
WORD dest_seq;
WORD source_ip;
WORD sourceSeq;
}RREQ;
/*RREP包格式
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type |R|A| Reserved |Prefix Sz| Hop Count |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Destination IP address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Destination Sequence Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Originator IP address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| life_time |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
typedef struct _RREP
{
BYTE type;
union
{
struct
{
BYTE :6;
BYTE a:1;
BYTE r:1;
}bit;
BYTE val;
}flag;
BYTE reserved;
BYTE prefix; //低6位有效
BYTE hopCount;
WORD dest_ip;
WORD dest_seq;
WORD source_ip;
WORD life_time;
}RREP;
/*RERR包格式
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type |N| Reserved | DestCount |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Unreachable Destination IP Address (1) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Unreachable Destination Sequence Number (1) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-|
| Additional Unreachable Destination IP Addresses (if needed) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Additional Unreachable Destination Sequence Numbers (if needed)|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
typedef struct _RERR
{
BYTE type;
union
{
struct
{
BYTE :7;
BYTE n:1;
}bit;
BYTE val;
}flag;
BYTE reserved;
BYTE dest_count;
}RERR;
struct Err_Dest{
WORD unreach_dest_ip;
WORD unreach_dest_seq;
};
struct Err_Dest_List{
struct Err_Dest err_dest;
struct Err_Dest_List * next;
};
/*RREP_ACK包格式
0 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
typedef struct _RREP_ACK
{
BYTE type;
BYTE reserved;
}RREP_ACK;
//////////////////////////////////////////////////////////////////////////////////////////////////////
//路由表项
struct Route_Table_Entry
{
WORD dest_ip;
WORD dest_seq;
BYTE hopCount;
WORD next_ip;
struct Precuror_Entry *precuror;
WORD life_time;//路由表项的生存时间
union
{
struct
{ BYTE is_self_route:1;
BYTE is_route_valid:1;
BYTE is_route_seq_valid:1;
BYTE :5;
}bit;
BYTE val;
}flag;
WORD req_id;//not use in current edition
struct Route_Table_Entry * prev;
struct Route_Table_Entry * next;
};
//先驱表项
struct Precuror_Entry
{
WORD prev_ip;
struct Precuror_Entry *prev;
struct Precuror_Entry *next;
};
struct REQ_ID
{
WORD source_ip;
WORD dest_ip;
WORD req_id;
WORD life_time;
struct REQ_ID *next;
};
struct NWK_FRAME_STATUS
{
union
{
struct
{
unsigned int bIsInUse : 1;
unsigned int bIsConfirmed:1;
unsigned int bIsTimedOut:1;
} bits;
BYTE Val;
} Flags;
BYTE macDSN;
//TICK lastTick;
BYTE retryCount;
} ;
//route_table function
/////////////////////////////////////////////////////////////////////////////////////////////////////
void init_route_table();
struct Route_Table_Entry *create_route( WORD ip);
void insert_route(struct Route_Table_Entry * new_route);
struct Route_Table_Entry *lookup_route( WORD dest_ip);
void cleanup_route_table();
//void expire_aodv_route(Route_Table_Entry * tmp_route);
void delete_route( WORD dest_ip);
void update_route( WORD dest_ip, WORD next_ip, WORD dest_seq, BYTE hopCount);
//int flush_route_table();
//Route_Table_Entry *first_aodv_route();
//////////////////////////////////////////////////////////////////////////////////////////////////////
//req_id_queue function
///////////////////////////////////////////////////////////////////////////////////////////////////////
void init_req_id_queue();
void insert_req_id( WORD src_ip, WORD dst_ip, WORD id);
struct REQ_ID *find_req_id( WORD src_ip, WORD id);
void cleanup_req_id_queue();
void flush_req_id_queue();
//////////////////////////////////////////////////////////////////////////////////////////////////////
//aodv task function
//////////////////////////////////////////////////////////////////////////////////////////////////////
void nwk_proc_rreq( WORD prev_ip, RREQ* request, unsigned int length);
void nwk_proc_rrep( WORD prev_ip, RREP *reply, unsigned int length);
void nwk_proc_rerr( WORD prev_ip, RERR* error, unsigned int length);
void nwk_proc_rrep_ack( WORD prev_ip, RREP_ACK* ack, unsigned int length);
//////////////////////////////////////////////////////////////////////////////////////////////////////
void send_rreq( WORD dest_ip);
void forward_rreq( RREQ *request);
void send_rrep( RREQ * request);
void forward_rrep( RREP *reply);
void send_rrep_ack( WORD dest_ip);
void gen_rerr( WORD break_ip);
void send_rerr(struct Err_Dest_List *err_list, WORD dest_count);
BOOL seq_less_or_equal(WORD seq_one, WORD seq_two);
BOOL seq_greater(WORD seq_one,WORD seq_two);
void init_route();
BOOL is_route_discovered(SHORT_ADDR);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -