From 97533f67cccd99818153ace4ed79577d7e0a9cc5 Mon Sep 17 00:00:00 2001 From: 7u83 <7u83@mail.ru> Date: Tue, 13 Sep 2022 08:18:05 +0200 Subject: [PATCH] some stuff for dot11 handling added --- src/ac/wtpman.c | 11 +++++++++++ src/cw/cw_format_pkt_hdr.c | 3 ++- src/cw/dot11.c | 3 +-- src/cw/dot11.h | 31 +++++++++++++++++++------------ src/cw/dot11_inline.c | 8 ++++++++ 5 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/ac/wtpman.c b/src/ac/wtpman.c index 6a52e54c..2b8b4f74 100644 --- a/src/ac/wtpman.c +++ b/src/ac/wtpman.c @@ -44,6 +44,8 @@ #include "actube.h" +#include "cw/dot11.h" + static void wtpman_remove(struct wtpman *wtpman) { @@ -319,6 +321,15 @@ static int dataman_process_msg(struct cw_Conn *nc, uint8_t * rawmsg, int len, uint8_t * dot11frame = rawmsg + offs; int dot11len = len-offs; cw_dbg_dot11_frame(dot11frame,dot11len); + + char frame[1000]; + dot11_init_assoc_resp(frame); + dot11_copy_mac(dot11_get_sa(dot11frame),dot11_get_da(frame)); + dot11_copy_mac(dot11_get_bssid(dot11frame),dot11_get_bssid(frame)); + dot11_copy_mac(dot11_get_da(dot11frame),dot11_get_sa(frame)); + + + return 0; } diff --git a/src/cw/cw_format_pkt_hdr.c b/src/cw/cw_format_pkt_hdr.c index 4685f95f..53dcaabc 100644 --- a/src/cw/cw_format_pkt_hdr.c +++ b/src/cw/cw_format_pkt_hdr.c @@ -7,7 +7,7 @@ int cw_format_dot11_fc_flags(char *dst, uint8_t *frame){ char *s = dst; - uint8_t f = frame[2]; + uint8_t f = frame[0]; s+=sprintf(s,"ToDS:%d ", f&1 ? 1:0); s+=sprintf(s,"FromDS:%d ", f&2 ? 1:0); s+=sprintf(s,"More Frgs:%d ", f&4 ? 1:0); @@ -88,6 +88,7 @@ int cw_format_dot11_hdr(char * dst, uint8_t * packet, int len) s+=format_mac(s,dot11_get_bssid(packet),6); s+=sprintf(s," seq: %d\n",dot11_get_seq(packet)); s+=cw_format_dot11_fc_flags(s,packet); + s+=sprintf(s,"\nDuration: %d",dot11_get_duration(packet)); // /* switch (type){ case DOT11_ASSOC_REQ: diff --git a/src/cw/dot11.c b/src/cw/dot11.c index 78a49057..a16fa503 100644 --- a/src/cw/dot11.c +++ b/src/cw/dot11.c @@ -61,6 +61,5 @@ struct cw_StrListElem dot11_names[]={ int dot11_init_assoc_resp(uint8_t * dst) { - dst[0]=0; - + dot11_set_type_and_subtype(dst,DOT11_ASSOC_RESP); } diff --git a/src/cw/dot11.h b/src/cw/dot11.h index 8b4e327e..22147d6e 100644 --- a/src/cw/dot11.h +++ b/src/cw/dot11.h @@ -148,16 +148,11 @@ uint16_t dot11_get_word(uint8_t * ptr); #define dot11_get_version(frame) ( (frame)[1] & 0x03) #define dot11_get_type(frame) ( ((frame)[1] & 0x0c) >> 2) #define dot11_get_subtype(frame) ( (frame)[1] >> 4 ) -#define dot11_get_type_and_subtype( frame) ((frame)[1]) -/** - * Get Frame Control field - * @param frame - * @return Frame Control field - */ -#define dot11_get_fc(frame) dot11_get_word(frame) +#define dot11_get_type_and_subtype(frame) ((frame)[1]) +#define dot11_set_type_and_subtype(frame,val) ((frame)[1]=val) + -#define dot11_get_duration(frame) dot11_get_word(frame+2) void dot11_get_address(uint8_t * dst, uint8_t * frame); @@ -251,10 +246,18 @@ extern struct cw_StrListElem dot11_names[]; #define dot11_get_frame_name(data) cw_strlist_get_str(dot11_names,(data)[1]) -#define dot11_get_da(frame) ((frame)+2+2) -#define dot11_get_sa(frame) ((frame)+2+2+6) -#define dot11_get_bssid(frame) ((frame)+2+2+12) -#define dot11_get_seq(frame) dot11_get_word((frame)+2+2+12+6) +/** + * Get Frame Control field + * @param frame uint8_t pointer to the frame + * @return uint16_t Frame Control field + */ +#define dot11_get_fc(frame) dot11_get_word(frame) +#define dot11_get_duration(frame) dot11_get_word(frame+2) +#define dot11_get_da(frame) ((frame)+4) +#define dot11_get_sa(frame) ((frame)+10) +#define dot11_get_bssid(frame) ((frame)+16) +#define dot11_get_seq(frame) dot11_get_word((frame)+22) +#define dot11_get_body(frame) ((frame)+24) #define dot11_assoc_req_get_cap(frame) \ dot11_get_word((frame)+2+2+12+6+2) @@ -269,6 +272,10 @@ extern struct cw_StrListElem dot11_names[]; +#define dot11_copy_mac(src,dst)\ + memcpy(dst,src,6); + + /** diff --git a/src/cw/dot11_inline.c b/src/cw/dot11_inline.c index 1a9a5bfb..73f3a52c 100644 --- a/src/cw/dot11_inline.c +++ b/src/cw/dot11_inline.c @@ -71,3 +71,11 @@ int dot11_put_dsss_param_set(uint8_t *dst,int ch) { } +#define DOT11_INLINE + + +DOT11_INLINE +uint8_t * dot11_get_body(uint8_t * frame) +{ + +}