blob: 40a9568c02486fe65102f5de8df51df0c0764a7e [file] [log] [blame]
Johannes Bergf408e012008-09-18 19:32:11 +02001#include "nl80211.h"
Luis Carlos Cobo3d1e8702008-04-01 12:03:41 -07002#include "iw.h"
3
4int mac_addr_n2a(char *mac_addr, unsigned char *arg)
5{
Johannes Berg53e5ce72008-04-02 16:49:50 +02006 int i, l;
Luis Carlos Cobo3d1e8702008-04-01 12:03:41 -07007
8 l = 0;
9 for (i = 0; i < ETH_ALEN ; i++) {
10 if (i == 0) {
Johannes Berg53e5ce72008-04-02 16:49:50 +020011 sprintf(mac_addr+l, "%02x", arg[i]);
Luis Carlos Cobo3d1e8702008-04-01 12:03:41 -070012 l += 2;
13 } else {
Johannes Berg53e5ce72008-04-02 16:49:50 +020014 sprintf(mac_addr+l, ":%02x", arg[i]);
Luis Carlos Cobo3d1e8702008-04-01 12:03:41 -070015 l += 3;
16 }
17 }
18 return 0;
19}
20
21int 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 Berg541ef422008-09-16 14:50:11 +020047
48static 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
59static char modebuf[100];
60
61const 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 Berg379f8392008-12-08 12:53:58 +010068
69int 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
81int 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}