2 * UWB radio (channel) management.
4 * Copyright (C) 2008 Cambridge Silicon Radio Ltd.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include <linux/kernel.h>
19 #include <linux/uwb.h>
20 #include <linux/export.h>
22 #include "uwb-internal.h"
25 static int uwb_radio_select_channel(struct uwb_rc
*rc
)
28 * Default to channel 9 (BG1, TFC1) unless the user has
29 * selected a specific channel or there are no active PALs.
31 if (rc
->active_pals
== 0)
33 if (rc
->beaconing_forced
)
34 return rc
->beaconing_forced
;
40 * Notify all active PALs that the channel has changed.
42 static void uwb_radio_channel_changed(struct uwb_rc
*rc
, int channel
)
46 list_for_each_entry(pal
, &rc
->pals
, node
) {
47 if (pal
->channel
&& channel
!= pal
->channel
) {
48 pal
->channel
= channel
;
49 if (pal
->channel_changed
)
50 pal
->channel_changed(pal
, pal
->channel
);
56 * Change to a new channel and notify any active PALs of the new
59 * When stopping the radio, PALs need to be notified first so they can
60 * terminate any active reservations.
62 static int uwb_radio_change_channel(struct uwb_rc
*rc
, int channel
)
67 uwb_radio_channel_changed(rc
, channel
);
69 if (channel
!= rc
->beaconing
) {
70 if (rc
->beaconing
!= -1 && channel
!= -1) {
72 * FIXME: should signal the channel change
73 * with a Channel Change IE.
75 ret
= uwb_radio_change_channel(rc
, -1);
79 ret
= uwb_rc_beacon(rc
, channel
, 0);
83 uwb_radio_channel_changed(rc
, rc
->beaconing
);
89 * uwb_radio_start - request that the radio be started
90 * @pal: the PAL making the request.
92 * If the radio is not already active, aa suitable channel is selected
93 * and beacons are started.
95 int uwb_radio_start(struct uwb_pal
*pal
)
97 struct uwb_rc
*rc
= pal
->rc
;
100 mutex_lock(&rc
->uwb_dev
.mutex
);
105 ret
= uwb_radio_change_channel(rc
, uwb_radio_select_channel(rc
));
108 mutex_unlock(&rc
->uwb_dev
.mutex
);
111 EXPORT_SYMBOL_GPL(uwb_radio_start
);
114 * uwb_radio_stop - request tha the radio be stopped.
115 * @pal: the PAL making the request.
117 * Stops the radio if no other PAL is making use of it.
119 void uwb_radio_stop(struct uwb_pal
*pal
)
121 struct uwb_rc
*rc
= pal
->rc
;
123 mutex_lock(&rc
->uwb_dev
.mutex
);
127 uwb_radio_change_channel(rc
, uwb_radio_select_channel(rc
));
131 mutex_unlock(&rc
->uwb_dev
.mutex
);
133 EXPORT_SYMBOL_GPL(uwb_radio_stop
);
136 * uwb_radio_force_channel - force a specific channel to be used
137 * @rc: the radio controller.
138 * @channel: the channel to use; -1 to force the radio to stop; 0 to
139 * use the default channel selection algorithm.
141 int uwb_radio_force_channel(struct uwb_rc
*rc
, int channel
)
145 mutex_lock(&rc
->uwb_dev
.mutex
);
147 rc
->beaconing_forced
= channel
;
148 ret
= uwb_radio_change_channel(rc
, uwb_radio_select_channel(rc
));
150 mutex_unlock(&rc
->uwb_dev
.mutex
);
155 * uwb_radio_setup - setup the radio manager
156 * @rc: the radio controller.
158 * The radio controller is reset to ensure it's in a known state
161 int uwb_radio_setup(struct uwb_rc
*rc
)
163 return uwb_rc_reset(rc
);
167 * uwb_radio_reset_state - reset any radio manager state
168 * @rc: the radio controller.
170 * All internal radio manager state is reset to values corresponding
171 * to a reset radio controller.
173 void uwb_radio_reset_state(struct uwb_rc
*rc
)
177 mutex_lock(&rc
->uwb_dev
.mutex
);
179 list_for_each_entry(pal
, &rc
->pals
, node
) {
182 if (pal
->channel_changed
)
183 pal
->channel_changed(pal
, -1);
190 mutex_unlock(&rc
->uwb_dev
.mutex
);
194 * uwb_radio_shutdown - shutdown the radio manager
195 * @rc: the radio controller.
197 * The radio controller is reset.
199 void uwb_radio_shutdown(struct uwb_rc
*rc
)
201 uwb_radio_reset_state(rc
);