1 #include <net/if.h> 2 #include <errno.h> 3 #include <string.h> 4 5 #include "nl80211.h" 6 #include "iw.h" 7 8 SECTION(ocb); 9 10 static int join_ocb(struct nl80211_state *state, struct nl_cb *cb, 11 struct nl_msg *msg, int argc, char **argv, 12 enum id_input id) 13 { 14 unsigned long freq; 15 char *end; 16 int i; 17 static const struct { 18 const char *name; 19 unsigned int width; 20 } *chanmode_selected, chanmode[] = { 21 { .name = "5MHZ", 22 .width = NL80211_CHAN_WIDTH_5 }, 23 { .name = "10MHZ", 24 .width = NL80211_CHAN_WIDTH_10 }, 25 }; 26 27 if (argc < 2) 28 return 1; 29 30 /* freq */ 31 freq = strtoul(argv[0], &end, 10); 32 if (*end != '\0') 33 return 1; 34 35 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); 36 argv++; 37 argc--; 38 39 /* channel width */ 40 for (i = 0; i < ARRAY_SIZE(chanmode); i++) { 41 if (strcasecmp(chanmode[i].name, argv[0]) == 0) { 42 chanmode_selected = &chanmode[i]; 43 break; 44 } 45 } 46 if (chanmode_selected) { 47 NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, 48 chanmode_selected->width); 49 NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ1, freq); 50 51 argv++; 52 argc--; 53 } else { 54 return 1; 55 } 56 57 return 0; 58 59 nla_put_failure: 60 return -ENOBUFS; 61 } 62 COMMAND(ocb, join, "<freq in MHz> <5MHZ|10MHZ>", 63 NL80211_CMD_JOIN_OCB, 0, CIB_NETDEV, join_ocb, 64 "Join the OCB mode network."); 65 66 static int leave_ocb(struct nl80211_state *state, struct nl_cb *cb, 67 struct nl_msg *msg, int argc, char **argv, 68 enum id_input id) 69 { 70 if (argc) 71 return 1; 72 73 return 0; 74 } 75 COMMAND(ocb, leave, NULL, NL80211_CMD_LEAVE_OCB, 0, CIB_NETDEV, leave_ocb, 76 "Leave the OCB mode network."); 77