Ejemplo n.º 1
0
void scan_sdt() {
    int fd_sdt;
    int n,seclen;
    int i,k;
    int max_k;
    unsigned char buf[4096];
    struct dmx_sct_filter_params sctFilterParams;
    int ca,service_id,loop_length;
    int pmt_pid;
    struct pollfd ufd;
    int section_number,last_section_number;

    if((fd_sdt = open(demuxdev[card],O_RDWR|O_NONBLOCK)) < 0) {
        perror("fd_sdt DEVICE: ");
        return;
    }

    sctFilterParams.pid=0x11;
    memset(&sctFilterParams.filter,0,sizeof(sctFilterParams.filter));
    sctFilterParams.timeout = 0;
    sctFilterParams.flags = DMX_IMMEDIATE_START;
    sctFilterParams.filter.filter[0]=0x42;
    sctFilterParams.filter.mask[0]=0xff;

    if (ioctl(fd_sdt,DMX_SET_FILTER,&sctFilterParams) < 0) {
        perror("SDT - DMX_SET_FILTER:");
        close(fd_sdt);
        return;
    }

    max_k=1;
//  printf("<sdt>\n");

    for (k=0; k<max_k; k++) {
        ufd.fd=fd_sdt;
        ufd.events=POLLPRI;
        if (poll(&ufd,1,20000) < 0 ) {
            fprintf(stderr,"TIMEOUT on read from fd_sdt\n");
            close(fd_sdt);
            return;
        }
        if (read(fd_sdt,buf,3)==3) {
            seclen=((buf[1] & 0x0f) << 8) | (buf[2] & 0xff);
            n = read(fd_sdt,buf+3,seclen);
            if (n==seclen) {
                seclen+=3;
//      printf("Read %d bytes\n",seclen);
                //    for (i=0;i<seclen+3;i++) { printf("%02x ",buf[i]); }
                /*      for (i=0;i< seclen;i++) {
                        printf("%02x ",buf[i]);
                        if ((i % 16)==15) {
                          printf("  ");
                          for (j=i-15;j<=i;j++) {
                             printf("%c",((buf[j]>31) && (buf[j]<=127)) ? buf[j] : '.');
                          }
                          printf("\n");
                        }
                      }
                */
                section_number=buf[6];
                last_section_number=buf[7];
                fprintf(stderr,"Read SDT section - section_number=%d, last_section_number=%d\n",section_number,last_section_number);
                max_k=buf[7]+1; // last_sec_num - read this many (+1) sections

                i=11;
                while (i < (seclen-4)) {
                    service_id=(buf[i]<<8)|buf[i+1];
                    i+=2;
                    i++;  // Skip a field
                    ca=(buf[i]&0x10)>>4;
                    loop_length=((buf[i]&0x0f)<<8)|buf[i+1];
                    pmt_pid = get_pmt_pid(service_id);
                    printf("<service id=\"%d\" pmt_pid=\"%d\" ca=\"%d\">\n",service_id,pmt_pid,ca);
                    i+=2;
                    parse_descriptors(loop_length,&buf[i],&transponder,&transponders);
                    i+=loop_length;
                    scan_pmt(pmt_pid,service_id,(service_id==pnr));
                    printf("</service>\n");
                }
            }  else {
Ejemplo n.º 2
0
int scan_nit(int x) {
    int fd_nit;
    int n,seclen;
    int i;
    struct pollfd ufd;
    unsigned char buf[4096];
    struct dmx_sct_filter_params sctFilterParams;
    int info_len,network_id;

    if((fd_nit = open(demuxdev[card],O_RDWR|O_NONBLOCK)) < 0) {
        perror("fd_nit DEVICE: ");
        return -1;
    }

    sctFilterParams.pid=0x10;
    memset(&sctFilterParams.filter,0,sizeof(sctFilterParams.filter));
    sctFilterParams.timeout = 0;
    sctFilterParams.flags = DMX_IMMEDIATE_START;
    sctFilterParams.filter.filter[0]=x;
    sctFilterParams.filter.mask[0]=0xff;

    if (ioctl(fd_nit,DMX_SET_FILTER,&sctFilterParams) < 0) {
        perror("NIT - DMX_SET_FILTER:");
        close(fd_nit);
        return -1;
    }

    ufd.fd=fd_nit;
    ufd.events=POLLPRI;
    if (poll(&ufd,1,10000) < 0 ) {
        fprintf(stderr,"TIMEOUT on read from fd_nit\n");
        close(fd_nit);
        return -1;
    }
    if (read(fd_nit,buf,3)==3) {
        seclen=((buf[1] & 0x0f) << 8) | (buf[2] & 0xff);
        n = read(fd_nit,buf+3,seclen);
        if (n==seclen) {
            seclen+=3;
//      dump("nit.dat",seclen,buf);
//      printf("<nit>\n");
            network_id=(buf[3]<<8)|buf[4];
//      printf("<network id=\"%d\">\n",network_id);

            info_len=((buf[8]&0x0f)<<8)|buf[9];
            i=10;
            parse_descriptors(info_len,&buf[i],&transponder,&transponders);
            i+=info_len;
            i+=2;
            while (i < (seclen-4)) {
                transponder.id=(buf[i]<<8)|buf[i+1];
                i+=2;
                transponder.onid=(buf[i]<<8)|buf[i+1];
                i+=2;
                //        printf("<transponder id=\"%d\" onid=\"%d\">\n",transponder.id,transponder.onid);
                info_len=((buf[i]&0x0f)<<8)|buf[i+1];
                i+=2;
                parse_descriptors(info_len,&buf[i],&transponder,&transponders);
//        printf("</transponder>\n");
                i+=info_len;
            }
//      printf("</network>\n");
//      printf("</nit>\n");
        } else {
            fprintf(stderr,"Under-read bytes for NIT - wanted %d, got %d\n",seclen,n);
        }
    } else {
        fprintf(stderr,"Nothing to read from fd_nit\n");
    }
    close(fd_nit);
    return(0);
}
Ejemplo n.º 3
0
void scan_pmt(int pid,int sid,int change) {
    int fd_pmt;
    int n,seclen;
    int i;
    unsigned char buf[4096];
    struct dmx_sct_filter_params sctFilterParams;
    int service_id;
    int info_len,es_pid,stream_type;
    struct pollfd ufd;

    fprintf(stderr,"Scanning pmt: pid=%d, sid=%d\n",pid,sid);

    if (pid==0) {
        return;
    }

    if((fd_pmt = open(demuxdev[card],O_RDWR|O_NONBLOCK)) < 0) {
        perror("fd_pmt DEVICE: ");
        return;
    }

    sctFilterParams.pid=pid;
    memset(&sctFilterParams.filter,0,sizeof(sctFilterParams.filter));
    sctFilterParams.timeout = 0;
    sctFilterParams.flags = DMX_IMMEDIATE_START;
    sctFilterParams.filter.filter[0]=0x02;
    sctFilterParams.filter.mask[0]=0xff;

    if (ioctl(fd_pmt,DMX_SET_FILTER,&sctFilterParams) < 0) {
        perror("PMT - DMX_SET_FILTER:");
        close(fd_pmt);
        return;
    }

    ufd.fd=fd_pmt;
    ufd.events=POLLPRI;
    if (poll(&ufd,1,10000) < 0) {
        fprintf(stderr,"TIMEOUT reading from fd_pmt\n");
        close(fd_pmt);
        return;
    }

    if (read(fd_pmt,buf,3)==3) {
        seclen=((buf[1] & 0x0f) << 8) | (buf[2] & 0xff);
        n = read(fd_pmt,buf+3,seclen);
        if (n==seclen) {
            seclen+=3;
//      printf("<pmt>\n");
            service_id=(buf[3]<<8)|buf[4];
//      printf("<service id=\"%d\" pmt_pid=\"%d\">\n",service_id,pid);

            if (sid != service_id) {
                close(fd_pmt);
                scan_pmt(pid, sid, change);
                return;
            }

            info_len=((buf[10]&0x0f)<<8)|buf[11];
            i=12;
            parse_descriptors(info_len,&buf[i],&transponder,&transponders);
            i+=info_len;
            while (i < (seclen-4)) {
                stream_type=buf[i++];
                es_pid=((buf[i]&0x1f)<<8)|buf[i+1];
                printf("<stream type=\"%d\" pid=\"%d\">\n",stream_type,es_pid);
                if (change) {
                    if ((vpid==0) && ((stream_type==1) || (stream_type==2))) {
                        vpid=es_pid;
                    }
                    if ((apid==0) && ((stream_type==3) || (stream_type==4))) {
                        apid=es_pid;
                    }
                }

                i+=2;
                info_len=((buf[i]&0x0f)<<8)|buf[i+1];
                i+=2;
                parse_descriptors(info_len,&buf[i],&transponder,&transponders);
                i+=info_len;
                printf("</stream>\n");
            }
//      printf("</service>\n");
//      printf("</pmt>\n");
        } else {
            printf("Under-read bytes for PMT - wanted %d, got %d\n",seclen,n);
        }
    } else {
        fprintf(stderr,"Nothing to read from fd_pmt\n");
    }

    close(fd_pmt);
}
Ejemplo n.º 4
0
/* Return     : None                                                                */
void insertion( struct usbd_connection *pConnection, usbd_device_instance_t *pInstance )
{
   int rc;
   struct usbd_device * pDevice;
   pModule_data_t pModule, * ppModule;
   
   if(verbosity)
     printf("Try to inser device\n");
   if( EOK != (rc = usbd_attach( pConnection, pInstance, sizeof(module_data_t **), &pDevice ) ))
     {
     char * pMsgTxt = "Error: cannot attach USB device #%i (error code is %i)\n";
     fprintf(stderr, pMsgTxt, (int)(pInstance -> devno), rc);
     slogf(_SLOG_SETCODE(_SLOGC_INPUT, 0), _SLOG_ERROR, pMsgTxt, (int)(pInstance -> devno), rc);
     return;
     }
   ppModule = (pModule_data_t *)usbd_device_extra(pDevice);
	
	
   // Try to find if somebody cares about keyboard reports
   for(pModule = LIST_FIRST_ITEM(&modList); NULL != pModule; pModule = LIST_NEXT_ITEM(pModule, lst_conn))
        {
	// Check device number if specified
        if( (USBD_CONNECT_WILDCARD != pModule -> nDev) && (pModule -> nDev != pInstance -> devno))
	     continue;

        if( (USBD_CONNECT_WILDCARD != pModule -> nVendor) && (pModule -> nVendor != pInstance -> ident.vendor))
             continue; // Wrong vendor - ignore
	   
        if((USBD_CONNECT_WILDCARD != pModule -> nClass) && (pModule -> nClass != pInstance -> ident.dclass))
             continue;
   
        if((USBD_CONNECT_WILDCARD != pModule -> nSubClass) && (pModule -> nSubClass != pInstance -> ident.subclass))
             continue;

	pModule -> pInstance = pInstance;
	pModule -> pDevice   = pDevice;
        if( EOK == parse_descriptors( pModule) )
	   {
	   if( pModule -> ep_int_buf = usbd_alloc( pModule -> ep_int_size ) )
	      {
	      if( pModule -> urb = usbd_alloc_urb( NULL ) )
		 {
		 // Initialize request block
		 usbd_setup_interrupt( pModule -> urb,  
				      URB_DIR_IN, 
				      pModule -> ep_int_buf, 
				      pModule->ep_int_size );
		 // Initialize Interrupt callback function
		 if( EOK == usbd_io( pModule -> urb, 
				   pModule -> ep_int, 
				   usb_dev_int, 
				   pModule, USBD_TIME_INFINITY ) ) 
		      {
		      pModule -> flags |= USB_DEVICE_ON |  USB_DEVICE_PRESENT;
		      *ppModule = pModule;
                      if(verbosity)
                         printf("Attach device\n");
		      return;
		      }
		 else
		      {
                      if(verbosity)
                         printf("Cannot attach device\n");
		      }
		 }
               usbd_free( pModule -> ep_int_buf );
	       }
	   usbd_detach( pDevice );
	   }
         }
}