problem with 2.6 kernel driver for a USB MAG Stripe Reader as HID device.

Submitted by Anonymous
on July 23, 2008 - 3:03pm

I'm trying to take the track data from the MSR and output it as keyboard input.

I can see the data coming in from the MSR. But I can't get it to output as keyboard data.

Is there an easily understood or simple way to take data and input it as keyboard data?

I've tried writting it out to the keyboard buffer like I've done in a couple other applications but it only seems to register the first scancode instead of all of them.

Let me throw some simplified code at you.

I setup the urb and submit it:

usb_fill_int_urb(dev->int_in_urb, dev->udev,
usb_rcvintpipe(dev->udev, dev->int_in_endpoint->bEndpointAddress),
dev->int_in_buffer,
dev->int_in_endpoint->wMaxPacketSize,
msr_int_in_callback,
dev,
dev->int_in_endpoint->bInterval);
retval = usb_submit_urb(dev->int_in_urb, GFP_KERNEL);

In the callback I copy the data to a buffer and when it's down to the last 8 bytes I try to send it:
static void msr_int_in_callback(struct urb *urb, struct pt_regs *regs){
memcpy(&utc1800msr->data[utc1800msr->dataloc], urb->transfer_buffer, urb->actual_length);
utc1800msr->dataloc += urb->actual_length;

if(urb->actual_length < 8){
if(TRACK_1_ENABLED && t1Length){
sendKeyStrokes( dev, t1ss, strlen(t1ss));
// printk(t1bad);
//dont send the original start and end sentinels
sendKeyStrokes( dev, &data[TRACK_1_START_BYTE+1], t1Length-2);
sendKeyStrokes( dev, t1es, strlen(t1es));
}
}
}

sendKeyStrokes is:
void sendKeyStrokes( struct input_dev *inputdev, char *string, int length){
int i ;
for(i=0; i< length; i++){
printk("%c", string[i]);
WriteKb(string[i]);
}
WriteKb(0x0d);
printk("\n");
}

void WriteKb(unsigned char TheChar){
if((my_shift_state = Check_Shift[ (unsigned char)TheChar ]) == 1) {
SendScancode(LEFT_SHIFT);
}
SendScancode(ConvertToScancodes[(unsigned char)TheChar]);
// usleep(3);
SendScancode(ConvertToScancodes[(unsigned char)TheChar]|0x80);
if((my_shift_state = Check_Shift[ (unsigned char)TheChar ]) == 1) {
SendScancode(LEFT_SHIFT | 0x80);
}
}

Ok, so what I'm getting is it seems like the first scancode for the LEFT_SHIFT gets sent and registered. But all the rest of the scancodes seem to flake out.

The original code I'm borrowing this from has the usleep in it... but msleep is the only replacement. and when I replace that usleep with an msleep(1). the machine locks up hard. Poweroff the only option to recover.

Thoughts or URL's for a decent keyboard HID primer?