1 /*
2  * Copyright (c) 2015-2016 Quantenna Communications, Inc.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  */
15 
16 #include <linux/nl80211.h>
17 
18 #include "qlink_util.h"
19 
20 u16 qlink_iface_type_to_nl_mask(u16 qlink_type)
21 {
22 	u16 result = 0;
23 
24 	switch (qlink_type) {
25 	case QLINK_IFTYPE_AP:
26 		result |= BIT(NL80211_IFTYPE_AP);
27 		break;
28 	case QLINK_IFTYPE_STATION:
29 		result |= BIT(NL80211_IFTYPE_STATION);
30 		break;
31 	case QLINK_IFTYPE_ADHOC:
32 		result |= BIT(NL80211_IFTYPE_ADHOC);
33 		break;
34 	case QLINK_IFTYPE_MONITOR:
35 		result |= BIT(NL80211_IFTYPE_MONITOR);
36 		break;
37 	case QLINK_IFTYPE_WDS:
38 		result |= BIT(NL80211_IFTYPE_WDS);
39 		break;
40 	case QLINK_IFTYPE_AP_VLAN:
41 		result |= BIT(NL80211_IFTYPE_AP_VLAN);
42 		break;
43 	}
44 
45 	return result;
46 }
47 
48 u8 qlink_chan_width_mask_to_nl(u16 qlink_mask)
49 {
50 	u8 result = 0;
51 
52 	if (qlink_mask & QLINK_CHAN_WIDTH_5)
53 		result |= BIT(NL80211_CHAN_WIDTH_5);
54 
55 	if (qlink_mask & QLINK_CHAN_WIDTH_10)
56 		result |= BIT(NL80211_CHAN_WIDTH_10);
57 
58 	if (qlink_mask & QLINK_CHAN_WIDTH_20_NOHT)
59 		result |= BIT(NL80211_CHAN_WIDTH_20_NOHT);
60 
61 	if (qlink_mask & QLINK_CHAN_WIDTH_20)
62 		result |= BIT(NL80211_CHAN_WIDTH_20);
63 
64 	if (qlink_mask & QLINK_CHAN_WIDTH_40)
65 		result |= BIT(NL80211_CHAN_WIDTH_40);
66 
67 	if (qlink_mask & QLINK_CHAN_WIDTH_80)
68 		result |= BIT(NL80211_CHAN_WIDTH_80);
69 
70 	if (qlink_mask & QLINK_CHAN_WIDTH_80P80)
71 		result |= BIT(NL80211_CHAN_WIDTH_80P80);
72 
73 	if (qlink_mask & QLINK_CHAN_WIDTH_160)
74 		result |= BIT(NL80211_CHAN_WIDTH_160);
75 
76 	return result;
77 }
78