Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -uNr recfsusb2n.orig/src/Makefile recfsusb2n/src/Makefile
- --- recfsusb2n.orig/src/Makefile 2021-06-17 16:06:14.000000000 +0900
- +++ recfsusb2n/src/Makefile 2021-06-17 16:21:31.000000000 +0900
- @@ -1,7 +1,7 @@
- CC = gcc
- -CFLAGS = -O2 -Wall
- -OBJS = main.o utils.o message.o osdepend.o usbdevfile.o usbops.o tsthread.o em287x.o em287x_usb.o tc90522.o mxl136.o tda20142.o tssplitter_lite.o
- -LIBS = -lpthread
- +CFLAGS := -O2 -g -Wall `pkg-config --cflags libusb-1.0` $(CFLAGS)
- +OBJS = main.o utils.o message.o osdepend.o tsthread.o em287x.o em287x_usb.o tc90522.o mxl136.o tda20142.o tssplitter_lite.o
- +LIBS = -lpthread `pkg-config --libs libusb-1.0` $(LDFLAGS)
- TARGET = recfsusb2n
- CONF = $(TARGET).conf
- PREFIX = /usr/local
- diff -uNr recfsusb2n.orig/src/Makefile.dep recfsusb2n/src/Makefile.dep
- --- recfsusb2n.orig/src/Makefile.dep 2021-06-17 16:06:14.000000000 +0900
- +++ recfsusb2n/src/Makefile.dep 2021-06-17 16:06:40.000000000 +0900
- @@ -1,17 +1,14 @@
- -main.o: main.c usbdevfile.h types_u.h em287x.h tc90522.h mxl136.h \
- - tda20142.h tsthread.h utils.h verstr.h message.h
- -utils.o: utils.c utils.h message.h decoder.h tssplitter_lite.h
- +main.o: main.c em287x.h types_u.h tc90522.h mxl136.h tda20142.h \
- + tsthread.h utils.h verstr.h message.h
- +utils.o: utils.c decoder.h utils.h message.h tssplitter_lite.h channel.h
- message.o: message.c message.h
- osdepend.o: osdepend.c osdepend.h types_u.h
- -usbdevfile.o: usbdevfile.c usbdevfile.h types_u.h message.h
- -usbops.o: usbops.c usbops.h types_u.h message.h
- -tsthread.o: tsthread.c usbops.h types_u.h osdepend.h tsbuff.h tsthread.h \
- - message.h
- -em287x.o: em287x.c usbops.h types_u.h osdepend.h em287x.h em287x_usb.h \
- +tsthread.o: tsthread.c osdepend.h types_u.h tsbuff.h tsthread.h message.h
- +em287x.o: em287x.c osdepend.h types_u.h em287x.h em287x_usb.h \
- em287x_priv.h message.h
- em287x_usb.o: em287x_usb.c osdepend.h types_u.h em287x_usb.h \
- em287x_priv.h message.h
- tc90522.o: tc90522.c osdepend.h types_u.h tc90522.h message.h
- mxl136.o: mxl136.c osdepend.h types_u.h mxl136.h message.h
- tda20142.o: tda20142.c osdepend.h types_u.h tda20142.h message.h
- -tssplitter_lite.o: tssplitter_lite.c tssplitter_lite.h
- +tssplitter_lite.o: tssplitter_lite.c decoder.h tssplitter_lite.h
- diff -uNr recfsusb2n.orig/src/em287x.c recfsusb2n/src/em287x.c
- --- recfsusb2n.orig/src/em287x.c 2021-06-17 16:06:14.000000000 +0900
- +++ recfsusb2n/src/em287x.c 2021-06-17 16:06:40.000000000 +0900
- @@ -6,9 +6,9 @@
- #include <errno.h>
- #include <string.h>
- -#include <malloc.h>
- +#include <stdlib.h>
- -#include "usbops.h"
- +#include <libusb.h>
- #include "osdepend.h"
- #include "em287x.h"
- #include "em287x_usb.h"
- @@ -209,7 +209,7 @@
- if(( ret = writeReg(s, 0x13, 0x08 ) )) goto err1;
- if(( ret = writeReg(s, 0x0c, 0x10 ) )) goto err1;
- - if(( ret = usb_setinterface(s->fd, 0, 1) )) {
- + if(( ret = libusb_set_interface_alt_setting(s->fd, 0, 1) )) {
- warn_info(ret,"failed"); goto err1;
- }
- if(( ret = writeReg(s, 0x5f, 0x80 ) )) goto err1;
- @@ -224,7 +224,7 @@
- {
- int ret;
- - if(( ret = usb_setinterface(s->fd, 0, 0) )) {
- + if(( ret = libusb_set_interface_alt_setting(s->fd, 0, 0) )) {
- warn_info(ret,"failed"); goto err1;
- }
- @@ -265,7 +265,7 @@
- pusbep->startstopFunc = em287x_startstopStream;
- st->chip_id = 0;
- st->fd = pusbep->fd;
- - if(( ret = usb_claim(st->fd, 0) )) {
- + if(( ret = libusb_claim_interface(st->fd, 0) )) {
- warn_info(ret,"failed");
- return -5;
- }
- @@ -309,7 +309,7 @@
- warn_info(r,"failed");
- ret = (ret << 8) | (r & 0xFF);
- }
- - if((r = usb_release(s->fd, 0))) {
- + if((r = libusb_release_interface(s->fd, 0))) {
- warn_info(r,"failed");
- ret = (ret << 8) | (r & 0xFF);
- }
- @@ -349,4 +349,4 @@
- -/*EOF*/
- \ No newline at end of file
- +/*EOF*/
- diff -uNr recfsusb2n.orig/src/em287x_usb.c recfsusb2n/src/em287x_usb.c
- --- recfsusb2n.orig/src/em287x_usb.c 2021-06-17 16:06:14.000000000 +0900
- +++ recfsusb2n/src/em287x_usb.c 2021-06-17 16:06:40.000000000 +0900
- @@ -7,21 +7,20 @@
- #include <stddef.h>
- #include <errno.h>
- #include <sys/ioctl.h>
- -#include <linux/usb/ch9.h>
- -#include <linux/usbdevice_fs.h>
- +#include <libusb.h>
- #include "osdepend.h"
- #include "em287x_usb.h"
- #include "em287x_priv.h"
- #include "message.h"
- -int em287x_ctrl(const int fd, const uint16_t reg, const uint16_t size, uint8_t* const data, const unsigned mode)
- +int em287x_ctrl(libusb_device_handle* fd, const uint16_t reg, const uint16_t size, uint8_t* const data, const unsigned mode)
- {
- int ret;
- - struct usbdevfs_ctrltransfer usb_cmd = { USB_TYPE_VENDOR|USB_RECIP_DEVICE, 0, 0, reg, size, USB_TIMEOUT, data};
- - usb_cmd.bRequestType |= (mode & 0x1) ? USB_DIR_OUT : USB_DIR_IN;
- - usb_cmd.bRequest = (mode >> 8) & 0xFF;
- - if(ioctl(fd, USBDEVFS_CONTROL, &usb_cmd) < 0) {
- + uint8_t bmRequestType = LIBUSB_REQUEST_TYPE_VENDOR| LIBUSB_RECIPIENT_DEVICE;
- + bmRequestType |= (mode & 0x1) ? LIBUSB_ENDPOINT_OUT : LIBUSB_ENDPOINT_IN;
- + uint8_t bRequest = (mode >> 8) & 0xFF;
- + if(libusb_control_transfer(fd, bmRequestType, bRequest, 0, reg, data, size, USB_TIMEOUT) < 0) {
- ret = errno;
- warn_info(ret,"%02X_%02X", (mode >> 8) & 0xFF, reg);
- return -ret;
- diff -uNr recfsusb2n.orig/src/em287x_usb.h recfsusb2n/src/em287x_usb.h
- --- recfsusb2n.orig/src/em287x_usb.h 2021-06-17 16:06:14.000000000 +0900
- +++ recfsusb2n/src/em287x_usb.h 2021-06-17 16:06:40.000000000 +0900
- @@ -8,6 +8,6 @@
- #define USB_TIMEOUT 400 //# USB ctrl timeout (msec)
- -int em287x_ctrl(const int fd, const uint16_t reg, const uint16_t size, uint8_t* const data, const unsigned mode);
- +int em287x_ctrl(libusb_device_handle* fd, const uint16_t reg, const uint16_t size, uint8_t* const data, const unsigned mode);
- /*EOF*/
- diff -uNr recfsusb2n.orig/src/main.c recfsusb2n/src/main.c
- --- recfsusb2n.orig/src/main.c 2021-06-17 16:06:14.000000000 +0900
- +++ recfsusb2n/src/main.c 2021-06-17 16:06:40.000000000 +0900
- @@ -10,7 +10,7 @@
- #include <errno.h>
- #include <unistd.h>
- -#include "usbdevfile.h"
- +#include <libusb.h>
- #include "em287x.h"
- #include "tc90522.h"
- #include "mxl136.h"
- @@ -26,21 +26,6 @@
- static unsigned char volatile caughtSignal = 0;
- static void sighandler(int arg) { caughtSignal = 1; }
- -static int check_usbdevId(const unsigned int* desc)
- -{
- - //if(0xeb1a == desc[0] && 0x8178 == desc[1]) return 0;
- - if(0x0511 == desc[0]) {
- - switch( desc[1] ) {
- - //case 0x0029:
- - //case 0x003b:
- - case 0x0045:
- - return 0;
- - }
- - }
- - return 1; //# not match
- -}
- -
- -
- int main(int argc, char **argv)
- {
- int ret = 0, i, j;
- @@ -58,14 +43,16 @@
- msg("recfsusb2n " PRG_VER " " PRG_BUILT " " PRG_TIMESTAMP ", (GPL) 2016 trinity19683\n");
- parseOption(argc, argv, &args);
- - usbep.fd = usbdevfile_alloc(check_usbdevId, &args.devfile);
- + libusb_init(NULL);
- + usbep.fd = libusb_open_device_with_vid_pid(NULL, 0x0511, 0x0045);
- if(0 <= usbep.fd) {
- - msg("# ISDB-T/S TV Tuner FSUSB2N: '%s', freq= %u kHz, duration= %u sec.\n", args.devfile, args.freq, args.recsec);
- - free(args.devfile);
- + msg("# ISDB-T/S TV Tuner FSUSB2N: freq= %u kHz, duration= %u sec.\n", args.freq, args.recsec);
- }else{
- warn_msg(0,"No device can be used.");
- ret = 40; goto end1;
- }
- + libusb_claim_interface(usbep.fd, 0);
- +
- u_gettime(&time_begin);
- if(em287x_create(&devst, &usbep) != 0) {
- ret = 41; goto end3;
- @@ -259,9 +246,7 @@
- end3:
- em287x_destroy(devst);
- //end2:
- - if(close(usbep.fd) == -1) {
- - warn_msg(errno,"failed to close usbdevfile");
- - }
- + libusb_close(usbep.fd);
- end1:
- if(0 == ret) {
- u_difftime(&time_begin, &time_end, &i, &j);
- diff -uNr recfsusb2n.orig/src/mxl136.c recfsusb2n/src/mxl136.c
- --- recfsusb2n.orig/src/mxl136.c 2021-06-17 16:06:14.000000000 +0900
- +++ recfsusb2n/src/mxl136.c 2021-06-17 16:06:40.000000000 +0900
- @@ -7,7 +7,7 @@
- #include <stdint.h>
- #include <errno.h>
- #include <string.h>
- -#include <malloc.h>
- +#include <stdlib.h>
- #include "osdepend.h"
- #include "mxl136.h"
- @@ -183,4 +183,4 @@
- }
- -/*EOF*/
- \ No newline at end of file
- +/*EOF*/
- diff -uNr recfsusb2n.orig/src/osdepend.c recfsusb2n/src/osdepend.c
- --- recfsusb2n.orig/src/osdepend.c 2021-06-17 16:06:14.000000000 +0900
- +++ recfsusb2n/src/osdepend.c 2021-06-17 16:06:40.000000000 +0900
- @@ -5,7 +5,7 @@
- */
- #include <pthread.h>
- -#include <malloc.h>
- +#include <stdlib.h>
- #include <errno.h>
- #include <unistd.h>
- #include "osdepend.h"
- @@ -57,4 +57,4 @@
- return 0;
- }
- -/*EOF*/
- \ No newline at end of file
- +/*EOF*/
- diff -uNr recfsusb2n.orig/src/tc90522.c recfsusb2n/src/tc90522.c
- --- recfsusb2n.orig/src/tc90522.c 2021-06-17 16:06:14.000000000 +0900
- +++ recfsusb2n/src/tc90522.c 2021-06-17 16:06:40.000000000 +0900
- @@ -7,7 +7,7 @@
- #include <stdint.h>
- #include <errno.h>
- #include <string.h>
- -#include <malloc.h>
- +#include <stdlib.h>
- #include "osdepend.h"
- #include "tc90522.h"
- @@ -640,4 +640,4 @@
- }
- -/*EOF*/
- \ No newline at end of file
- +/*EOF*/
- diff -uNr recfsusb2n.orig/src/tda20142.c recfsusb2n/src/tda20142.c
- --- recfsusb2n.orig/src/tda20142.c 2021-06-17 16:06:14.000000000 +0900
- +++ recfsusb2n/src/tda20142.c 2021-06-17 16:06:40.000000000 +0900
- @@ -7,7 +7,7 @@
- #include <stdint.h>
- #include <errno.h>
- #include <string.h>
- -#include <malloc.h>
- +#include <stdlib.h>
- #include "osdepend.h"
- #include "tda20142.h"
- @@ -408,4 +408,4 @@
- }
- -/*EOF*/
- \ No newline at end of file
- +/*EOF*/
- diff -uNr recfsusb2n.orig/src/tssplitter_lite.h recfsusb2n/src/tssplitter_lite.h
- --- recfsusb2n.orig/src/tssplitter_lite.h 2021-06-17 16:06:14.000000000 +0900
- +++ recfsusb2n/src/tssplitter_lite.h 2021-06-17 16:06:40.000000000 +0900
- @@ -21,6 +21,7 @@
- #define __STDC_FORMAT_MACROS
- #include <inttypes.h>
- +#include <sys/types.h>
- #include <unistd.h>
- #define LENGTH_PACKET (188)
- diff -uNr recfsusb2n.orig/src/tsthread.c recfsusb2n/src/tsthread.c
- --- recfsusb2n.orig/src/tsthread.c 2021-06-17 16:06:14.000000000 +0900
- +++ recfsusb2n/src/tsthread.c 2021-06-17 16:06:40.000000000 +0900
- @@ -6,12 +6,11 @@
- #include <errno.h>
- #include <sys/ioctl.h>
- -#include <linux/usbdevice_fs.h>
- #include <string.h>
- #include <poll.h>
- #include <pthread.h>
- -#include "usbops.h"
- +#include <libusb.h>
- #include "osdepend.h"
- #include "tsbuff.h"
- #include "tsthread.h"
- @@ -36,37 +35,42 @@
- int buff_pop;
- };
- +static void cb_iso(struct libusb_transfer* urbp);
- +static void cb_bulk(struct libusb_transfer* urbp);
- -static int submitNextURB(struct tsthread_param* const ps, struct usbdevfs_urb* const urbp)
- +static int submitNextURB(struct tsthread_param* const ps, struct libusb_transfer* const urbp)
- {
- - //# isochronous URB request
- int ret = 0, j;
- - memset(urbp, 0, sizeof(struct usbdevfs_urb) + sizeof(struct usbdevfs_iso_packet_desc) * NUM_ISOC_PACKET );
- - urbp->type = (ps->pUSB->endpoint & 0x100) ? USBDEVFS_URB_TYPE_ISO : USBDEVFS_URB_TYPE_BULK;
- + urbp->dev_handle = ps->pUSB->fd;
- + urbp->flags = 0;
- urbp->endpoint = ps->pUSB->endpoint & 0xFF;
- - urbp->usercontext = &(ps->actual_length[ps->buff_push]);
- + urbp->type = (ps->pUSB->endpoint & 0x100) ? LIBUSB_TRANSFER_TYPE_ISOCHRONOUS : LIBUSB_TRANSFER_TYPE_BULK ;
- + urbp->timeout = 4000;
- + urbp->user_data = &(ps->actual_length[ps->buff_push]);
- urbp->buffer = ps->buffer + (ps->buff_push * ps->buff_unitSize);
- - if(USBDEVFS_URB_TYPE_BULK == urbp->type) {
- - urbp->buffer_length = ps->buff_unitSize;
- + if(LIBUSB_TRANSFER_TYPE_BULK == urbp->type) {
- + urbp->length = ps->buff_unitSize;
- ps->actual_length[ps->buff_push] = -2;
- + urbp->callback = &cb_bulk;
- }else{
- - urbp->number_of_packets = NUM_ISOC_PACKET;
- - urbp->flags = USBDEVFS_URB_ISO_ASAP;
- + urbp->num_iso_packets = NUM_ISOC_PACKET;
- + urbp->flags = 0;
- + urbp->callback = &cb_iso;
- for(j = 0; j < NUM_ISOC_PACKET; j++ ) {
- - urbp->iso_frame_desc[j].length = ps->buff_unitSize;
- + urbp->iso_packet_desc[j].length = ps->buff_unitSize;
- ps->actual_length[ps->buff_push + j] = -2;
- }
- }
- - if(ioctl(ps->pUSB->fd, USBDEVFS_SUBMITURB, urbp) < 0) {
- + if(libusb_submit_transfer(urbp) < 0) {
- ret = -errno;
- warn_info(errno,"submitURB failed");
- urbp->buffer = NULL;
- }else{
- int next_index = ps->buff_push;
- - if(USBDEVFS_URB_TYPE_BULK == urbp->type) {
- + if(LIBUSB_TRANSFER_TYPE_BULK == urbp->type) {
- next_index ++;
- }else{
- next_index += NUM_ISOC_PACKET;
- @@ -76,67 +80,48 @@
- return ret;
- }
- -static int reapURB(struct tsthread_param* const ps)
- +static void cb_iso(struct libusb_transfer* urbp)
- {
- - struct usbdevfs_urb *urbp;
- - int i = 0, j, ret;
- -
- - for(;;) {
- - if((ret = ioctl(ps->pUSB->fd, USBDEVFS_REAPURBNDELAY, (void *)(&urbp)) ) < 0) {
- - if(EAGAIN == errno || EWOULDBLOCK == errno) {
- - //# no more data to be received
- - ret = -EAGAIN;
- - }else{
- - warn_info(errno,"reapURB_ndelay failed");
- - ret = -errno;
- - }
- - }
- - if(0 > ret) break;
- -
- - //# received
- - int* const pLen = urbp->usercontext;
- - if(USBDEVFS_URB_TYPE_BULK == urbp->type) {
- - if(0 == urbp->status) {
- - //# success
- - int actual_length = urbp->actual_length;
- - if(ps->buff_unitSize < actual_length) {
- - warn_info(actual_length,"reapURB overflow");
- - actual_length = ps->buff_unitSize;
- - }
- - pLen[0] = actual_length;
- - }else{
- - //# failed
- - pLen[0] = 0;
- - warn_info(urbp->status,"reapURB");
- - }
- + if (urbp->status != LIBUSB_TRANSFER_COMPLETED) {
- + return;
- + }
- +
- + int j;
- + int* const pLen = urbp->user_data;
- + const int numPkts = urbp->num_iso_packets;
- + for(j = 0; j < numPkts; j++ ) {
- + struct libusb_iso_packet_descriptor* const isocDesc = &(urbp->iso_packet_desc[j]);
- + if(0 == isocDesc->status) {
- + //# success
- + int actual_length = isocDesc->actual_length;
- + pLen[j] = actual_length;
- }else{
- - const int numPkts = urbp->number_of_packets;
- - for(j = 0; j < numPkts; j++ ) {
- - struct usbdevfs_iso_packet_desc* const isocDesc = &(urbp->iso_frame_desc[j]);
- - if(0 == isocDesc->status) {
- - //# success
- - int actual_length = isocDesc->actual_length;
- - if(ps->buff_unitSize < actual_length) {
- - warn_info(actual_length,"reapURB overflow");
- - actual_length = ps->buff_unitSize;
- - }
- - pLen[j] = actual_length;
- - }else{
- - //# failed
- - pLen[j] = 0;
- - warn_info(isocDesc->status,"reapURB");
- - }
- - }
- + //# failed
- + pLen[j] = 0;
- + warn_info(isocDesc->status,"reapURB");
- }
- - //# mark this URB unused
- - urbp->buffer = NULL;
- - i++;
- }
- +
- + urbp->buffer = NULL;
- +}
- - if(-EAGAIN != ret) {
- - return ret;
- +static void cb_bulk(struct libusb_transfer* urbp)
- +{
- + if (urbp->status != LIBUSB_TRANSFER_COMPLETED) {
- + return;
- }
- - return i;
- +
- + int* const pLen = urbp->user_data;
- + if(0 == urbp->status) {
- + //# success
- + int actual_length = urbp->actual_length;
- + pLen[0] = actual_length;
- + }else{
- + //# failed
- + pLen[0] = 0;
- + warn_info(urbp->status,"reapURB");
- + }
- + urbp->buffer = NULL;
- }
- /* TS thread function issues URB requests. */
- @@ -144,32 +129,28 @@
- {
- struct tsthread_param* const ps = param;
- int ret, i;
- - const unsigned UrbSize = ROUNDUP( sizeof(struct usbdevfs_urb) + sizeof(struct usbdevfs_iso_packet_desc) * NUM_ISOC_PACKET ,0xF);
- - void* ptrUrb;
- + struct libusb_transfer* pUrb[TS_MaxNumIO];
- - ptrUrb = uHeapAlloc(UrbSize * TS_MaxNumIO);
- - if(! ptrUrb) {
- - warn_info(errno,"failed to allocate");
- - return;
- + for (i = 0; i < TS_MaxNumIO; i++) {
- + pUrb[i] = libusb_alloc_transfer(NUM_ISOC_PACKET);
- + if(!pUrb[i]) {
- + warn_info(errno,"failed to allocate");
- + return;
- + }
- + pUrb[i]->buffer = NULL;
- }
- ps->buff_push = 0;
- - for(i = 0; i < TS_MaxNumIO; i++) {
- - struct usbdevfs_urb* const pUrb = ptrUrb + UrbSize * i;
- - //# mark this URB unused
- - pUrb->buffer = NULL;
- - }
- for(;;) {
- int num = TS_MaxNumIO;
- for(i = 0; i < TS_MaxNumIO; i++) {
- - struct usbdevfs_urb* const pUrb = ptrUrb + UrbSize * i;
- - if(! pUrb->buffer) {
- + if(! pUrb[i]->buffer) {
- if(ps->flags & 0x01) {
- num--;
- }else{
- //# continue to issue a new URB request
- - submitNextURB(ps, pUrb);
- + submitNextURB(ps, pUrb[i]);
- }
- }
- }
- @@ -179,33 +160,23 @@
- }
- if(ps->flags & 0x02) {
- //# canceled
- - reapURB(ps);
- for(i = 0; i < TS_MaxNumIO; i++) {
- - struct usbdevfs_urb* const pUrb = ptrUrb + UrbSize * i;
- - if(! pUrb->buffer) continue;
- - if(ioctl(ps->pUSB->fd, USBDEVFS_DISCARDURB, pUrb) < 0) {
- + if(! pUrb[i]->buffer) continue;
- + if(libusb_cancel_transfer(pUrb[i]) < 0) {
- warn_info(errno,"failed to discard URB");
- }
- }
- + libusb_handle_events(NULL);
- break;
- }
- -
- - struct pollfd pfd;
- - pfd.fd = ps->pUSB->fd;
- - pfd.events = POLLOUT | POLLERR;
- - ret = poll(&pfd, 1, TS_PollTimeout);
- - if(0 > ret) {
- - warn_info(errno,"poll failed");
- - break;
- - }else{
- - if(0 == ret) {
- - //# timeout
- - if(!(ps->flags & 0x01)) dmsg("poll timeout");
- - }
- - if(reapURB(ps) < 0) break;
- + ret = libusb_handle_events(NULL);
- + if (ret == 1) {
- + warn_info(errno, "libusb_handle_events timeout");
- }
- }
- - uHeapFree(ptrUrb);
- + for (i = 0; i < TS_MaxNumIO; i++)
- + if (pUrb[i])
- + libusb_free_transfer(pUrb[i]);
- ps->flags |= 0x01; //# continue = F
- }
- @@ -324,19 +295,6 @@
- return ps->actual_length[j];
- }
- -int tsthread_wait(const tsthread_ptr tptr, const int timeout)
- -{
- - struct tsthread_param* const ps = tptr;
- - int ret;
- - struct pollfd pfd;
- - pfd.fd = ps->pUSB->fd;
- - pfd.events = POLLOUT | POLLERR;
- - ret = poll(&pfd, 1, timeout);
- - if(0 > ret) {
- - warn_info(errno,"poll failed");
- - }
- - return ret;
- -}
- /*EOF*/
- diff -uNr recfsusb2n.orig/src/types_u.h recfsusb2n/src/types_u.h
- --- recfsusb2n.orig/src/types_u.h 2021-06-17 16:06:14.000000000 +0900
- +++ recfsusb2n/src/types_u.h 2021-06-17 16:06:40.000000000 +0900
- @@ -4,8 +4,9 @@
- 2016-01-22
- */
- #pragma once
- +#include <libusb.h>
- -typedef int HANDLE;
- +typedef libusb_device_handle* HANDLE;
- typedef void* PMUTEX;
- struct usb_endpoint_st {
- @@ -22,4 +23,4 @@
- unsigned char addr;
- };
- -/*EOF*/
- \ No newline at end of file
- +/*EOF*/
- diff -uNr recfsusb2n.orig/src/usbdevfile.c recfsusb2n/src/usbdevfile.c
- --- recfsusb2n.orig/src/usbdevfile.c 2021-06-17 16:06:14.000000000 +0900
- +++ recfsusb2n/src/usbdevfile.c 1970-01-01 09:00:00.000000000 +0900
- @@ -1,154 +0,0 @@
- -/* fsusb2i (c) 2015 trinity19683
- - USB device file (Linux OSes)
- - usbdevfile.c
- - 2015-12-28
- -*/
- -
- -#include <errno.h>
- -#include <unistd.h>
- -#include <string.h>
- -#include <sys/file.h>
- -#include <linux/usb/ch9.h>
- -#include <dirent.h>
- -
- -#include "usbdevfile.h"
- -#include "message.h"
- -
- -#define PATH_SEPARATOR '/'
- -
- -const char* BASE_DIR_UDEV = "/dev/bus/usb";
- -
- -static int usb_getdesc(const char *devfile, struct usb_device_descriptor* desc)
- -{
- - int f;
- -
- - f = open(devfile, O_RDONLY);
- - if(-1 == f) {
- - warn_msg(errno,"can't open usbdevfile to read '%s'", devfile);
- - return errno;
- - }
- - memset(desc, 0, sizeof(struct usb_device_descriptor));
- - ssize_t rlen = read(f, desc, sizeof(struct usb_device_descriptor));
- - if(-1 == rlen) {
- - warn_msg(errno,"can't read usbdevfile '%s'", devfile);
- - return errno;
- - }
- - if(close(f) == -1) {
- - warn_msg(errno,"can't close usbdevfile '%s'", devfile);
- - return errno;
- - }
- -
- - return 0;
- -}
- -
- -static int path_strcat(char* const path, const int lpos, const char* const fname, const size_t maxlen)
- -{
- - int len = strlen(fname);
- - if(lpos + len >= maxlen -2) {
- - //# buffer overflow
- - return -1;
- - }
- - path[lpos] = PATH_SEPARATOR;
- - memcpy(&path[lpos +1], fname, 1 + len);
- - return lpos + 1 + len;
- -}
- -
- -static HANDLE usb_open(const char *devfile)
- -{
- - HANDLE fd;
- -
- - if((fd = open(devfile, O_RDWR)) == -1) {
- - warn_msg(errno,"can't open usbdevfile to read/write '%s'", devfile);
- - return -errno;
- - }
- - if(flock(fd, LOCK_EX | LOCK_NB) < 0) {
- - warn_msg(errno,"share violation. usbdevfile '%s'", devfile);
- - if(close(fd) == -1) {
- - warn_msg(errno,"failed to close usbdevfile '%s'", devfile);
- - //return -errno;
- - }
- - return -errno;
- - }
- - return fd;
- -}
- -
- -HANDLE usbdevfile_alloc(int (*check_func)(const unsigned int*), char** const pdevfile)
- -{
- -#define MAX_DEPTH_DIR 2
- - DIR *dp[MAX_DEPTH_DIR];
- - int depth, dirpath_len;
- - char dirpath[PATH_MAX];
- -
- - if(NULL == pdevfile) {
- - return -EINVAL;
- - }
- - if(NULL != *pdevfile) {
- - return usb_open(*pdevfile);
- - }
- -
- - strcpy(dirpath, BASE_DIR_UDEV);
- - dirpath_len = strlen(BASE_DIR_UDEV);
- - dp[0] = NULL;
- - depth = 0;
- - while(0 <= depth) {
- - if(NULL == dp[depth]) {
- - dp[depth] = opendir(dirpath);
- - }
- - if(NULL == dp[depth]) {
- - warn_info(0,"failed to opendir '%s'", dirpath);
- - depth--;
- - continue;
- - }
- - struct dirent *dentry;
- - while((dentry = readdir(dp[depth])) != NULL) {
- - if(DT_CHR == dentry->d_type) {
- - //# found USB devfile
- - const int r = path_strcat(dirpath, dirpath_len, dentry->d_name, sizeof(dirpath));
- - if(0 > r)
- - goto endcheck_usbdevfile; //# buffer overflow check
- -
- - struct usb_device_descriptor desc;
- - if(usb_getdesc(dirpath, &desc) != 0)
- - goto endcheck_usbdevfile;
- - unsigned int tmpbuf[2];
- - tmpbuf[0] = desc.idVendor;
- - tmpbuf[1] = desc.idProduct;
- - if(check_func(tmpbuf) != 0)
- - goto endcheck_usbdevfile;
- - HANDLE fd = usb_open(dirpath);
- - if(0 <= fd) {
- - //# usb_open success
- - *pdevfile = strdup(dirpath);
- - return fd;
- - }
- -endcheck_usbdevfile:
- - dirpath[dirpath_len] = 0;
- -
- - }else if(MAX_DEPTH_DIR -1 > depth && DT_DIR == dentry->d_type) {
- - if(strcmp(dentry->d_name,".") == 0 || strcmp(dentry->d_name,"..") == 0) {
- - //# self or parent directory, skip
- - continue;
- - }
- - const int len = path_strcat(dirpath, dirpath_len, dentry->d_name, sizeof(dirpath));
- - if(0 <= len) { //# buffer overflow check
- - dirpath_len = len;
- - dp[++depth] = NULL;
- - break;
- - }
- - }
- - }
- - if(NULL == dentry) {
- - //# end of directory stream
- - closedir(dp[depth]);
- - char* const ptr = strrchr(dirpath, PATH_SEPARATOR);
- - if(NULL != ptr) {
- - *ptr = 0;
- - dirpath_len = (int)(ptr - dirpath);
- - }
- - depth--;
- - }
- - }
- - return -1;
- -}
- -
- -/*EOF*/
- diff -uNr recfsusb2n.orig/src/usbdevfile.h recfsusb2n/src/usbdevfile.h
- --- recfsusb2n.orig/src/usbdevfile.h 2021-06-17 16:06:14.000000000 +0900
- +++ recfsusb2n/src/usbdevfile.h 1970-01-01 09:00:00.000000000 +0900
- @@ -1,11 +0,0 @@
- -/* fsusb2i (c) 2015 trinity19683
- - USB device file
- - usbdevfile.h
- - 2015-12-09
- -*/
- -#pragma once
- -#include "types_u.h"
- -
- -HANDLE usbdevfile_alloc(int (*check_func)(const unsigned int*), char** const pdevfile);
- -
- -/*EOF*/
- diff -uNr recfsusb2n.orig/src/usbops.c recfsusb2n/src/usbops.c
- --- recfsusb2n.orig/src/usbops.c 2021-06-17 16:06:14.000000000 +0900
- +++ recfsusb2n/src/usbops.c 1970-01-01 09:00:00.000000000 +0900
- @@ -1,67 +0,0 @@
- -/* SunPTV-USB (c) 2016 trinity19683
- - USB operations (Linux OSes)
- - usbops.c
- - 2016-01-11
- -*/
- -
- -#include <errno.h>
- -#include <sys/ioctl.h>
- -#include <linux/usbdevice_fs.h>
- -#include "usbops.h"
- -#include "message.h"
- -
- -int usb_reset(HANDLE fd)
- -{
- - if(ioctl(fd, USBDEVFS_RESET, 0) < 0) {
- - warn_info(errno,"failed");
- - return errno;
- - }
- - return 0;
- -}
- -
- -int usb_claim(HANDLE fd, unsigned int interface)
- -{
- - if(ioctl(fd, USBDEVFS_CLAIMINTERFACE, &interface) < 0) {
- - if(errno == EBUSY) {
- - //# BUSY
- - warn_msg(0,"USB interface%u is busy", interface);
- - }else{
- - warn_info(errno,"failed");
- - }
- - return errno;
- - }
- - return 0;
- -}
- -
- -int usb_release(HANDLE fd, unsigned int interface)
- -{
- - if(ioctl(fd, USBDEVFS_RELEASEINTERFACE, &interface) < 0) {
- - warn_info(errno,"failed");
- - return errno;
- - }
- - return 0;
- -}
- -
- -int usb_setconfiguration(HANDLE fd, unsigned int confignum)
- -{
- - return ioctl(fd, USBDEVFS_SETCONFIGURATION, &confignum);
- -}
- -
- -int usb_setinterface(HANDLE fd, const unsigned int interface, const unsigned int altsetting)
- -{
- - struct usbdevfs_setinterface setintf;
- - setintf.interface = interface;
- - setintf.altsetting = altsetting;
- - return ioctl(fd, USBDEVFS_SETINTERFACE, &setintf);
- -}
- -
- -int usb_clearhalt(HANDLE fd, unsigned int endpoint)
- -{
- - if(ioctl(fd, USBDEVFS_CLEAR_HALT, &endpoint) < 0) {
- - warn_info(errno,"EP=%02X failed", endpoint);
- - return -errno;
- - }
- - return 0;
- -}
- -
- -/*EOF*/
- diff -uNr recfsusb2n.orig/src/usbops.h recfsusb2n/src/usbops.h
- --- recfsusb2n.orig/src/usbops.h 2021-06-17 16:06:14.000000000 +0900
- +++ recfsusb2n/src/usbops.h 1970-01-01 09:00:00.000000000 +0900
- @@ -1,16 +0,0 @@
- -/* SunPTV-USB (c) 2016 trinity19683
- - USB operations
- - usbops.h
- - 2016-01-11
- -*/
- -#pragma once
- -#include "types_u.h"
- -
- -int usb_reset(HANDLE);
- -int usb_claim(HANDLE, unsigned int interface);
- -int usb_release(HANDLE, unsigned int interface);
- -int usb_setconfiguration(HANDLE, unsigned int confignum);
- -int usb_setinterface(HANDLE, const unsigned int interface, const unsigned int altsetting);
- -int usb_clearhalt(HANDLE, unsigned int endpoint);
- -
- -/*EOF*/
- diff -uNr recfsusb2n.orig/src/utils.c recfsusb2n/src/utils.c
- --- recfsusb2n.orig/src/utils.c 2021-06-17 16:06:14.000000000 +0900
- +++ recfsusb2n/src/utils.c 2021-06-17 16:12:55.000000000 +0900
- @@ -38,7 +38,7 @@
- #ifdef STD_B25
- msg(" [--b25]");
- #endif
- - msg(" [--dev devfile] [--tsid n] [--sid n1,n2,...] channel recsec destfile\n");
- + msg(" [--tsid n] [--sid n1,n2,...] channel recsec destfile\n");
- exit(1);
- }
- @@ -51,7 +51,6 @@
- for(;;) {
- int option_index = 0;
- static struct option long_options[] = {
- - {"dev", required_argument, NULL, 'd'},
- #ifdef STD_B25
- {"b25", no_argument, NULL, 'b'},
- {"B25", no_argument, NULL, 'b'},
- @@ -69,10 +68,6 @@
- case 'v': //# verbose
- args->flags |= 0x1;
- break;
- - case 'd': //# specify devfile (usbdevfs)
- - if( optarg )
- - args->devfile = strdup(optarg);
- - break;
- #ifdef STD_B25
- case 'b': //# enable descrambling (STD-B25)
- args->flags |= 0x1000;
- @@ -536,10 +531,21 @@
- char *p, buf[256];
- ssize_t len;
- +#ifdef __linux__
- if((len = readlink("/proc/self/exe", buf, sizeof(buf) - 8)) == -1)
- return 2;
- buf[len] = '\0';
- strcat(buf, ".conf");
- +#else
- +#ifdef __APPLE__
- + uint32_t bufsize = 256;
- + _NSGetExecutablePath(buf, &bufsize);
- + strcat(buf, ".conf");
- +
- +#else
- + strcpy(buf, "recfsusb2n.conf");
- +#endif
- +#endif
- fp = fopen(buf, "r");
- if(fp == NULL) {
- @@ -593,4 +599,4 @@
- return 0;
- }
- -/*EOF*/
- \ No newline at end of file
- +/*EOF*/
- diff -uNr recfsusb2n.orig/src/utils.h recfsusb2n/src/utils.h
- --- recfsusb2n.orig/src/utils.h 2021-06-17 16:06:14.000000000 +0900
- +++ recfsusb2n/src/utils.h 2021-06-17 16:06:40.000000000 +0900
- @@ -15,7 +15,6 @@
- unsigned int recsec;
- unsigned int splitter;
- char sid_list[32];
- - char* devfile;
- char* destfile;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement