1 /*****************************************************************************
2 * dvb.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 *****************************************************************************/
26 #include <sys/ioctl.h>
28 #ifdef HAVE_INTTYPES_H
29 # include <inttypes.h> /* int16_t .. */
31 #include <sys/types.h>
36 #include <sys/types.h>
40 /* DVB Card Drivers */
43 #include <ost/frontend.h>
48 /*****************************************************************************
49 * ioctl_SECControl : commands the SEC device
50 *****************************************************************************/
53 int ioctl_SECControl( int freq, int pol, int lnb_slof, int diseqc)
55 struct secCommand scmd;
56 struct secCmdSequence scmds;
59 if((sec = open(SEC,O_RDWR)) < 0)
64 /* Set the frequency of the transponder, taking into account the
65 local frequencies of the LNB */
66 scmds.continuousTone = (freq<lnb_slof) ? SEC_TONE_OFF : SEC_TONE_ON;
68 /* Set the polarity of the transponder by setting the correct
69 voltage on the universal LNB */
70 scmds.voltage = (pol) ? SEC_VOLTAGE_18 : SEC_VOLTAGE_13;
72 /* In case we have a DiSEqC, set it to the correct address */
74 scmd.u.diseqc.addr=0x10;
75 scmd.u.diseqc.cmd=0x38;
76 scmd.u.diseqc.numParams=1;
77 scmd.u.diseqc.params[0] = 0xF0 | ((diseqc * 4) & 0x0F) |
78 (scmds.continuousTone == SEC_TONE_ON ? 1 : 0) |
79 (scmds.voltage==SEC_VOLTAGE_18 ? 2 : 0);
81 scmds.miniCommand=SEC_MINI_NONE;
85 /* Send the data to the SEC device to prepare the LNB for tuning */
86 /*intf_Msg("Sec: Sending data\n");*/
87 if (ioctl(sec, SEC_SEND_SEQUENCE, &scmds) < 0)
97 static int check_qpsk( int );
99 /*****************************************************************************
100 * ioctl_SetQPSKFrontend : controls the FE device
101 *****************************************************************************/
103 int ioctl_SetQPSKFrontend (int freq, int srate, int fec,\
104 int lnb_lof1, int lnb_lof2, int lnb_slof)
106 FrontendParameters fep;
110 /* Open the frontend device */
111 if((front = open(FRONTEND,O_RDWR)) < 0)
116 /* Set the frequency of the transponder, taking into account the
117 local frequencies of the LNB */
118 fep.Frequency = (freq < lnb_slof) ? freq - lnb_lof1 : freq - lnb_lof2;
120 /* Set symbol rate and FEC */
121 fep.u.qpsk.SymbolRate = srate;
122 fep.u.qpsk.FEC_inner = FEC_AUTO;
124 /* Now send it all to the frontend device */
125 if (ioctl(front, FE_SET_FRONTEND, &fep) < 0)
130 /* Check if it worked */
131 rc=check_qpsk(front);
133 /* Close front end device */
141 /******************************************************************
142 * Check completion of the frontend control sequence
143 ******************************************************************/
144 static int check_qpsk(int front)
146 struct pollfd pfd[1];
148 /* poll for QPSK event to check if tuning worked */
150 pfd[0].events = POLLIN;
152 if (poll(pfd,1,3000))
154 if (pfd[0].revents & POLLIN)
156 if ( ioctl(front, FE_GET_EVENT, &event) == -EBUFFEROVERFLOW)
163 case FE_UNEXPECTED_EV:
167 case FE_COMPLETION_EV:
173 /* should come here */
186 /*****************************************************************************
187 * ioctl_SetDMXAudioFilter : controls the demux to add a filter
188 *****************************************************************************/
190 int ioctl_SetDMXFilter( int i_pid, int * pi_fd , int i_type )
192 struct dmxPesFilterParams s_filter_params;
194 /* We first open the device */
195 if ((*pi_fd = open(DMX, O_RDWR|O_NONBLOCK)) < 0)
200 /* We fill the DEMUX structure : */
201 s_filter_params.pid = i_pid;
202 s_filter_params.input = DMX_IN_FRONTEND;
203 s_filter_params.output = DMX_OUT_TS_TAP;
207 s_filter_params.pesType = DMX_PES_VIDEO;
210 s_filter_params.pesType = DMX_PES_AUDIO;
213 s_filter_params.pesType = DMX_PES_OTHER;
216 s_filter_params.flags = DMX_IMMEDIATE_START;
218 /* We then give the order to the device : */
219 if (ioctl(*pi_fd, DMX_SET_PES_FILTER, &s_filter_params) < 0)
227 /*****************************************************************************
228 * ioctl_UnsetDMXFilter : removes a filter
229 *****************************************************************************/
230 int ioctl_UnsetDMXFilter(int demux)
232 ioctl(demux, DMX_STOP);