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