[59fa7ab] | 1 | /*
|
---|
| 2 | * Copyright (c) 2015 Jan Kolarik
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup libdrv
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file
|
---|
| 34 | * @brief Driver-side RPC skeletons for IEEE 802.11 interface
|
---|
| 35 | */
|
---|
| 36 |
|
---|
| 37 | #include <errno.h>
|
---|
| 38 | #include <macros.h>
|
---|
| 39 | #include <str.h>
|
---|
| 40 |
|
---|
| 41 | #include "ops/ieee80211.h"
|
---|
| 42 | #include "ieee80211_iface.h"
|
---|
| 43 |
|
---|
| 44 | #define MAX_STRING_SIZE 32
|
---|
| 45 |
|
---|
| 46 | /** IEEE 802.11 RPC functions IDs. */
|
---|
| 47 | typedef enum {
|
---|
| 48 | IEEE80211_GET_SCAN_RESULTS,
|
---|
[1dcc0b9] | 49 | IEEE80211_CONNECT,
|
---|
| 50 | IEEE80211_DISCONNECT
|
---|
[59fa7ab] | 51 | } ieee80211_funcs_t;
|
---|
| 52 |
|
---|
| 53 | /** Get scan results from IEEE 802.11 device
|
---|
| 54 | *
|
---|
| 55 | * @param[in] dev_sess Device session.
|
---|
| 56 | * @param[out] results Structure where to put scan results.
|
---|
| 57 | *
|
---|
| 58 | * @return EOK If the operation was successfully completed,
|
---|
| 59 | * negative error code otherwise.
|
---|
| 60 | */
|
---|
| 61 | int ieee80211_get_scan_results(async_sess_t *dev_sess,
|
---|
[1dcc0b9] | 62 | ieee80211_scan_results_t *results, bool now)
|
---|
[59fa7ab] | 63 | {
|
---|
| 64 | assert(results);
|
---|
| 65 |
|
---|
| 66 | async_exch_t *exch = async_exchange_begin(dev_sess);
|
---|
| 67 |
|
---|
[1dcc0b9] | 68 | aid_t aid = async_send_2(exch, DEV_IFACE_ID(IEEE80211_DEV_IFACE),
|
---|
| 69 | IEEE80211_GET_SCAN_RESULTS, now, NULL);
|
---|
[59fa7ab] | 70 | int rc = async_data_read_start(exch, results, sizeof(ieee80211_scan_results_t));
|
---|
| 71 | async_exchange_end(exch);
|
---|
| 72 |
|
---|
| 73 | sysarg_t res;
|
---|
| 74 | async_wait_for(aid, &res);
|
---|
| 75 |
|
---|
[1dcc0b9] | 76 | if(res != EOK)
|
---|
| 77 | return (int) res;
|
---|
| 78 | else
|
---|
[59fa7ab] | 79 | return rc;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | /** Connect to specified network.
|
---|
| 83 | *
|
---|
| 84 | * @param[in] dev_sess Device session.
|
---|
[1dcc0b9] | 85 | * @param[in] ssid_start Network SSID prefix.
|
---|
[59fa7ab] | 86 | * @param[in] password Network password (pass empty string if not needed).
|
---|
| 87 | *
|
---|
| 88 | * @return EOK If the operation was successfully completed,
|
---|
| 89 | * negative error code otherwise.
|
---|
| 90 | */
|
---|
[1dcc0b9] | 91 | int ieee80211_connect(async_sess_t *dev_sess, char *ssid_start, char *password)
|
---|
[59fa7ab] | 92 | {
|
---|
[1dcc0b9] | 93 | assert(ssid_start);
|
---|
[59fa7ab] | 94 |
|
---|
| 95 | sysarg_t rc_orig;
|
---|
| 96 |
|
---|
| 97 | async_exch_t *exch = async_exchange_begin(dev_sess);
|
---|
| 98 |
|
---|
| 99 | aid_t aid = async_send_1(exch, DEV_IFACE_ID(IEEE80211_DEV_IFACE),
|
---|
| 100 | IEEE80211_CONNECT, NULL);
|
---|
| 101 |
|
---|
[1dcc0b9] | 102 | sysarg_t rc = async_data_write_start(exch, ssid_start,
|
---|
| 103 | str_size(ssid_start) + 1);
|
---|
[59fa7ab] | 104 | if (rc != EOK) {
|
---|
| 105 | async_exchange_end(exch);
|
---|
| 106 | async_wait_for(aid, &rc_orig);
|
---|
| 107 |
|
---|
| 108 | if (rc_orig == EOK)
|
---|
| 109 | return (int) rc;
|
---|
| 110 | else
|
---|
| 111 | return (int) rc_orig;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | if(password == NULL) {
|
---|
| 115 | password = (char *) "";
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | rc = async_data_write_start(exch, password, str_size(password) + 1);
|
---|
| 119 | if (rc != EOK) {
|
---|
| 120 | async_exchange_end(exch);
|
---|
| 121 | async_wait_for(aid, &rc_orig);
|
---|
| 122 |
|
---|
| 123 | if (rc_orig == EOK)
|
---|
| 124 | return (int) rc;
|
---|
| 125 | else
|
---|
| 126 | return (int) rc_orig;
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | async_exchange_end(exch);
|
---|
| 130 |
|
---|
| 131 | async_wait_for(aid, &rc);
|
---|
| 132 |
|
---|
| 133 | return (int) rc;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
[1dcc0b9] | 136 | /** Disconnect device from network.
|
---|
| 137 | *
|
---|
| 138 | * @param[in] dev_sess Device session.
|
---|
| 139 | *
|
---|
| 140 | * @return EOK If the operation was successfully completed,
|
---|
| 141 | * negative error code otherwise.
|
---|
| 142 | */
|
---|
| 143 | int ieee80211_disconnect(async_sess_t *dev_sess)
|
---|
| 144 | {
|
---|
| 145 | async_exch_t *exch = async_exchange_begin(dev_sess);
|
---|
| 146 | int rc = async_req_1_0(exch, DEV_IFACE_ID(IEEE80211_DEV_IFACE),
|
---|
| 147 | IEEE80211_DISCONNECT);
|
---|
| 148 | async_exchange_end(exch);
|
---|
| 149 |
|
---|
| 150 | return rc;
|
---|
| 151 | }
|
---|
| 152 |
|
---|
[59fa7ab] | 153 | static void remote_ieee80211_get_scan_results(ddf_fun_t *fun, void *iface,
|
---|
| 154 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 155 | {
|
---|
| 156 | ieee80211_iface_t *ieee80211_iface = (ieee80211_iface_t *) iface;
|
---|
| 157 | assert(ieee80211_iface->get_scan_results);
|
---|
| 158 |
|
---|
| 159 | ieee80211_scan_results_t scan_results;
|
---|
| 160 | memset(&scan_results, 0, sizeof(ieee80211_scan_results_t));
|
---|
| 161 |
|
---|
[1dcc0b9] | 162 | bool now = IPC_GET_ARG2(*call);
|
---|
| 163 |
|
---|
| 164 | int rc = ieee80211_iface->get_scan_results(fun, &scan_results, now);
|
---|
[59fa7ab] | 165 | if (rc == EOK) {
|
---|
| 166 | ipc_callid_t data_callid;
|
---|
| 167 | size_t max_len;
|
---|
| 168 | if (!async_data_read_receive(&data_callid, &max_len)) {
|
---|
| 169 | async_answer_0(data_callid, EINVAL);
|
---|
| 170 | async_answer_0(callid, EINVAL);
|
---|
| 171 | return;
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | if (max_len < sizeof(ieee80211_scan_results_t)) {
|
---|
| 175 | async_answer_0(data_callid, ELIMIT);
|
---|
| 176 | async_answer_0(callid, ELIMIT);
|
---|
| 177 | return;
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | async_data_read_finalize(data_callid, &scan_results,
|
---|
| 181 | sizeof(ieee80211_scan_results_t));
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | async_answer_0(callid, rc);
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | static void remote_ieee80211_connect(ddf_fun_t *fun, void *iface,
|
---|
| 188 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 189 | {
|
---|
| 190 | ieee80211_iface_t *ieee80211_iface = (ieee80211_iface_t *) iface;
|
---|
| 191 | assert(ieee80211_iface->connect);
|
---|
| 192 |
|
---|
[1dcc0b9] | 193 | char ssid_start[MAX_STRING_SIZE];
|
---|
[59fa7ab] | 194 | char password[MAX_STRING_SIZE];
|
---|
| 195 |
|
---|
| 196 | ipc_callid_t data_callid;
|
---|
| 197 | size_t len;
|
---|
| 198 | if (!async_data_write_receive(&data_callid, &len)) {
|
---|
| 199 | async_answer_0(data_callid, EINVAL);
|
---|
| 200 | async_answer_0(callid, EINVAL);
|
---|
| 201 | return;
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | if (len > MAX_STRING_SIZE) {
|
---|
| 205 | async_answer_0(data_callid, EINVAL);
|
---|
| 206 | async_answer_0(callid, EINVAL);
|
---|
| 207 | return;
|
---|
| 208 | }
|
---|
| 209 |
|
---|
[1dcc0b9] | 210 | int rc = async_data_write_finalize(data_callid, ssid_start, len);
|
---|
[59fa7ab] | 211 | if (rc != EOK) {
|
---|
| 212 | async_answer_0(data_callid, EINVAL);
|
---|
| 213 | async_answer_0(callid, EINVAL);
|
---|
| 214 | return;
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | if (!async_data_write_receive(&data_callid, &len)) {
|
---|
| 218 | async_answer_0(data_callid, EINVAL);
|
---|
| 219 | async_answer_0(callid, EINVAL);
|
---|
| 220 | return;
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | if (len > MAX_STRING_SIZE) {
|
---|
| 224 | async_answer_0(data_callid, EINVAL);
|
---|
| 225 | async_answer_0(callid, EINVAL);
|
---|
| 226 | return;
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | rc = async_data_write_finalize(data_callid, password, len);
|
---|
| 230 | if (rc != EOK) {
|
---|
| 231 | async_answer_0(data_callid, EINVAL);
|
---|
| 232 | async_answer_0(callid, EINVAL);
|
---|
| 233 | return;
|
---|
| 234 | }
|
---|
| 235 |
|
---|
[1dcc0b9] | 236 | rc = ieee80211_iface->connect(fun, ssid_start, password);
|
---|
[59fa7ab] | 237 |
|
---|
| 238 | async_answer_0(callid, rc);
|
---|
| 239 | }
|
---|
| 240 |
|
---|
[1dcc0b9] | 241 | static void remote_ieee80211_disconnect(ddf_fun_t *fun, void *iface,
|
---|
| 242 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 243 | {
|
---|
| 244 | ieee80211_iface_t *ieee80211_iface = (ieee80211_iface_t *) iface;
|
---|
| 245 | assert(ieee80211_iface->disconnect);
|
---|
| 246 | int rc = ieee80211_iface->disconnect(fun);
|
---|
| 247 | async_answer_0(callid, rc);
|
---|
| 248 | }
|
---|
| 249 |
|
---|
[59fa7ab] | 250 | /** Remote IEEE 802.11 interface operations.
|
---|
| 251 | *
|
---|
| 252 | */
|
---|
| 253 | static const remote_iface_func_ptr_t remote_ieee80211_iface_ops[] = {
|
---|
| 254 | [IEEE80211_GET_SCAN_RESULTS] = remote_ieee80211_get_scan_results,
|
---|
[1dcc0b9] | 255 | [IEEE80211_CONNECT] = remote_ieee80211_connect,
|
---|
| 256 | [IEEE80211_DISCONNECT] = remote_ieee80211_disconnect
|
---|
[59fa7ab] | 257 | };
|
---|
| 258 |
|
---|
| 259 | /** Remote IEEE 802.11 interface structure.
|
---|
| 260 | *
|
---|
| 261 | * Interface for processing request from remote
|
---|
| 262 | * clients addressed to the IEEE 802.11 interface.
|
---|
| 263 | *
|
---|
| 264 | */
|
---|
| 265 | const remote_iface_t remote_ieee80211_iface = {
|
---|
| 266 | .method_count = ARRAY_SIZE(remote_ieee80211_iface_ops),
|
---|
| 267 | .methods = remote_ieee80211_iface_ops
|
---|
| 268 | };
|
---|
| 269 |
|
---|
| 270 | /**
|
---|
| 271 | * @}
|
---|
| 272 | */
|
---|