Johannes Berg | f408e01 | 2008-09-18 19:32:11 +0200 | [diff] [blame] | 1 | #include "nl80211.h" |
Luis Carlos Cobo | 3d1e870 | 2008-04-01 12:03:41 -0700 | [diff] [blame] | 2 | #include "iw.h" |
| 3 | |
| 4 | int mac_addr_n2a(char *mac_addr, unsigned char *arg) |
| 5 | { |
Johannes Berg | 53e5ce7 | 2008-04-02 16:49:50 +0200 | [diff] [blame] | 6 | int i, l; |
Luis Carlos Cobo | 3d1e870 | 2008-04-01 12:03:41 -0700 | [diff] [blame] | 7 | |
| 8 | l = 0; |
| 9 | for (i = 0; i < ETH_ALEN ; i++) { |
| 10 | if (i == 0) { |
Johannes Berg | 53e5ce7 | 2008-04-02 16:49:50 +0200 | [diff] [blame] | 11 | sprintf(mac_addr+l, "%02x", arg[i]); |
Luis Carlos Cobo | 3d1e870 | 2008-04-01 12:03:41 -0700 | [diff] [blame] | 12 | l += 2; |
| 13 | } else { |
Johannes Berg | 53e5ce7 | 2008-04-02 16:49:50 +0200 | [diff] [blame] | 14 | sprintf(mac_addr+l, ":%02x", arg[i]); |
Luis Carlos Cobo | 3d1e870 | 2008-04-01 12:03:41 -0700 | [diff] [blame] | 15 | l += 3; |
| 16 | } |
| 17 | } |
| 18 | return 0; |
| 19 | } |
| 20 | |
| 21 | int mac_addr_a2n(unsigned char *mac_addr, char *arg) |
| 22 | { |
| 23 | int i; |
| 24 | |
| 25 | for (i = 0; i < ETH_ALEN ; i++) { |
| 26 | int temp; |
| 27 | char *cp = strchr(arg, ':'); |
| 28 | if (cp) { |
| 29 | *cp = 0; |
| 30 | cp++; |
| 31 | } |
| 32 | if (sscanf(arg, "%x", &temp) != 1) |
| 33 | return -1; |
| 34 | if (temp < 0 || temp > 255) |
| 35 | return -1; |
| 36 | |
| 37 | mac_addr[i] = temp; |
| 38 | if (!cp) |
| 39 | break; |
| 40 | arg = cp; |
| 41 | } |
| 42 | if (i < ETH_ALEN - 1) |
| 43 | return -1; |
| 44 | |
| 45 | return 0; |
| 46 | } |
Johannes Berg | 541ef42 | 2008-09-16 14:50:11 +0200 | [diff] [blame] | 47 | |
| 48 | static const char *ifmodes[NL80211_IFTYPE_MAX + 1] = { |
| 49 | "unspecified", |
| 50 | "IBSS", |
| 51 | "Station", |
| 52 | "AP", |
| 53 | "AP(VLAN)", |
| 54 | "WDS", |
| 55 | "Monitor", |
| 56 | "mesh point" |
| 57 | }; |
| 58 | |
| 59 | static char modebuf[100]; |
| 60 | |
| 61 | const char *iftype_name(enum nl80211_iftype iftype) |
| 62 | { |
| 63 | if (iftype <= NL80211_IFTYPE_MAX) |
| 64 | return ifmodes[iftype]; |
| 65 | sprintf(modebuf, "Unknown mode (%d)", iftype); |
| 66 | return modebuf; |
| 67 | } |
Johannes Berg | 379f839 | 2008-12-08 12:53:58 +0100 | [diff] [blame^] | 68 | |
| 69 | int ieee80211_channel_to_frequency(int chan) |
| 70 | { |
| 71 | if (chan < 14) |
| 72 | return 2407 + chan * 5; |
| 73 | |
| 74 | if (chan == 14) |
| 75 | return 2484; |
| 76 | |
| 77 | /* FIXME: dot11ChannelStartingFactor (802.11-2007 17.3.8.3.2) */ |
| 78 | return (chan + 1000) * 5; |
| 79 | } |
| 80 | |
| 81 | int ieee80211_frequency_to_channel(int freq) |
| 82 | { |
| 83 | if (freq == 2484) |
| 84 | return 14; |
| 85 | |
| 86 | if (freq < 2484) |
| 87 | return (freq - 2407) / 5; |
| 88 | |
| 89 | /* FIXME: dot11ChannelStartingFactor (802.11-2007 17.3.8.3.2) */ |
| 90 | return freq/5 - 1000; |
| 91 | } |