+
+ while(!quit) {
+ int fd;
+
+ if (rdata.wrong_hmid) {
+ printf("changing hmId to 000000, this might reboot the device!\n");
+ if (dev.type == DEVICE_TYPE_HMCFGUSB) {
+ hmcfgusb_send(dev.hmcfgusb, (unsigned char*)"A\00\00\00", 4, 1);
+ rdata.wrong_hmid = 0;
+ hmcfgusb_send(dev.hmcfgusb, (unsigned char*)"K", 1, 1);
+ } else {
+ buf[0] = HMUARTLGW_APP_SET_HMID;
+ buf[1] = 0x00;
+ buf[2] = 0x00;
+ buf[3] = 0x00;
+ hmuartlgw_send(dev.hmuartlgw, buf, 4, HMUARTLGW_APP);
+ }
+ }
+ if (dev.type == DEVICE_TYPE_HMCFGUSB) {
+ fd = hmcfgusb_poll(dev.hmcfgusb, 1000);
+ } else {
+ fd = hmuartlgw_poll(dev.hmuartlgw, 60000);
+ }
+ if (fd >= 0) {
+ fprintf(stderr, "activity on unknown fd %d!\n", fd);
+ continue;
+ } else if (fd == -1) {
+ if (errno) {
+ if (errno != ETIMEDOUT) {
+ perror("hmsniff_poll");
+ break;
+ } else {
+ /* periodically wakeup the device */
+ if (dev.type == DEVICE_TYPE_HMCFGUSB) {
+ hmcfgusb_send_null_frame(dev.hmcfgusb, 1);
+ }
+ }
+ }
+ }
+ }
+
+ if (dev.type == DEVICE_TYPE_HMCFGUSB) {
+ if (dev.hmcfgusb)
+ hmcfgusb_close(dev.hmcfgusb);
+ } else {
+ if (dev.hmuartlgw)
+ hmuartlgw_close(dev.hmuartlgw);
+ }
+ } while (!quit);
+
+ if (dev.type == DEVICE_TYPE_HMCFGUSB) {
+ hmcfgusb_exit();