[Q] IOKit: Inside the bowels of IOHIDSystem

Ask a Question related to Mac Programming, Design and Development.

  1. #1

    Default [Q] IOKit: Inside the bowels of IOHIDSystem

    Hi everyone

    I try to understand the kernel/userland interface of the IOHIDSystem
    driver in MacOS X. I wrote the following test code, strongly inspired
    from XDarwin sources. But whatever happens, I never get any event for
    moved mouse in the low level queue.

    Anyone has an idea why?

    #include <mach/mach_types.h>
    #include <mach/mach_host.h>
    #include <mach/mach_traps.h>
    #include <mach/mach_init.h>

    #include <IOKitLib.h>
    #include <IOLLEvent.h>
    #include <IOHIDShared.h>

    #include <stdio.h>
    #include <unistd.h>
    #include <fcntl.h>
    #include <errno.h>
    #include <ctype.h>

    void dump(char *, size_t);

    /*
    * cc -Wall -Werror -ansi \
    * -I/System/Library/Frameworks/IOKit.framework/Headers \
    * -I/System/Library/Frameworks/IOKit.framework/Headers/hidsystem \
    * -L/System/Library/Frameworks/IOKit.framework -g
    * -o test -lIOKit test.c
    */
    int
    main(argc, argv)
    int argc;
    char **argv;
    {
    host_name_port_t hs;
    io_master_t iop;
    kern_return_t ret;
    mach_port_t rp;
    CFMutableDictionaryRef classToMatch;
    char *cn = "IOHIDSystem";
    io_iterator_t iterator;
    io_object_t serviceObject;
    io_connect_t dataport;
    vm_address_t shmem;
    vm_size_t size;
    EvGlobals *evg;
    int i;
    int log;

    if (argc != 2) {
    printf("usage: %s logfile\n", argv[0]);
    return 1;
    }

    log = open(argv[1], O_WRONLY|O_TRUNC|O_CREAT, 0644);
    if (log == -1) {
    perror("cannot open log file");
    return 1;
    }

    rp = mach_reply_port();
    hs = mach_host_self();

    ret = IOMasterPort(MACH_PORT_NULL, &iop);
    printf("ret = 0x%x, rp = 0x%x, hs = 0x%x, iop = 0x%x\n",
    ret, rp, hs, iop);
    if (ret != 0)
    return 1;

    classToMatch = IOServiceMatching(cn);

    ret = IOServiceGetMatchingServices(iop,
    classToMatch, &iterator);
    printf("ret = 0x%x, iterator = 0x%x\n", ret, iterator);
    if (ret != 0)
    return 1;

    serviceObject = IOIteratorNext(iterator);
    printf("serviceObject = 0x%x\n", serviceObject);

    ret = IOServiceOpen(serviceObject, mach_task_self(),
    0, &dataport);
    printf("ret = 0x%x, dataport = 0x%x\n", ret, dataport);
    if (ret != 0)
    return 1;

    ret = IOHIDCreateSharedMemory(dataport,
    kIOHIDCurrentShmemVersion);
    printf("ret = 0x%x\n", ret);
    if (ret != 0)
    return 1;

    ret = IOConnectMapMemory(dataport, kIOHIDGlobalMemory,
    mach_task_self(), &shmem, &size, kIOMapAnywhere);
    printf("ret = 0x%x, shmem = 0x%x, size = 0x%x\n",
    ret, shmem, size);
    if (ret != 0)
    return 1;

    evg = (EvGlobals *)(shmem +
    ((EvOffsets *)shmem)->evGlobalsOffset);
    printf("evg = %p\n", evg);
    if (evg == NULL)
    return 1;

    evg->movedMask = NX_MOUSEMOVEDMASK;

    printf("Perform an action within 3 seconds... \n");
    sleep(3);
    printf("Okay, let's dump in the logfile...\n");

    (void)close(1);
    (void)dup(log);

    printf("LLEHead = %d\n", evg->LLEHead);
    printf("LLETail = %d\n", evg->LLETail);
    printf("LLELast = %d\n", evg->LLELast);
    for (i = 0; i < LLEQSIZE; i++) {
    printf("item %d\n", i);
    printf(" next = %d, type = %d, flags = %d\n",
    evg->lleq[i].next,
    evg->lleq[i].event.type,
    evg->lleq[i].event.flags);
    printf(" x = %d, y = %d, window = %d\n",
    evg->lleq[i].event.location.x,
    evg->lleq[i].event.location.y,
    evg->lleq[i].event.window);
    dump((char *)&evg->lleq[i].event.data,
    sizeof(evg->lleq[i].event.data));
    }
    printf("\n\nFull dump of the shared memory\n");
    dump((char *)shmem, size);

    return 0;
    }

    void
    dump(data, len)
    char *data;
    size_t len;
    {
    int i, j;

    for (i = 0; i < len; i += 16) {
    printf("%p ", &data[i]);
    for (j = i; j < i + 16; j += 4)
    printf("0x%08x ", *((int *)(&data[j])));
    printf(" ");
    for (j = i; j < i + 16; j++)
    if (isprint(data[j]))
    printf("%c", data[j]);
    else
    printf(".");
    printf("\n");
    }
    return;
    }


    --
    Emmanuel Dreyfus
    [email]manu@netbsd.org[/email]
    Emmanuel Dreyfus Guest

  2. Similar Questions and Discussions

    1. Dynamic temp. datagrid col.gen. -Session access inside a class inside a UserCtrl
      Hello Dear Professionals: Based on this document:...
    2. Using class inside ASP
      Hi all professional I would like to know how to using java class file inside ASP page I have placed the class file to C:\WINNT\java\trustlib...
    3. buttons inside MCs
      I have a movie clip as a rollover menu, which as 4 buttons within it. The movie clips has the following code attached to it, making the MC play...
    4. Problem with an usb adsl modem driver - IOKit
      Hello, I have some problems with an usb adsl modem driver. My modem is recognized when I start it up after Mac's launching, but in all other...
    5. OT: Sorry to intrude Please see Inside.
      Wonder if anybody else is getting stupid pop ups from ByAdds or similar..they seem to change their name. Norton pro 2003 and AVG do not indicate any...
  3. #2

    Default Re: [Q] IOKit: Inside the bowels of IOHIDSystem

    In article <1g1dh7y.8ihsl21v0grpmN%manu@netbsd.org>,
    [email]manu@netbsd.org[/email] (Emmanuel Dreyfus) wrote:
    > I try to understand the kernel/userland interface of the IOHIDSystem
    > driver in MacOS X. I wrote the following test code, strongly inspired
    > from XDarwin sources. But whatever happens, I never get any event for
    > moved mouse in the low level queue.
    >
    > Anyone has an idea why?
    Probably not here. I'd suggest asking this on Apple's
    darwin-development mailing list.

    -Eric

    --
    Eric Albert [email]ejalbert@stanford.edu[/email]
    [url]http://rescomp.stanford.edu/~ejalbert/[/url]
    Eric Albert Guest

  4. #3

    Default Re: [Q] IOKit: Inside the bowels of IOHIDSystem

    Eric Albert <ejalbert@stanford.edu> wrote:
    > Probably not here. I'd suggest asking this on Apple's
    > darwin-development mailing list.
    Thanks for the hint.
    Anyway, someone else gave me the answer behinf the scene: IOHIDSystem
    will not report events until this is called:

    IOHIDSetEventsEnable (dataport, TRUE);

    --
    Emmanuel Dreyfus
    Publicité subliminale: achetez ce livre!
    [url]http://www.eyrolles.com/php.informatique/Ouvrages/9782212112443.php3[/url]
    [email]manu@netbsd.org[/email]
    Emmanuel Dreyfus Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139