]>
Commit | Line | Data |
---|---|---|
748f8489 | 1 | #include <ctype.h> |
3d1e8704 | 2 | #include "iw.h" |
f5f7b1d0 | 3 | #include "nl80211.h" |
3d1e8704 LCC |
4 | |
5 | int mac_addr_n2a(char *mac_addr, unsigned char *arg) | |
6 | { | |
53e5ce7a | 7 | int i, l; |
3d1e8704 LCC |
8 | |
9 | l = 0; | |
10 | for (i = 0; i < ETH_ALEN ; i++) { | |
11 | if (i == 0) { | |
53e5ce7a | 12 | sprintf(mac_addr+l, "%02x", arg[i]); |
3d1e8704 LCC |
13 | l += 2; |
14 | } else { | |
53e5ce7a | 15 | sprintf(mac_addr+l, ":%02x", arg[i]); |
3d1e8704 LCC |
16 | l += 3; |
17 | } | |
18 | } | |
19 | return 0; | |
20 | } | |
21 | ||
22 | int mac_addr_a2n(unsigned char *mac_addr, char *arg) | |
23 | { | |
24 | int i; | |
25 | ||
26 | for (i = 0; i < ETH_ALEN ; i++) { | |
27 | int temp; | |
28 | char *cp = strchr(arg, ':'); | |
29 | if (cp) { | |
30 | *cp = 0; | |
31 | cp++; | |
32 | } | |
33 | if (sscanf(arg, "%x", &temp) != 1) | |
34 | return -1; | |
35 | if (temp < 0 || temp > 255) | |
36 | return -1; | |
37 | ||
38 | mac_addr[i] = temp; | |
39 | if (!cp) | |
40 | break; | |
41 | arg = cp; | |
42 | } | |
43 | if (i < ETH_ALEN - 1) | |
44 | return -1; | |
45 | ||
46 | return 0; | |
47 | } | |
541ef425 JB |
48 | |
49 | static const char *ifmodes[NL80211_IFTYPE_MAX + 1] = { | |
50 | "unspecified", | |
51 | "IBSS", | |
34e78ed0 | 52 | "managed", |
541ef425 | 53 | "AP", |
34e78ed0 | 54 | "AP/VLAN", |
541ef425 | 55 | "WDS", |
34e78ed0 | 56 | "monitor", |
541ef425 JB |
57 | "mesh point" |
58 | }; | |
59 | ||
60 | static char modebuf[100]; | |
61 | ||
62 | const char *iftype_name(enum nl80211_iftype iftype) | |
63 | { | |
64 | if (iftype <= NL80211_IFTYPE_MAX) | |
65 | return ifmodes[iftype]; | |
66 | sprintf(modebuf, "Unknown mode (%d)", iftype); | |
67 | return modebuf; | |
68 | } | |
379f8397 JB |
69 | |
70 | int ieee80211_channel_to_frequency(int chan) | |
71 | { | |
72 | if (chan < 14) | |
73 | return 2407 + chan * 5; | |
74 | ||
75 | if (chan == 14) | |
76 | return 2484; | |
77 | ||
78 | /* FIXME: dot11ChannelStartingFactor (802.11-2007 17.3.8.3.2) */ | |
79 | return (chan + 1000) * 5; | |
80 | } | |
81 | ||
82 | int ieee80211_frequency_to_channel(int freq) | |
83 | { | |
84 | if (freq == 2484) | |
85 | return 14; | |
86 | ||
87 | if (freq < 2484) | |
88 | return (freq - 2407) / 5; | |
89 | ||
90 | /* FIXME: dot11ChannelStartingFactor (802.11-2007 17.3.8.3.2) */ | |
91 | return freq/5 - 1000; | |
92 | } | |
748f8489 JB |
93 | |
94 | void print_ssid_escaped(const uint8_t len, const uint8_t *data) | |
95 | { | |
96 | int i; | |
97 | ||
98 | for (i = 0; i < len; i++) { | |
99 | if (isprint(data[i])) | |
100 | printf("%c", data[i]); | |
101 | else | |
102 | printf("\\x%.2x", data[i]); | |
103 | } | |
104 | } |