if (cb_data && cb_data->cb) {
if (debug)
hexdump(transfer->buffer, transfer->actual_length, "USB > ");
- cb_data->cb(transfer->buffer, transfer->actual_length, cb_data->data);
+
+ if (!cb_data->cb(transfer->buffer, transfer->actual_length, cb_data->data)) {
+ quit = EIO;
+
+ if (cb_data && cb_data->dev && cb_data->dev->transfer) {
+ libusb_free_transfer(cb_data->dev->transfer);
+ cb_data->dev->transfer = NULL;
+ }
+
+ return;
+ }
} else {
hexdump(transfer->buffer, transfer->actual_length, "> ");
}
* IN THE SOFTWARE.
*/
-typedef void (*hmcfgusb_cb_fn)(uint8_t *buf, int buf_len, void *data);
+typedef int (*hmcfgusb_cb_fn)(uint8_t *buf, int buf_len, void *data);
struct hmcfgusb_dev {
libusb_device_handle *usb_devh;
#include <string.h>
#include <strings.h>
#include <poll.h>
+#include <signal.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
return *outpos - buf_out;
}
-static void hmlan_format_out(uint8_t *buf, int buf_len, void *data)
+static int hmlan_format_out(uint8_t *buf, int buf_len, void *data)
{
uint8_t out[1024];
uint8_t *outpos;
uint8_t *inpos;
int fd = *((int*)data);
+ int w;
if (buf_len < 1)
- return;
+ return 1;
memset(out, 0, sizeof(out));
outpos = out;
hexdump(buf, buf_len, "Unknown> ");
break;
}
- write(fd, out, outpos-out);
if (debug)
fprintf(stderr, "LAN < %s\n", out);
+
+ w = write(fd, out, outpos-out);
+ if (w <= 0) {
+ perror("write");
+ return 0;
+ }
+
+ return 1;
}
static int hmlan_parse_in(int fd, void *data)
static int socket_server(int port, int daemon)
{
+ struct sigaction sact;
struct sockaddr_in sin;
int sock;
int n;
}
}
+ memset(&sact, 0, sizeof(sact));
+ sact.sa_handler = SIG_IGN;
+
+ if (sigaction(SIGPIPE, &sact, NULL) == -1) {
+ perror("sigaction");
+ }
+
impersonate_hmlanif = 1;
sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
int wrong_hmid;
};
-static void parse_hmcfgusb(uint8_t *buf, int buf_len, void *data)
+static int parse_hmcfgusb(uint8_t *buf, int buf_len, void *data)
{
struct recv_data *rdata = data;
if (buf_len < 1)
- return;
+ return 1;
switch(buf[0]) {
case 'E':
hexdump(buf, buf_len, "Unknown> ");
break;
}
+
+ return 1;
}
int main(int argc, char **argv)