?? capmt.cpp
字號:
//===========================================================// CAPMT object (C++)// Handles some CAMPT and CA I/O// Code is independent of encryption scheme used// (c) Aug 2008 by Dirktator//===========================================================#include "capmt.h"#include "/data/dreambox/tuxbox-bb/build/tmp/staging/powerpc-linux/include/ost/ca.h"#include <fcntl.h>#include <stdio.h>#include <stdlib.h>#include <sys/ioctl.h>#include <sys/poll.h>#include <sys/socket.h>#include <sys/types.h>#include <stropts.h> #include <sys/un.h>#include <unistd.h>#include <errno.h>//constructor, basically just passed debug informationca_handler::ca_handler(int debug){ dbg = debug; //after the object is created, set the dbg value as defined by the command line parameter, one of these silly C++ syntax things}//the Linux DVB API does not provide a mechanism to read the program the user is watching//thus we must read the CAPMT device to receive this info from Enigma//inputs: none//returns: int ca_handler::Read_CAPMT(void){ int i, s,t, len; struct sockaddr_un remote; unsigned char buffer[8192]; if (dbg) printf("Reading CAPMT device\n"); if ((s=socket(AF_UNIX,SOCK_STREAM,0))==-1) //We need a local socket to read the data from Enigma! This is client code (PLi) { perror("\tCAPMT socket"); return 0; } if (dbg) printf("\tTrying to connect...\n"); remote.sun_family = AF_UNIX; //internal Unix socket (non-IP) strcpy(remote.sun_path, CAPMTNAME); //set the local socket path, something like /tmp/.listen.camd.socket or something len = strlen(remote.sun_path) + sizeof(remote.sun_family); if (connect(s, (struct sockaddr *)&remote, len) == -1) //connect to the socket { perror("connect"); close(s); return 0; } if (dbg) printf("\tConnected.\n"); if ((t=recv(s,buffer,100,0))>0) //receive data from the socket { i=(buffer[7]<<8)+buffer[8]; if (dbg) printf("\tSID:%04x (%04d)\n",i,i); } else perror("\tCAPMT recv"); close(s); return(i);}//Unscramble the video stream by writing both control words to the CA device//inputs: ca device file handler, 2 control word buffers (8 bytes each) and some index which's function is unclear//Returns: nothing, drives the Dreambox's unscramblingvoid ca_handler::write_control_words(unsigned int ca, unsigned char *cw_0, unsigned char *cw_1, int index){ ca_descr_t ca_descr; long long ecw,ocw; int i; static char lastcw0[8], lastcw1[8]; if (memcmp(cw_0,lastcw0,8)) { printf("write control words\nCW0:"); for (i=0;i<8;i++) printf("%02x ",cw_0[i]); printf("\n"); ca_descr.index = index; ca_descr.parity = 0; memcpy(lastcw0,cw_0,8); memcpy(ca_descr.cw,cw_0,8); if (ioctl(ca,CA_SET_DESCR,&ca_descr) < 0) perror("CA_SET_DESCR"); else printf("\t written CW0 to CA device\n"); } if (memcmp(cw_1,lastcw1,8)) { printf("write control words\nCW1:"); for (i=0;i<8;i++) printf("%02x ",cw_1[i]); printf("\n"); ca_descr.index = index; ca_descr.parity = 1; memcpy(lastcw1,cw_1,8); memcpy(ca_descr.cw,cw_1,8); if (ioctl(ca,CA_SET_DESCR,&ca_descr) < 0) perror("CA_SET_DESCR"); else printf("\t written CW1 to CA device\n"); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -