1 // SPDX-License-Identifier: GPL-2.0-only
2 /******************************************************************************
4 Copyright(c) 2005 Intel Corporation. All rights reserved.
8 Intel Linux Wireless <ilw@linux.intel.com>
9 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
11 ******************************************************************************/
12 #include <linux/compiler.h>
13 #include <linux/errno.h>
14 #include <linux/if_arp.h>
15 #include <linux/in6.h>
18 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <linux/netdevice.h>
21 #include <linux/proc_fs.h>
22 #include <linux/skbuff.h>
23 #include <linux/tcp.h>
24 #include <linux/types.h>
25 #include <linux/wireless.h>
26 #include <linux/etherdevice.h>
27 #include <linux/uaccess.h>
31 int libipw_is_valid_channel(struct libipw_device
*ieee
, u8 channel
)
35 /* Driver needs to initialize the geography map before using
36 * these helper functions */
37 if (ieee
->geo
.bg_channels
== 0 && ieee
->geo
.a_channels
== 0)
40 if (ieee
->freq_band
& LIBIPW_24GHZ_BAND
)
41 for (i
= 0; i
< ieee
->geo
.bg_channels
; i
++)
42 /* NOTE: If G mode is currently supported but
43 * this is a B only channel, we don't see it
45 if ((ieee
->geo
.bg
[i
].channel
== channel
) &&
46 !(ieee
->geo
.bg
[i
].flags
& LIBIPW_CH_INVALID
) &&
47 (!(ieee
->mode
& IEEE_G
) ||
48 !(ieee
->geo
.bg
[i
].flags
& LIBIPW_CH_B_ONLY
)))
49 return LIBIPW_24GHZ_BAND
;
51 if (ieee
->freq_band
& LIBIPW_52GHZ_BAND
)
52 for (i
= 0; i
< ieee
->geo
.a_channels
; i
++)
53 if ((ieee
->geo
.a
[i
].channel
== channel
) &&
54 !(ieee
->geo
.a
[i
].flags
& LIBIPW_CH_INVALID
))
55 return LIBIPW_52GHZ_BAND
;
60 int libipw_channel_to_index(struct libipw_device
*ieee
, u8 channel
)
64 /* Driver needs to initialize the geography map before using
65 * these helper functions */
66 if (ieee
->geo
.bg_channels
== 0 && ieee
->geo
.a_channels
== 0)
69 if (ieee
->freq_band
& LIBIPW_24GHZ_BAND
)
70 for (i
= 0; i
< ieee
->geo
.bg_channels
; i
++)
71 if (ieee
->geo
.bg
[i
].channel
== channel
)
74 if (ieee
->freq_band
& LIBIPW_52GHZ_BAND
)
75 for (i
= 0; i
< ieee
->geo
.a_channels
; i
++)
76 if (ieee
->geo
.a
[i
].channel
== channel
)
82 u32
libipw_channel_to_freq(struct libipw_device
* ieee
, u8 channel
)
84 const struct libipw_channel
* ch
;
86 /* Driver needs to initialize the geography map before using
87 * these helper functions */
88 if (ieee
->geo
.bg_channels
== 0 && ieee
->geo
.a_channels
== 0)
91 ch
= libipw_get_channel(ieee
, channel
);
97 u8
libipw_freq_to_channel(struct libipw_device
* ieee
, u32 freq
)
101 /* Driver needs to initialize the geography map before using
102 * these helper functions */
103 if (ieee
->geo
.bg_channels
== 0 && ieee
->geo
.a_channels
== 0)
108 if (ieee
->freq_band
& LIBIPW_24GHZ_BAND
)
109 for (i
= 0; i
< ieee
->geo
.bg_channels
; i
++)
110 if (ieee
->geo
.bg
[i
].freq
== freq
)
111 return ieee
->geo
.bg
[i
].channel
;
113 if (ieee
->freq_band
& LIBIPW_52GHZ_BAND
)
114 for (i
= 0; i
< ieee
->geo
.a_channels
; i
++)
115 if (ieee
->geo
.a
[i
].freq
== freq
)
116 return ieee
->geo
.a
[i
].channel
;
121 void libipw_set_geo(struct libipw_device
*ieee
,
122 const struct libipw_geo
*geo
)
124 memcpy(ieee
->geo
.name
, geo
->name
, 3);
125 ieee
->geo
.name
[3] = '\0';
126 ieee
->geo
.bg_channels
= geo
->bg_channels
;
127 ieee
->geo
.a_channels
= geo
->a_channels
;
128 memcpy(ieee
->geo
.bg
, geo
->bg
, geo
->bg_channels
*
129 sizeof(struct libipw_channel
));
130 memcpy(ieee
->geo
.a
, geo
->a
, ieee
->geo
.a_channels
*
131 sizeof(struct libipw_channel
));
134 const struct libipw_geo
*libipw_get_geo(struct libipw_device
*ieee
)
139 u8
libipw_get_channel_flags(struct libipw_device
* ieee
, u8 channel
)
141 int index
= libipw_channel_to_index(ieee
, channel
);
144 return LIBIPW_CH_INVALID
;
146 if (channel
<= LIBIPW_24GHZ_CHANNELS
)
147 return ieee
->geo
.bg
[index
].flags
;
149 return ieee
->geo
.a
[index
].flags
;
152 static const struct libipw_channel bad_channel
= {
154 .flags
= LIBIPW_CH_INVALID
,
158 const struct libipw_channel
*libipw_get_channel(struct libipw_device
161 int index
= libipw_channel_to_index(ieee
, channel
);
166 if (channel
<= LIBIPW_24GHZ_CHANNELS
)
167 return &ieee
->geo
.bg
[index
];
169 return &ieee
->geo
.a
[index
];
172 EXPORT_SYMBOL(libipw_get_channel
);
173 EXPORT_SYMBOL(libipw_get_channel_flags
);
174 EXPORT_SYMBOL(libipw_is_valid_channel
);
175 EXPORT_SYMBOL(libipw_freq_to_channel
);
176 EXPORT_SYMBOL(libipw_channel_to_freq
);
177 EXPORT_SYMBOL(libipw_channel_to_index
);
178 EXPORT_SYMBOL(libipw_set_geo
);
179 EXPORT_SYMBOL(libipw_get_geo
);