beginning of hmsniff, a small HomeMatic sniffer/dissector
[hmcfgusb] / hmcfgusb.c
index b8c1546708802beba99b3f0b00f1eb21ad1ccee2..1a6bb760eb36764eb2d9b2c736bcd4244db4778b 100644 (file)
@@ -145,7 +145,7 @@ int hmcfgusb_send(struct hmcfgusb_dev *usbdev, unsigned char* send_data, int len
        int cnt;
 
        if (debug)
-               hexdump(send_data, len, "< ");
+               hexdump(send_data, len, "USB < ");
        err = libusb_interrupt_transfer(usbdev->usb_devh, EP_OUT, send_data, len, &cnt, USB_TIMEOUT);
        if (err) {
                fprintf(stderr, "Can't send data: %s\n", usb_strerror(err));
@@ -225,7 +225,7 @@ static void LIBUSB_CALL hmcfgusb_interrupt(struct libusb_transfer *transfer)
        } else {
                if (cb_data && cb_data->cb) {
                        if (debug)
-                               hexdump(transfer->buffer, transfer->actual_length, "> ");
+                               hexdump(transfer->buffer, transfer->actual_length, "USB > ");
                        cb_data->cb(transfer->buffer, transfer->actual_length, cb_data->data);
                } else {
                        hexdump(transfer->buffer, transfer->actual_length, "> ");
@@ -317,6 +317,8 @@ struct hmcfgusb_dev *hmcfgusb_init(hmcfgusb_cb_fn cb, void *data)
 
        dev->n_pfd = dev->n_usb_pfd;
 
+       quit = 0;
+
        return dev;
 }
 
@@ -370,6 +372,7 @@ int hmcfgusb_poll(struct hmcfgusb_dev *dev, int timeout)
                n = poll(dev->pfd, dev->n_pfd, tv.tv_sec * 1000);
                if (n < 0) {
                        perror("poll");
+                       errno = 0;
                        return -1;
                } else if (n == 0) {
                        usb_event = 1;
@@ -380,6 +383,7 @@ int hmcfgusb_poll(struct hmcfgusb_dev *dev, int timeout)
                                                usb_event = 1;
                                                break;
                                        } else {
+                                               errno = 0;
                                                return dev->pfd[fd_n].fd;
                                        }
                                }
@@ -397,8 +401,11 @@ int hmcfgusb_poll(struct hmcfgusb_dev *dev, int timeout)
                }
        }
 
-       if (quit)
+       errno = 0;
+       if (quit) {
+               fprintf(stderr, "closing device-connection due to error %d\n", quit);
                errno = quit;
+       }
 
        return -1;
 }
Impressum, Datenschutz