1 /*****************************************************************************
2 * linux_dvb_tools.c : functions to control a DVB card under Linux
3 *****************************************************************************
4 * Copyright (C) 1998-2001 VideoLAN
6 * Authors: Damien Lucas <nitrox@via.ecp.fr>
7 * Johan Bilien <jobi@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 #include <sys/ioctl.h>
27 #include <sys/types.h>
32 #include <sys/types.h>
36 /* DVB Card Drivers */
39 #include <ost/frontend.h>
42 #include "satellite_tools.h"
44 /*****************************************************************************
45 * ioctl_SECControl : commands the SEC device
46 *****************************************************************************/
49 int ioctl_SECControl( int freq, int pol, int lnb_slof, int diseqc)
51 struct secCommand scmd;
52 struct secCmdSequence scmds;
55 if((sec = open(SEC,O_RDWR)) < 0)
60 /* Set the frequency of the transponder, taking into account the
61 local frequencies of the LNB */
62 scmds.continuousTone = (freq<lnb_slof) ? SEC_TONE_OFF : SEC_TONE_ON;
64 /* Set the polarity of the transponder by setting the correct
65 voltage on the universal LNB */
66 scmds.voltage = (pol) ? SEC_VOLTAGE_18 : SEC_VOLTAGE_13;
68 /* In case we have a DiSEqC, set it to the correct address */
70 scmd.u.diseqc.addr=0x10;
71 scmd.u.diseqc.cmd=0x38;
72 scmd.u.diseqc.numParams=1;
73 scmd.u.diseqc.params[0] = 0xF0 | ((diseqc * 4) & 0x0F) |
74 (scmds.continuousTone == SEC_TONE_ON ? 1 : 0) |
75 (scmds.voltage==SEC_VOLTAGE_18 ? 2 : 0);
77 scmds.miniCommand=SEC_MINI_NONE;
81 /* Send the data to the SEC device to prepare the LNB for tuning */
82 /*intf_Msg("Sec: Sending data\n");*/
83 if (ioctl(sec, SEC_SEND_SEQUENCE, &scmds) < 0)
93 static int check_qpsk( int );
95 /*****************************************************************************
96 * ioctl_SetQPSKFrontend : controls the FE device
97 *****************************************************************************/
99 int ioctl_SetQPSKFrontend (int freq, int srate, int fec,\
100 int lnb_lof1, int lnb_lof2, int lnb_slof)
102 FrontendParameters fep;
106 /* Open the frontend device */
107 if((front = open(FRONTEND,O_RDWR)) < 0)
112 /* Set the frequency of the transponder, taking into account the
113 local frequencies of the LNB */
114 fep.Frequency = (freq < lnb_slof) ? freq - lnb_lof1 : freq - lnb_lof2;
116 /* Set symbol rate and FEC */
117 fep.u.qpsk.SymbolRate = srate;
118 fep.u.qpsk.FEC_inner = FEC_AUTO;
120 /* Now send it all to the frontend device */
121 if (ioctl(front, FE_SET_FRONTEND, &fep) < 0)
126 /* Check if it worked */
127 rc=check_qpsk(front);
129 /* Close front end device */
137 /******************************************************************
138 * Check completion of the frontend control sequence
139 ******************************************************************/
140 static int check_qpsk(int front)
142 struct pollfd pfd[1];
144 /* poll for QPSK event to check if tuning worked */
146 pfd[0].events = POLLIN;
148 if (poll(pfd,1,3000))
150 if (pfd[0].revents & POLLIN)
152 if ( ioctl(front, FE_GET_EVENT, &event) == -EBUFFEROVERFLOW)
159 case FE_UNEXPECTED_EV:
163 case FE_COMPLETION_EV:
169 /* should come here */
182 /*****************************************************************************
183 * ioctl_SetDMXAudioFilter : controls the demux to add a filter
184 *****************************************************************************/
186 int ioctl_SetDMXFilter( int i_pid, int * pi_fd , int i_type )
188 struct dmxPesFilterParams s_filter_params;
190 /* We first open the device */
191 if ((*pi_fd = open(DMX, O_RDWR|O_NONBLOCK)) < 0)
196 /* We fill the DEMUX structure : */
197 s_filter_params.pid = i_pid;
198 s_filter_params.input = DMX_IN_FRONTEND;
199 s_filter_params.output = DMX_OUT_TS_TAP;
203 s_filter_params.pesType = DMX_PES_VIDEO;
206 s_filter_params.pesType = DMX_PES_AUDIO;
209 s_filter_params.pesType = DMX_PES_OTHER;
212 s_filter_params.flags = DMX_IMMEDIATE_START;
214 /* We then give the order to the device : */
215 if (ioctl(*pi_fd, DMX_SET_PES_FILTER, &s_filter_params) < 0)
223 /*****************************************************************************
224 * ioctl_UnsetDMXFilter : removes a filter
225 *****************************************************************************/
226 int ioctl_UnsetDMXFilter(int demux)
228 ioctl(demux, DMX_STOP);