This source file includes following definitions.
- uwb_radio_select_channel
- uwb_radio_channel_changed
- uwb_radio_change_channel
- uwb_radio_start
- uwb_radio_stop
- uwb_radio_force_channel
- uwb_radio_setup
- uwb_radio_reset_state
- uwb_radio_shutdown
1
2
3
4
5
6
7 #include <linux/kernel.h>
8 #include <linux/export.h>
9
10 #include "uwb.h"
11 #include "uwb-internal.h"
12
13
14 static int uwb_radio_select_channel(struct uwb_rc *rc)
15 {
16
17
18
19
20 if (rc->active_pals == 0)
21 return -1;
22 if (rc->beaconing_forced)
23 return rc->beaconing_forced;
24 return 9;
25 }
26
27
28
29
30
31 static void uwb_radio_channel_changed(struct uwb_rc *rc, int channel)
32 {
33 struct uwb_pal *pal;
34
35 list_for_each_entry(pal, &rc->pals, node) {
36 if (pal->channel && channel != pal->channel) {
37 pal->channel = channel;
38 if (pal->channel_changed)
39 pal->channel_changed(pal, pal->channel);
40 }
41 }
42 }
43
44
45
46
47
48
49
50
51 static int uwb_radio_change_channel(struct uwb_rc *rc, int channel)
52 {
53 int ret = 0;
54 struct device *dev = &rc->uwb_dev.dev;
55
56 dev_dbg(dev, "%s: channel = %d, rc->beaconing = %d\n", __func__,
57 channel, rc->beaconing);
58
59 if (channel == -1)
60 uwb_radio_channel_changed(rc, channel);
61
62 if (channel != rc->beaconing) {
63 if (rc->beaconing != -1 && channel != -1) {
64
65
66
67
68 ret = uwb_radio_change_channel(rc, -1);
69 if (ret < 0)
70 return ret;
71 }
72 ret = uwb_rc_beacon(rc, channel, 0);
73 }
74
75 if (channel != -1)
76 uwb_radio_channel_changed(rc, rc->beaconing);
77
78 return ret;
79 }
80
81
82
83
84
85
86
87
88 int uwb_radio_start(struct uwb_pal *pal)
89 {
90 struct uwb_rc *rc = pal->rc;
91 int ret = 0;
92
93 mutex_lock(&rc->uwb_dev.mutex);
94
95 if (!pal->channel) {
96 pal->channel = -1;
97 rc->active_pals++;
98 ret = uwb_radio_change_channel(rc, uwb_radio_select_channel(rc));
99 }
100
101 mutex_unlock(&rc->uwb_dev.mutex);
102 return ret;
103 }
104 EXPORT_SYMBOL_GPL(uwb_radio_start);
105
106
107
108
109
110
111
112 void uwb_radio_stop(struct uwb_pal *pal)
113 {
114 struct uwb_rc *rc = pal->rc;
115
116 mutex_lock(&rc->uwb_dev.mutex);
117
118 if (pal->channel) {
119 rc->active_pals--;
120 uwb_radio_change_channel(rc, uwb_radio_select_channel(rc));
121 pal->channel = 0;
122 }
123
124 mutex_unlock(&rc->uwb_dev.mutex);
125 }
126 EXPORT_SYMBOL_GPL(uwb_radio_stop);
127
128
129
130
131
132
133
134 int uwb_radio_force_channel(struct uwb_rc *rc, int channel)
135 {
136 int ret = 0;
137
138 mutex_lock(&rc->uwb_dev.mutex);
139
140 rc->beaconing_forced = channel;
141 ret = uwb_radio_change_channel(rc, uwb_radio_select_channel(rc));
142
143 mutex_unlock(&rc->uwb_dev.mutex);
144 return ret;
145 }
146
147
148
149
150
151
152
153
154 int uwb_radio_setup(struct uwb_rc *rc)
155 {
156 return uwb_rc_reset(rc);
157 }
158
159
160
161
162
163
164
165
166 void uwb_radio_reset_state(struct uwb_rc *rc)
167 {
168 struct uwb_pal *pal;
169
170 mutex_lock(&rc->uwb_dev.mutex);
171
172 list_for_each_entry(pal, &rc->pals, node) {
173 if (pal->channel) {
174 pal->channel = -1;
175 if (pal->channel_changed)
176 pal->channel_changed(pal, -1);
177 }
178 }
179
180 rc->beaconing = -1;
181 rc->scanning = -1;
182
183 mutex_unlock(&rc->uwb_dev.mutex);
184 }
185
186
187
188
189
190
191
192 void uwb_radio_shutdown(struct uwb_rc *rc)
193 {
194 uwb_radio_reset_state(rc);
195 uwb_rc_reset(rc);
196 }