Professional Web Applications Themes

[Q] IOKit: Inside the bowels of IOHIDSystem - Mac Programming

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, ...

  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]manunetbsd.org[/email]
    Emmanuel Dreyfus Guest

  2. #2

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

    In article <1g1dh7y.8ihsl21v0grpmN%manunetbsd.org>,
    [email]manunetbsd.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]ejalbertstanford.edu[/email]
    [url]http://rescomp.stanford.edu/~ejalbert/[/url]
    Eric Albert Guest

  3. #3

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

    Eric Albert <ejalbertstanford.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]manunetbsd.org[/email]
    Emmanuel Dreyfus Guest

Similar Threads

  1. PDF inside PDF problem
    By Doug_Katz@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 1
    Last Post: September 1st, 12:01 AM
  2. PHP - Trying to add sha() inside a sql query
    By ....hooligan in forum Macromedia Dynamic HTML
    Replies: 1
    Last Post: April 22nd, 02:31 PM
  3. Replies: 1
    Last Post: March 1st, 11:48 PM
  4. Using class inside ASP
    By Utada P.W. SIU in forum ASP Components
    Replies: 1
    Last Post: February 24th, 10:01 AM
  5. Problem with an usb adsl modem driver - IOKit
    By Cedric Vuillet in forum Mac Programming
    Replies: 0
    Last Post: July 16th, 06:29 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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