Skip to content

Commit

Permalink
Protecting and verifying frames
Browse files Browse the repository at this point in the history
  • Loading branch information
Javier Cardona committed Apr 1, 2011
1 parent a98f2de commit b3bfd42
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
14 changes: 13 additions & 1 deletion ampe.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,19 @@
#include "sae.h"

int
process_plink_frame (struct ieee80211_mgmt_frame *frame, int *len, int max_len)
protect_plink_frame (struct ieee80211_mgmt_frame *frame, int *len, int max_len)
{
/* Henceforth this frame is self-protected */
frame->action.category = 15;
//frame->action.u.var8[0] = 0xbb;
return 0;
}

int
verify_plink_frame (struct ieee80211_mgmt_frame *frame, int *len, int max_len)
{
/* Henceforth this frame is un-protected */
frame->action.category = 13;
//frame->action.u.var8[0] = 0xaa;
return 0;
}
13 changes: 11 additions & 2 deletions ampe.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef __AMPE_H
#define __AMPE_H
/**
* process_plink_frame - protect peer link management frames
* protect_plink_frame - protect peer link management frames
* gets unsecured mesh peering management frames and returns self protected
* frames with the right AMPE fields. All processing is done in place, so
* the returned frame is ready to be sent.
Expand All @@ -15,5 +15,14 @@
* frame. If not, the function will return -ENOMEM.
* Returns: 0 on success, negative on failure.
*/
int process_plink_frame (struct ieee80211_mgmt_frame *frame, int *len, int max_len);
int protect_plink_frame (struct ieee80211_mgmt_frame *frame, int *len, int max_len);

/**
* verify_plink_frame - verify peer link management frames
*
* See above funtion for arguments.
*
* Returns: 0 on success, negative on failure.
*/
int verify_plink_frame (struct ieee80211_mgmt_frame *frame, int *len, int max_len);
#endif
8 changes: 8 additions & 0 deletions ieee802_11.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ struct ieee80211_mgmt_frame {
unsigned short var16[0];
}u;
} __attribute__ ((packed)) beacon;
struct {
unsigned char category;
unsigned char action;
union {
unsigned char var8[0];
unsigned short var16[0];
}u;
} __attribute__ ((packed)) action;
};
} __attribute__ ((packed));

Expand Down
27 changes: 12 additions & 15 deletions linux/meshd-nl80211.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,9 @@ static int register_for_plink_frames(struct netlink_config_s *nlcfg)
#define IEEE80211_FTYPE_MGMT 0x0000
#define IEEE80211_STYPE_ACTION 0x00D0
uint16_t frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
int ret;
int ret = 0;
char *pret;
#ifdef SOON
char action_codes[3][2] = { {15, 1 }, {15, 2}, {15, 3}}; /* 11s draft 10.0, Table 7-24, Self-Protected */
#endif
char action_codes[3][2] = { {30, 0 }, {30, 1}, {30, 2}}; /* This is what the kernel now gives us */
char action_codes[3][2] = {{15, 1 }, {15, 2}, {15, 3}}; /* 11s draft 10.0, Table 7-24, Self-Protected */

for (i = 0; i < 3; i++) {
msg = nlmsg_alloc();
Expand Down Expand Up @@ -492,16 +489,16 @@ static int event_handler(struct nl_msg *msg, void *arg)
/* Action (peer link) frames go to AMPE */
} else if (frame->frame_control == htole16((IEEE802_11_FC_TYPE_MGMT << 2 |
IEEE802_11_FC_STYPE_ACTION << 4))) {
if (process_plink_frame(frame, &frame_len, frame_len))
fprintf(stderr, "libsae: process_plink_frame failed\n");
else {
/* The current 11s draft requires that address 3
* (BSSID) == address2, but frames that we get from
* the kernel may conform to older 11s drafts and use
* a null BSSID. */
memcpy(frame->bssid, frame->sa, ETH_ALEN);
meshd_write_mgmt((char*) frame, frame_len);
}
/* ingress (to be verified)? */
if (memcmp(frame->da, nlcfg.mymacaddr, ETH_ALEN) == 0) {
fprintf(stderr, "verifying frame\n");
verify_plink_frame(frame, &frame_len, frame_len);
} else if (memcmp(frame->sa, nlcfg.mymacaddr, ETH_ALEN) == 0) {
fprintf(stderr, "protecting frame\n");
protect_plink_frame(frame, &frame_len, frame_len);
} else
debug_msg("got unexpected frame (%d.%d)\n", now.tv_sec, now.tv_usec);
meshd_write_mgmt((char*) frame, frame_len);
} else
debug_msg("got unexpected frame (%d.%d)\n", now.tv_sec, now.tv_usec);
}
Expand Down

0 comments on commit b3bfd42

Please sign in to comment.