SASC-NG
DVBSoftCAM

plugin_legacysw.c

Go to the documentation of this file.
00001 /*
00002    DVBLoopback
00003    Copyright Alan Nisota 2006
00004 
00005    This file is part of DVBLoopback.
00006 
00007     DVBLoopback is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     DVBLoopback is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with DVBLoopback; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 */
00021 #include <stdlib.h>
00022 #include <stdio.h>
00023 #include <fcntl.h>
00024 #include <pthread.h>
00025 #include <sys/mman.h>
00026 #include <sys/poll.h>
00027 #include <sys/ioctl.h>
00028 #include <signal.h>
00029 #include <string.h>
00030 #include <getopt.h>
00031 #include <unistd.h>
00032 #include <errno.h>
00033 #include "list.h"
00034 #include <linux/dvb/dmx.h>
00035 #include <linux/dvb/frontend.h>
00036 
00037 #include "process_req.h"
00038 #include "msg_passing.h"
00039 
00040 #define PLUGIN_ID 9
00041 #define DBG_NAME "LEGACYSW"
00042 #include "debug.h" //This is required to happen AFTER PLUGIN_ID is defined
00043 
00044 #ifdef FE_DISHNETWORK_SEND_LEGACY_CMD
00045 enum {
00046   LEGSW_UNKNOWN = 0,
00047   LEGSW_SW64,
00048   LEGSW_SW21,
00049 };
00050 static int legsw_opt = 0;
00051 static int opt_mapdiseqc = LEGSW_UNKNOWN;
00052 static struct option LegacySW_Opts[] = {
00053   {"legsw-diseqcmap", 1, &legsw_opt, 'd'},
00054   {0, 0, 0, 0},
00055 };
00056 
00057 static void fe_ioctl(struct parser_cmds *pc, struct poll_ll *fdptr,
00058                     cmdret_t *result, int *ret,
00059                     unsigned long int cmd, unsigned char *data)
00060 {
00061     if(FE_DISEQC_SEND_MASTER_CMD == cmd) {
00062       struct dvb_diseqc_master_cmd *msg = (struct dvb_diseqc_master_cmd *)data;
00063       unsigned char lcmd = 0;
00064       if(msg->msg_len != 4)
00065         return;
00066       if(msg->msg[0] != 0xe0 || msg->msg[1] != 0x10 || msg->msg[2] != 0x38)
00067         return;
00068       switch(msg->msg[3] & 0x0c) {
00069         case 0x00: //Port 0
00070           if(opt_mapdiseqc == LEGSW_SW64) {
00071             if(msg->msg[3] & 0x02) {
00072               lcmd = 0x1a;
00073             } else {
00074               lcmd = 0x39;
00075             }
00076           } else if(opt_mapdiseqc == LEGSW_SW21) {
00077             lcmd = 0x34;
00078           }
00079           break;
00080         case 0x04: //Port 1
00081           if(opt_mapdiseqc == LEGSW_SW64) {
00082             if(msg->msg[3] & 0x02) {
00083               lcmd = 0x5c;
00084             } else {
00085               lcmd = 0x4b;
00086             }
00087           } else if(opt_mapdiseqc == LEGSW_SW21) {
00088             lcmd = 0x65;
00089           }
00090           break;
00091         case 0x08: //Port 2
00092           if(opt_mapdiseqc == LEGSW_SW64) {
00093             if(msg->msg[3] & 0x02) {
00094               lcmd = 0x2e;
00095             } else {
00096               lcmd = 0x0d;
00097             }
00098           }
00099           break;
00100       }
00101       printf("Got Diseqc cmd!!!\n len: %d %02x->%02x\n", msg->msg_len, msg->msg[3], lcmd);
00102       if (lcmd == 0)
00103         return;
00104       if(msg->msg[3] & 0x02)
00105         lcmd |= 0x80;
00106       *result = CMD_SKIPCALL;
00107       *ret = ioctl(fdptr->fd, FE_DISHNETWORK_SEND_LEGACY_CMD, lcmd);
00108       if(*ret < 0) {
00109         *ret = errno;
00110       }
00111     }
00112 }
00113 
00114 static void connect_legsw(struct parser_adpt *pc_all)
00115 {
00116   if(opt_mapdiseqc) {
00117     ATTACH_CALLBACK(&pc_all->frontend->pre_ioctl, fe_ioctl, -1);
00118   }
00119 }
00120 static struct option *parseopt_legsw(arg_enum_t cmd)
00121 {
00122   if(cmd == ARG_INIT) {
00123     return LegacySW_Opts;
00124   } 
00125   if(cmd == ARG_HELP) {
00126     printf("   --legsw-diseqcmap <legacy-type> :\n");
00127     printf("                        map diseqc switch cmds to legacy cmds\n");
00128     printf("                        legacy-type must be sw64 or sw21\n");
00129   } 
00130   if(! legsw_opt)
00131     return NULL;
00132 
00133   switch(legsw_opt) {
00134     case 'd':
00135       if(strncmp(optarg, "sw64", 4) == 0) {
00136         opt_mapdiseqc = LEGSW_SW64;
00137       } else if(strncmp(optarg, "sw21", 4) == 0) {
00138         opt_mapdiseqc = LEGSW_SW21;
00139       }
00140       break;
00141   }
00142   //must reset sid_opt after every call
00143   legsw_opt = 0;
00144   return NULL;
00145 }
00146 
00147 //list, plugin_id, name, parse_args, connect, launch, message, send_msg
00148 static struct plugin_cmd plugin_cmds = {{NULL, NULL}, PLUGIN_ID, 
00149                      "legacy switch",
00150                      parseopt_legsw, connect_legsw, NULL, NULL, NULL, NULL, NULL};
00151 int __attribute__((constructor)) __legacysw_init(void)
00152 {
00153   list_add(&plugin_cmds.list, &plugin_cmdlist);
00154   return 0;
00155 }
00156 #endif //FE_DISHNETWORK_SEND_LEGACY_CMD
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines