[2ecb5ec] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Jan Vesely
|
---|
| 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 | */
|
---|
[acac2ef] | 28 | /** @addtogroup drvmouse
|
---|
[2ecb5ec] | 29 | * @{
|
---|
| 30 | */
|
---|
| 31 | /** @file
|
---|
[acac2ef] | 32 | * @brief ps2 mouse driver.
|
---|
[2ecb5ec] | 33 | */
|
---|
| 34 |
|
---|
[3e6a98c5] | 35 | #include <stdbool.h>
|
---|
[2ecb5ec] | 36 | #include <errno.h>
|
---|
| 37 | #include <ddf/log.h>
|
---|
| 38 | #include <io/keycode.h>
|
---|
| 39 | #include <io/console.h>
|
---|
| 40 | #include <ipc/mouseev.h>
|
---|
| 41 | #include <abi/ipc/methods.h>
|
---|
| 42 |
|
---|
| 43 | #include "ps2mouse.h"
|
---|
[a455321] | 44 | #include "chardev.h"
|
---|
[2ecb5ec] | 45 |
|
---|
[c637571] | 46 | #define PS2_MOUSE_GET_DEVICE_ID 0xf2
|
---|
| 47 | #define PS2_MOUSE_SET_SAMPLE_RATE 0xf3
|
---|
| 48 | #define PS2_MOUSE_ENABLE_DATA_REPORT 0xf4
|
---|
| 49 | #define PS2_MOUSE_ACK 0xfa
|
---|
[2ecb5ec] | 50 |
|
---|
[c637571] | 51 | #define PS2_BUFSIZE 3
|
---|
| 52 | #define INTELLIMOUSE_BUFSIZE 4
|
---|
[2ecb5ec] | 53 |
|
---|
[c322fd6] | 54 | #define Z_SIGN (1 << 3) /* 4th byte */
|
---|
| 55 | #define X_SIGN (1 << 4) /* 1st byte */
|
---|
| 56 | #define Y_SIGN (1 << 5) /* 1st byte */
|
---|
| 57 | #define X_OVERFLOW (1 << 6) /* 1st byte */
|
---|
| 58 | #define Y_OVERFLOW (1 << 7) /* 1st byte */
|
---|
[2ecb5ec] | 59 |
|
---|
| 60 | #define BUTTON_LEFT 0
|
---|
| 61 | #define BUTTON_RIGHT 1
|
---|
| 62 | #define BUTTON_MIDDLE 2
|
---|
[c637571] | 63 | #define PS2_BUTTON_COUNT 3
|
---|
[c322fd6] | 64 |
|
---|
| 65 | #define INTELLIMOUSE_ALWAYS_ZERO (0xc0)
|
---|
| 66 | #define INTELLIMOUSE_BUTTON_4 (1 << 4) /* 4th byte */
|
---|
| 67 | #define INTELLIMOUSE_BUTTON_5 (1 << 5) /* 4th byte */
|
---|
[c637571] | 68 | #define INTELLIMOUSE_BUTTON_COUNT 5
|
---|
[2ecb5ec] | 69 |
|
---|
[c637571] | 70 | #define PS2_BUTTON_MASK(button) (1 << button)
|
---|
[2ecb5ec] | 71 |
|
---|
[c637571] | 72 | #define MOUSE_READ_BYTE_TEST(sess, value) \
|
---|
| 73 | do { \
|
---|
| 74 | uint8_t data = 0; \
|
---|
[2f79a38] | 75 | const ssize_t size = chardev_read(sess, &data, 1); \
|
---|
[c637571] | 76 | if (size != 1) { \
|
---|
[f0a2720] | 77 | ddf_msg(LVL_ERROR, "Failed reading byte: %zd)", size);\
|
---|
[c637571] | 78 | return size < 0 ? size : EIO; \
|
---|
| 79 | } \
|
---|
[c322fd6] | 80 | if (data != (value)) { \
|
---|
[68c60b0] | 81 | ddf_msg(LVL_DEBUG, "Failed testing byte: got %hhx vs. %hhx)", \
|
---|
[c322fd6] | 82 | data, (value)); \
|
---|
[c637571] | 83 | return EIO; \
|
---|
| 84 | } \
|
---|
| 85 | } while (0)
|
---|
[a455321] | 86 |
|
---|
[c637571] | 87 | #define MOUSE_WRITE_BYTE(sess, value) \
|
---|
| 88 | do { \
|
---|
[c322fd6] | 89 | uint8_t data = (value); \
|
---|
[2f79a38] | 90 | const ssize_t size = chardev_write(sess, &data, 1); \
|
---|
[c637571] | 91 | if (size < 0 ) { \
|
---|
| 92 | ddf_msg(LVL_ERROR, "Failed writing byte: %hhx", value); \
|
---|
| 93 | return size; \
|
---|
| 94 | } \
|
---|
| 95 | } while (0)
|
---|
[8bb9540] | 96 |
|
---|
[2ecb5ec] | 97 | static int polling_ps2(void *);
|
---|
[c637571] | 98 | static int polling_intellimouse(void *);
|
---|
[2f79a38] | 99 | static int probe_intellimouse(async_exch_t *, bool);
|
---|
[acac2ef] | 100 | static void default_connection_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *);
|
---|
[8bb9540] | 101 |
|
---|
[acac2ef] | 102 | /** ps/2 mouse driver ops. */
|
---|
[2ecb5ec] | 103 | static ddf_dev_ops_t mouse_ops = {
|
---|
| 104 | .default_handler = default_connection_handler
|
---|
| 105 | };
|
---|
[8bb9540] | 106 |
|
---|
[acac2ef] | 107 | /** Initialize mouse driver structure.
|
---|
| 108 | * @param kbd Mouse driver structure to initialize.
|
---|
| 109 | * @param dev DDF device structure.
|
---|
| 110 | *
|
---|
| 111 | * Connects to parent, creates keyboard function, starts polling fibril.
|
---|
| 112 | */
|
---|
[2ecb5ec] | 113 | int ps2_mouse_init(ps2_mouse_t *mouse, ddf_dev_t *dev)
|
---|
| 114 | {
|
---|
[e98fe28c] | 115 | mouse->client_sess = NULL;
|
---|
[56fd7cf] | 116 | mouse->parent_sess = ddf_dev_parent_sess_create(dev, EXCHANGE_SERIALIZE);
|
---|
[2ecb5ec] | 117 | if (!mouse->parent_sess)
|
---|
| 118 | return ENOMEM;
|
---|
| 119 |
|
---|
| 120 | mouse->mouse_fun = ddf_fun_create(dev, fun_exposed, "mouse");
|
---|
| 121 | if (!mouse->mouse_fun) {
|
---|
| 122 | return ENOMEM;
|
---|
| 123 | }
|
---|
[56fd7cf] | 124 | ddf_fun_set_ops(mouse->mouse_fun, &mouse_ops);
|
---|
[2ecb5ec] | 125 |
|
---|
| 126 | int ret = ddf_fun_bind(mouse->mouse_fun);
|
---|
| 127 | if (ret != EOK) {
|
---|
| 128 | ddf_fun_destroy(mouse->mouse_fun);
|
---|
| 129 | return ENOMEM;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | ret = ddf_fun_add_to_category(mouse->mouse_fun, "mouse");
|
---|
| 133 | if (ret != EOK) {
|
---|
| 134 | ddf_fun_unbind(mouse->mouse_fun);
|
---|
| 135 | ddf_fun_destroy(mouse->mouse_fun);
|
---|
| 136 | return ENOMEM;
|
---|
| 137 | }
|
---|
[c637571] | 138 | /* Probe IntelliMouse extensions. */
|
---|
| 139 | int (*polling_f)(void*) = polling_ps2;
|
---|
[2f79a38] | 140 | async_exch_t *exch = async_exchange_begin(mouse->parent_sess);
|
---|
| 141 | if (probe_intellimouse(exch, false) == EOK) {
|
---|
[c637571] | 142 | ddf_msg(LVL_NOTE, "Enabled IntelliMouse extensions");
|
---|
| 143 | polling_f = polling_intellimouse;
|
---|
[2f79a38] | 144 | if (probe_intellimouse(exch, true) == EOK)
|
---|
[c322fd6] | 145 | ddf_msg(LVL_NOTE, "Enabled 4th and 5th button.");
|
---|
[c637571] | 146 | }
|
---|
[2ecb5ec] | 147 | /* Enable mouse data reporting. */
|
---|
[c637571] | 148 | uint8_t report = PS2_MOUSE_ENABLE_DATA_REPORT;
|
---|
[2f79a38] | 149 | ssize_t size = chardev_write(exch, &report, 1);
|
---|
[2ecb5ec] | 150 | if (size != 1) {
|
---|
[c637571] | 151 | ddf_msg(LVL_ERROR, "Failed to enable data reporting.");
|
---|
[2f79a38] | 152 | async_exchange_end(exch);
|
---|
[2ecb5ec] | 153 | ddf_fun_unbind(mouse->mouse_fun);
|
---|
| 154 | ddf_fun_destroy(mouse->mouse_fun);
|
---|
| 155 | return EIO;
|
---|
| 156 | }
|
---|
[d56ab85] | 157 |
|
---|
[2f79a38] | 158 | size = chardev_read(exch, &report, 1);
|
---|
| 159 | async_exchange_end(exch);
|
---|
[2ecb5ec] | 160 | if (size != 1 || report != PS2_MOUSE_ACK) {
|
---|
[c637571] | 161 | ddf_msg(LVL_ERROR, "Failed to confirm data reporting: %hhx.",
|
---|
| 162 | report);
|
---|
[2ecb5ec] | 163 | ddf_fun_unbind(mouse->mouse_fun);
|
---|
| 164 | ddf_fun_destroy(mouse->mouse_fun);
|
---|
| 165 | return EIO;
|
---|
| 166 | }
|
---|
| 167 |
|
---|
[c637571] | 168 | mouse->polling_fibril = fibril_create(polling_f, mouse);
|
---|
[2ecb5ec] | 169 | if (!mouse->polling_fibril) {
|
---|
| 170 | ddf_fun_unbind(mouse->mouse_fun);
|
---|
| 171 | ddf_fun_destroy(mouse->mouse_fun);
|
---|
| 172 | return ENOMEM;
|
---|
| 173 | }
|
---|
| 174 | fibril_add_ready(mouse->polling_fibril);
|
---|
| 175 | return EOK;
|
---|
| 176 | }
|
---|
[8bb9540] | 177 |
|
---|
[acac2ef] | 178 | /** Get data and parse ps2 protocol packets.
|
---|
| 179 | * @param arg Pointer to ps2_mouse_t structure.
|
---|
| 180 | * @return Never.
|
---|
| 181 | */
|
---|
[2ecb5ec] | 182 | int polling_ps2(void *arg)
|
---|
| 183 | {
|
---|
| 184 | assert(arg);
|
---|
[acac2ef] | 185 | const ps2_mouse_t *mouse = arg;
|
---|
[2ecb5ec] | 186 |
|
---|
| 187 | assert(mouse->parent_sess);
|
---|
[c637571] | 188 | bool buttons[PS2_BUTTON_COUNT] = {};
|
---|
[2f79a38] | 189 | async_exch_t *parent_exch = async_exchange_begin(mouse->parent_sess);
|
---|
[2ecb5ec] | 190 | while (1) {
|
---|
| 191 |
|
---|
[c637571] | 192 | uint8_t packet[PS2_BUFSIZE] = {};
|
---|
[2ecb5ec] | 193 | const ssize_t size =
|
---|
[2f79a38] | 194 | chardev_read(parent_exch, packet, PS2_BUFSIZE);
|
---|
[2ecb5ec] | 195 |
|
---|
[c637571] | 196 | if (size != PS2_BUFSIZE) {
|
---|
[2ecb5ec] | 197 | ddf_msg(LVL_WARN, "Incorrect packet size: %zd.", size);
|
---|
| 198 | continue;
|
---|
| 199 | }
|
---|
| 200 | ddf_msg(LVL_DEBUG2, "Got packet: %hhx:%hhx:%hhx.",
|
---|
| 201 | packet[0], packet[1], packet[2]);
|
---|
| 202 |
|
---|
| 203 | async_exch_t *exch =
|
---|
[e98fe28c] | 204 | async_exchange_begin(mouse->client_sess);
|
---|
[2ecb5ec] | 205 | if (!exch) {
|
---|
| 206 | ddf_msg(LVL_ERROR,
|
---|
[e98fe28c] | 207 | "Failed creating exchange.");
|
---|
[2ecb5ec] | 208 | continue;
|
---|
| 209 | }
|
---|
[db9ef0c] | 210 |
|
---|
[2ecb5ec] | 211 | /* Buttons */
|
---|
[c637571] | 212 | for (unsigned i = 0; i < PS2_BUTTON_COUNT; ++i) {
|
---|
| 213 | const bool status = (packet[0] & PS2_BUTTON_MASK(i));
|
---|
| 214 | if (buttons[i] != status) {
|
---|
| 215 | buttons[i] = status;
|
---|
[2ecb5ec] | 216 | async_msg_2(exch, MOUSEEV_BUTTON_EVENT, i + 1,
|
---|
| 217 | buttons[i]);
|
---|
| 218 | }
|
---|
| 219 | }
|
---|
[db9ef0c] | 220 |
|
---|
[ec3b125] | 221 | /* Movement */
|
---|
[db9ef0c] | 222 | const int16_t move_x =
|
---|
| 223 | ((packet[0] & X_SIGN) ? 0xff00 : 0) | packet[1];
|
---|
| 224 | const int16_t move_y =
|
---|
| 225 | (((packet[0] & Y_SIGN) ? 0xff00 : 0) | packet[2]);
|
---|
| 226 | //TODO: Consider overflow bit
|
---|
[2ecb5ec] | 227 | if (move_x != 0 || move_y != 0) {
|
---|
[db9ef0c] | 228 | async_msg_2(exch, MOUSEEV_MOVE_EVENT, move_x, -move_y);
|
---|
[2ecb5ec] | 229 | }
|
---|
| 230 | async_exchange_end(exch);
|
---|
| 231 | }
|
---|
[2f79a38] | 232 | async_exchange_end(parent_exch);
|
---|
[2ecb5ec] | 233 | }
|
---|
[8bb9540] | 234 |
|
---|
[c322fd6] | 235 | /** Get data and parse ps2 protocol with IntelliMouse extension packets.
|
---|
[c637571] | 236 | * @param arg Pointer to ps2_mouse_t structure.
|
---|
| 237 | * @return Never.
|
---|
| 238 | */
|
---|
| 239 | static int polling_intellimouse(void *arg)
|
---|
| 240 | {
|
---|
| 241 | assert(arg);
|
---|
| 242 | const ps2_mouse_t *mouse = arg;
|
---|
| 243 |
|
---|
| 244 | assert(mouse->parent_sess);
|
---|
| 245 | bool buttons[INTELLIMOUSE_BUTTON_COUNT] = {};
|
---|
[2f79a38] | 246 | async_exch_t *parent_exch = NULL;
|
---|
[c637571] | 247 | while (1) {
|
---|
[2f79a38] | 248 | if (!parent_exch)
|
---|
| 249 | parent_exch = async_exchange_begin(mouse->parent_sess);
|
---|
[c637571] | 250 |
|
---|
| 251 | uint8_t packet[INTELLIMOUSE_BUFSIZE] = {};
|
---|
[a455321] | 252 | const ssize_t size = chardev_read(
|
---|
[2f79a38] | 253 | parent_exch, packet, INTELLIMOUSE_BUFSIZE);
|
---|
[c637571] | 254 |
|
---|
| 255 | if (size != INTELLIMOUSE_BUFSIZE) {
|
---|
| 256 | ddf_msg(LVL_WARN, "Incorrect packet size: %zd.", size);
|
---|
| 257 | continue;
|
---|
| 258 | }
|
---|
| 259 | ddf_msg(LVL_DEBUG2, "Got packet: %hhx:%hhx:%hhx:%hhx.",
|
---|
| 260 | packet[0], packet[1], packet[2], packet[3]);
|
---|
| 261 |
|
---|
| 262 | async_exch_t *exch =
|
---|
[e98fe28c] | 263 | async_exchange_begin(mouse->client_sess);
|
---|
[c637571] | 264 | if (!exch) {
|
---|
| 265 | ddf_msg(LVL_ERROR,
|
---|
[e98fe28c] | 266 | "Failed creating exchange.");
|
---|
[c637571] | 267 | continue;
|
---|
| 268 | }
|
---|
[c322fd6] | 269 |
|
---|
| 270 | /* Buttons */
|
---|
| 271 | /* NOTE: Parsing 4th and 5th button works even if this extension
|
---|
| 272 | * is not supported and whole 4th byte should be interpreted
|
---|
| 273 | * as Z-axis movement. the upper 4 bits are just a sign
|
---|
| 274 | * extension then. + sign is interpreted as "button up"
|
---|
| 275 | * (i.e no change since that is the default) and - sign fails
|
---|
| 276 | * the "imb" condition. Thus 4th and 5th buttons are never
|
---|
| 277 | * down on wheel only extension. */
|
---|
| 278 | const bool imb = (packet[3] & INTELLIMOUSE_ALWAYS_ZERO) == 0;
|
---|
| 279 | const bool status[] = {
|
---|
| 280 | [0] = packet[0] & PS2_BUTTON_MASK(0),
|
---|
| 281 | [1] = packet[0] & PS2_BUTTON_MASK(1),
|
---|
| 282 | [2] = packet[0] & PS2_BUTTON_MASK(2),
|
---|
| 283 | [3] = (packet[3] & INTELLIMOUSE_BUTTON_4) && imb,
|
---|
| 284 | [4] = (packet[3] & INTELLIMOUSE_BUTTON_5) && imb,
|
---|
| 285 | };
|
---|
| 286 | for (unsigned i = 0; i < INTELLIMOUSE_BUTTON_COUNT; ++i) {
|
---|
| 287 | if (buttons[i] != status[i]) {
|
---|
| 288 | buttons[i] = status[i];
|
---|
[c637571] | 289 | async_msg_2(exch, MOUSEEV_BUTTON_EVENT, i + 1,
|
---|
| 290 | buttons[i]);
|
---|
| 291 | }
|
---|
| 292 | }
|
---|
| 293 |
|
---|
| 294 | /* Movement */
|
---|
| 295 | const int16_t move_x =
|
---|
| 296 | ((packet[0] & X_SIGN) ? 0xff00 : 0) | packet[1];
|
---|
| 297 | const int16_t move_y =
|
---|
| 298 | (((packet[0] & Y_SIGN) ? 0xff00 : 0) | packet[2]);
|
---|
| 299 | const int8_t move_z =
|
---|
| 300 | (((packet[3] & Z_SIGN) ? 0xf0 : 0) | (packet[3] & 0xf));
|
---|
| 301 | ddf_msg(LVL_DEBUG2, "Parsed moves: %d:%d:%hhd", move_x, move_y,
|
---|
| 302 | move_z);
|
---|
| 303 | //TODO: Consider overflow bit
|
---|
| 304 | if (move_x != 0 || move_y != 0 || move_z != 0) {
|
---|
| 305 | async_msg_3(exch, MOUSEEV_MOVE_EVENT,
|
---|
| 306 | move_x, -move_y, -move_z);
|
---|
| 307 | }
|
---|
| 308 | async_exchange_end(exch);
|
---|
| 309 | }
|
---|
[2f79a38] | 310 | async_exchange_end(parent_exch);
|
---|
[c637571] | 311 | }
|
---|
[8bb9540] | 312 |
|
---|
[c322fd6] | 313 | /** Send magic sequence to initialize IntelliMouse extensions.
|
---|
[2f79a38] | 314 | * @param exch IPC exchange to the parent device.
|
---|
[c322fd6] | 315 | * @param buttons True selects magic sequence for 4th and 5th button,
|
---|
| 316 | * false selects wheel support magic sequence.
|
---|
| 317 | * See http://www.computer-engineering.org/ps2mouse/ for details.
|
---|
| 318 | */
|
---|
[2f79a38] | 319 | static int probe_intellimouse(async_exch_t *exch, bool buttons)
|
---|
[c637571] | 320 | {
|
---|
[2f79a38] | 321 | assert(exch);
|
---|
| 322 |
|
---|
| 323 | MOUSE_WRITE_BYTE(exch, PS2_MOUSE_SET_SAMPLE_RATE);
|
---|
| 324 | MOUSE_READ_BYTE_TEST(exch, PS2_MOUSE_ACK);
|
---|
| 325 | MOUSE_WRITE_BYTE(exch, 200);
|
---|
| 326 | MOUSE_READ_BYTE_TEST(exch, PS2_MOUSE_ACK);
|
---|
| 327 |
|
---|
| 328 | MOUSE_WRITE_BYTE(exch, PS2_MOUSE_SET_SAMPLE_RATE);
|
---|
| 329 | MOUSE_READ_BYTE_TEST(exch, PS2_MOUSE_ACK);
|
---|
| 330 | MOUSE_WRITE_BYTE(exch, buttons ? 200 : 100);
|
---|
| 331 | MOUSE_READ_BYTE_TEST(exch, PS2_MOUSE_ACK);
|
---|
| 332 |
|
---|
| 333 | MOUSE_WRITE_BYTE(exch, PS2_MOUSE_SET_SAMPLE_RATE);
|
---|
| 334 | MOUSE_READ_BYTE_TEST(exch, PS2_MOUSE_ACK);
|
---|
| 335 | MOUSE_WRITE_BYTE(exch, 80);
|
---|
| 336 | MOUSE_READ_BYTE_TEST(exch, PS2_MOUSE_ACK);
|
---|
| 337 |
|
---|
| 338 | MOUSE_WRITE_BYTE(exch, PS2_MOUSE_GET_DEVICE_ID);
|
---|
| 339 | MOUSE_READ_BYTE_TEST(exch, PS2_MOUSE_ACK);
|
---|
| 340 | MOUSE_READ_BYTE_TEST(exch, buttons ? 4 : 3);
|
---|
[c637571] | 341 |
|
---|
| 342 | return EOK;
|
---|
| 343 | }
|
---|
[8bb9540] | 344 |
|
---|
[acac2ef] | 345 | /** Default handler for IPC methods not handled by DDF.
|
---|
| 346 | *
|
---|
| 347 | * @param fun Device function handling the call.
|
---|
| 348 | * @param icallid Call id.
|
---|
| 349 | * @param icall Call data.
|
---|
| 350 | */
|
---|
[2ecb5ec] | 351 | void default_connection_handler(ddf_fun_t *fun,
|
---|
| 352 | ipc_callid_t icallid, ipc_call_t *icall)
|
---|
| 353 | {
|
---|
| 354 | const sysarg_t method = IPC_GET_IMETHOD(*icall);
|
---|
[56fd7cf] | 355 | ps2_mouse_t *mouse = ddf_dev_data_get(ddf_fun_get_dev(fun));
|
---|
[2ecb5ec] | 356 |
|
---|
| 357 | switch (method) {
|
---|
| 358 | /* This might be ugly but async_callback_receive_start makes no
|
---|
| 359 | * difference for incorrect call and malloc failure. */
|
---|
| 360 | case IPC_M_CONNECT_TO_ME: {
|
---|
| 361 | async_sess_t *sess =
|
---|
| 362 | async_callback_receive_start(EXCHANGE_SERIALIZE, icall);
|
---|
| 363 | /* Probably ENOMEM error, try again. */
|
---|
| 364 | if (sess == NULL) {
|
---|
| 365 | ddf_msg(LVL_WARN,
|
---|
[e98fe28c] | 366 | "Failed creating client callback session");
|
---|
[2ecb5ec] | 367 | async_answer_0(icallid, EAGAIN);
|
---|
| 368 | break;
|
---|
| 369 | }
|
---|
[e98fe28c] | 370 | if (mouse->client_sess == NULL) {
|
---|
| 371 | mouse->client_sess = sess;
|
---|
| 372 | ddf_msg(LVL_DEBUG, "Set client session");
|
---|
[2ecb5ec] | 373 | async_answer_0(icallid, EOK);
|
---|
| 374 | } else {
|
---|
[e98fe28c] | 375 | ddf_msg(LVL_ERROR, "Client session already set");
|
---|
[2ecb5ec] | 376 | async_answer_0(icallid, ELIMIT);
|
---|
| 377 | }
|
---|
| 378 | break;
|
---|
| 379 | }
|
---|
| 380 | default:
|
---|
[9b56a8dd] | 381 | ddf_msg(LVL_ERROR, "Unknown method: %d.", (int)method);
|
---|
[2ecb5ec] | 382 | async_answer_0(icallid, EINVAL);
|
---|
| 383 | break;
|
---|
| 384 | }
|
---|
| 385 | }
|
---|