]>
Commit | Line | Data |
---|---|---|
3d1e8704 | 1 | #include "iw.h" |
f5f7b1d0 | 2 | #include "nl80211.h" |
3d1e8704 LCC |
3 | |
4 | int mac_addr_n2a(char *mac_addr, unsigned char *arg) | |
5 | { | |
53e5ce7a | 6 | int i, l; |
3d1e8704 LCC |
7 | |
8 | l = 0; | |
9 | for (i = 0; i < ETH_ALEN ; i++) { | |
10 | if (i == 0) { | |
53e5ce7a | 11 | sprintf(mac_addr+l, "%02x", arg[i]); |
3d1e8704 LCC |
12 | l += 2; |
13 | } else { | |
53e5ce7a | 14 | sprintf(mac_addr+l, ":%02x", arg[i]); |
3d1e8704 LCC |
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 | } | |
541ef425 JB |
47 | |
48 | static const char *ifmodes[NL80211_IFTYPE_MAX + 1] = { | |
49 | "unspecified", | |
50 | "IBSS", | |
34e78ed0 | 51 | "managed", |
541ef425 | 52 | "AP", |
34e78ed0 | 53 | "AP/VLAN", |
541ef425 | 54 | "WDS", |
34e78ed0 | 55 | "monitor", |
541ef425 JB |
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 | } | |
379f8397 JB |
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 | } |