void dt_msg_dump(struct dt_msg *msg) { int i, l; l = DT_CTL_LEN(msg->ctl); printf("hdr: dst=%02x src=%02x p=%02x sub=%02x len=%02x\n", msg->dst, msg->src, DT_CTL_P(msg->ctl), DT_CTL_SUBADDR(msg->ctl), l); printf("body: "); for (i = 0; i < l && i < 20; i++) printf("%02x ", msg->body[i]); if (i < l) { printf("\n"); for (; i < l; i++) printf("%02x ", msg->body[i]); } printf("\n"); }
void dt_dispatch(void *cookie) { struct dt_softc *sc; struct dt_msg *msg; int s, other, mouse; struct dt_device *dtdv; sc = cookie; msg = NULL; other = DT_ADDR_KBD; mouse = 0; for (;;) { s = spltty(); if (msg != NULL) { SLIST_INSERT_HEAD(&sc->sc_free, msg, chain.slist); if (mouse) { dt_ms_addr = msg->src; dt_kbd_addr = other; } else { dt_kbd_addr = msg->src; dt_ms_addr = other; } } msg = SIMPLEQ_FIRST(&sc->sc_queue); if (msg != NULL) SIMPLEQ_REMOVE_HEAD(&sc->sc_queue, chain.simpleq); splx(s); if (msg == NULL) break; if (msg->src == DT_ADDR_MOUSE) other = DT_ADDR_KBD; else if (msg->src == DT_ADDR_KBD) other = DT_ADDR_MOUSE; else { printf("%s: message from unknown dev 0x%x\n", sc->sc_dv.dv_xname, sc->sc_msg.src); dt_msg_dump(msg); continue; } if (DT_CTL_P(msg->ctl) != 0) { printf("%s: received control message\n", sc->sc_dv.dv_xname); dt_msg_dump(msg); continue; } /* * 1. Mouse should have no more than eight buttons. * 2. Mouse should always send full locator report. * 3. Keyboard should never report all-up (0x00) in * a packet with size > 1. */ if (DT_CTL_LEN(msg->ctl) == sizeof(struct dt_locator_msg) && msg->body[0] == 0) { mouse = 1; dtdv = &dt_ms_dv; } else { mouse = 0; dtdv = &dt_kbd_dv; } if (dtdv->dtdv_handler != NULL) (*dtdv->dtdv_handler)(dtdv->dtdv_dv, msg); } }
void dt_dispatch(void *cookie) { struct dt_softc *sc; struct dt_msg *msg; int s; struct dt_device *dtdv; sc = cookie; msg = NULL; for (;;) { s = spltty(); if (msg != NULL) SLIST_INSERT_HEAD(&sc->sc_free, msg, chain.slist); msg = SIMPLEQ_FIRST(&sc->sc_queue); if (msg != NULL) SIMPLEQ_REMOVE_HEAD(&sc->sc_queue, chain.simpleq); splx(s); if (msg == NULL) break; if (msg->src != DT_ADDR_MOUSE && msg->src != DT_ADDR_KBD) { printf("%s: message from unknown dev 0x%x\n", device_xname(sc->sc_dev), sc->sc_msg.src); dt_msg_dump(msg); continue; } if (DT_CTL_P(msg->ctl) != 0) { printf("%s: received control message\n", device_xname(sc->sc_dev)); dt_msg_dump(msg); continue; } /* * 1. Mouse should have no more than eight buttons, so first * 8 bits of body will be zero. * 2. Mouse should always send full locator report. * Note: my mouse does not send 'z' data, so the size * did not match the size of struct dt_locator_msg - mhitch * 3. Keyboard should never report all-up (0x00) in * a packet with size > 1. */ if (DT_CTL_LEN(msg->ctl) >= 6 && msg->body[0] == 0 && msg->src != dt_ms_addr) { dt_kbd_addr = dt_ms_addr; dt_ms_addr = msg->src; } else if (DT_CTL_LEN(msg->ctl) < 6 && msg->body[0] != 0 && msg->src != dt_kbd_addr) { dt_ms_addr = dt_kbd_addr; dt_kbd_addr = msg->src; } if (msg->src == dt_kbd_addr) dtdv = &dt_kbd_dv; else dtdv = &dt_ms_dv; if (dtdv->dtdv_handler != NULL) (*dtdv->dtdv_handler)(dtdv->dtdv_arg, msg); } }