1 /* 2 * libdvbfe - a DVB frontend library 3 * 4 * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net) 5 * Copyright (C) 2005 Manu Abraham <abraham.manu@gmail.com> 6 * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org) 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2.1 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 21 */ 22 23 #ifndef LIBDVBFE_H 24 #define LIBDVBFE_H 1 25 26 #ifdef __cplusplus 27 extern "C" 28 { 29 #endif 30 31 #include <stdint.h> 32 33 /** 34 * The types of frontend we support. 35 */ 36 enum dvbfe_type { 37 DVBFE_TYPE_DVBS, 38 DVBFE_TYPE_DVBC, 39 DVBFE_TYPE_DVBT, 40 DVBFE_TYPE_ATSC, 41 }; 42 43 enum dvbfe_spectral_inversion { 44 DVBFE_INVERSION_OFF, 45 DVBFE_INVERSION_ON, 46 DVBFE_INVERSION_AUTO 47 }; 48 49 enum dvbfe_code_rate { 50 DVBFE_FEC_NONE, 51 DVBFE_FEC_1_2, 52 DVBFE_FEC_2_3, 53 DVBFE_FEC_3_4, 54 DVBFE_FEC_4_5, 55 DVBFE_FEC_5_6, 56 DVBFE_FEC_6_7, 57 DVBFE_FEC_7_8, 58 DVBFE_FEC_8_9, 59 DVBFE_FEC_AUTO 60 }; 61 62 enum dvbfe_dvbt_const { 63 DVBFE_DVBT_CONST_QPSK, 64 DVBFE_DVBT_CONST_QAM_16, 65 DVBFE_DVBT_CONST_QAM_32, 66 DVBFE_DVBT_CONST_QAM_64, 67 DVBFE_DVBT_CONST_QAM_128, 68 DVBFE_DVBT_CONST_QAM_256, 69 DVBFE_DVBT_CONST_AUTO 70 }; 71 72 enum dvbfe_dvbc_mod { 73 DVBFE_DVBC_MOD_QAM_16, 74 DVBFE_DVBC_MOD_QAM_32, 75 DVBFE_DVBC_MOD_QAM_64, 76 DVBFE_DVBC_MOD_QAM_128, 77 DVBFE_DVBC_MOD_QAM_256, 78 DVBFE_DVBC_MOD_AUTO, 79 }; 80 81 enum dvbfe_atsc_mod { 82 DVBFE_ATSC_MOD_QAM_64, 83 DVBFE_ATSC_MOD_QAM_256, 84 DVBFE_ATSC_MOD_VSB_8, 85 DVBFE_ATSC_MOD_VSB_16, 86 DVBFE_ATSC_MOD_AUTO 87 }; 88 89 enum dvbfe_dvbt_transmit_mode { 90 DVBFE_DVBT_TRANSMISSION_MODE_2K, 91 DVBFE_DVBT_TRANSMISSION_MODE_8K, 92 DVBFE_DVBT_TRANSMISSION_MODE_AUTO 93 }; 94 95 enum dvbfe_dvbt_bandwidth { 96 DVBFE_DVBT_BANDWIDTH_8_MHZ, 97 DVBFE_DVBT_BANDWIDTH_7_MHZ, 98 DVBFE_DVBT_BANDWIDTH_6_MHZ, 99 DVBFE_DVBT_BANDWIDTH_AUTO 100 }; 101 102 enum dvbfe_dvbt_guard_interval { 103 DVBFE_DVBT_GUARD_INTERVAL_1_32, 104 DVBFE_DVBT_GUARD_INTERVAL_1_16, 105 DVBFE_DVBT_GUARD_INTERVAL_1_8, 106 DVBFE_DVBT_GUARD_INTERVAL_1_4, 107 DVBFE_DVBT_GUARD_INTERVAL_AUTO 108 }; 109 110 enum dvbfe_dvbt_hierarchy { 111 DVBFE_DVBT_HIERARCHY_NONE, 112 DVBFE_DVBT_HIERARCHY_1, 113 DVBFE_DVBT_HIERARCHY_2, 114 DVBFE_DVBT_HIERARCHY_4, 115 DVBFE_DVBT_HIERARCHY_AUTO 116 }; 117 118 /** 119 * Structure used to store and communicate frontend parameters. 120 */ 121 struct dvbfe_parameters { 122 uint32_t frequency; 123 enum dvbfe_spectral_inversion inversion; 124 union { 125 struct { 126 uint32_t symbol_rate; 127 enum dvbfe_code_rate fec_inner; 128 } dvbs; 129 130 struct { 131 uint32_t symbol_rate; 132 enum dvbfe_code_rate fec_inner; 133 enum dvbfe_dvbc_mod modulation; 134 } dvbc; 135 136 struct { 137 enum dvbfe_dvbt_bandwidth bandwidth; 138 enum dvbfe_code_rate code_rate_HP; 139 enum dvbfe_code_rate code_rate_LP; 140 enum dvbfe_dvbt_const constellation; 141 enum dvbfe_dvbt_transmit_mode transmission_mode; 142 enum dvbfe_dvbt_guard_interval guard_interval; 143 enum dvbfe_dvbt_hierarchy hierarchy_information; 144 } dvbt; 145 146 struct { 147 enum dvbfe_atsc_mod modulation; 148 } atsc; 149 } u; 150 }; 151 152 enum dvbfe_sec_voltage { 153 DVBFE_SEC_VOLTAGE_13, 154 DVBFE_SEC_VOLTAGE_18, 155 DVBFE_SEC_VOLTAGE_OFF 156 }; 157 158 enum dvbfe_sec_tone_mode { 159 DVBFE_SEC_TONE_ON, 160 DVBFE_SEC_TONE_OFF 161 }; 162 163 enum dvbfe_sec_mini_cmd { 164 DVBFE_SEC_MINI_A, 165 DVBFE_SEC_MINI_B 166 }; 167 168 /** 169 * Mask of values used in the dvbfe_get_info() call. 170 */ 171 enum dvbfe_info_mask { 172 DVBFE_INFO_LOCKSTATUS = 0x01, 173 DVBFE_INFO_FEPARAMS = 0x02, 174 DVBFE_INFO_BER = 0x04, 175 DVBFE_INFO_SIGNAL_STRENGTH = 0x08, 176 DVBFE_INFO_SNR = 0x10, 177 DVBFE_INFO_UNCORRECTED_BLOCKS = 0x20, 178 }; 179 180 /** 181 * Structure containing values used by the dvbfe_get_info() call. 182 */ 183 struct dvbfe_info { 184 enum dvbfe_type type; /* always retrieved */ 185 const char *name; /* always retrieved */ 186 unsigned int signal : 1; /* } DVBFE_INFO_LOCKSTATUS */ 187 unsigned int carrier : 1; /* } */ 188 unsigned int viterbi : 1; /* } */ 189 unsigned int sync : 1; /* } */ 190 unsigned int lock : 1; /* } */ 191 struct dvbfe_parameters feparams; /* DVBFE_INFO_FEPARAMS */ 192 uint32_t ber; /* DVBFE_INFO_BER */ 193 uint16_t signal_strength; /* DVBFE_INFO_SIGNAL_STRENGTH */ 194 uint16_t snr; /* DVBFE_INFO_SNR */ 195 uint32_t ucblocks; /* DVBFE_INFO_UNCORRECTED_BLOCKS */ 196 }; 197 198 /** 199 * Possible types of query used in dvbfe_get_info. 200 * 201 * DVBFE_INFO_QUERYTYPE_IMMEDIATE - interrogate frontend for most up to date values. 202 * DVBFE_INFO_QUERYTYPE_LOCKCHANGE - return details from queued lock status 203 * change events, or wait for one to occur 204 * if none are queued. 205 */ 206 enum dvbfe_info_querytype { 207 DVBFE_INFO_QUERYTYPE_IMMEDIATE, 208 DVBFE_INFO_QUERYTYPE_LOCKCHANGE, 209 }; 210 211 212 /** 213 * Frontend handle datatype. 214 */ 215 struct dvbfe_handle; 216 217 /** 218 * Open a DVB frontend. 219 * 220 * @param adapter DVB adapter ID. 221 * @param frontend Frontend ID of that adapter to open. 222 * @param readonly If 1, frontend will be opened in readonly mode only. 223 * @return A handle on success, or NULL on failure. 224 */ 225 extern struct dvbfe_handle *dvbfe_open(int adapter, int frontend, int readonly); 226 227 /** 228 * Close a DVB frontend. 229 * 230 * @param fehandle Handle opened with dvbfe_open(). 231 */ 232 extern void dvbfe_close(struct dvbfe_handle *handle); 233 234 /** 235 * Set the frontend tuning parameters. 236 * 237 * Note: this function provides only the basic tuning operation; you might want to 238 * investigate dvbfe_set_sec() in sec.h for a unified device tuning operation. 239 * 240 * @param fehandle Handle opened with dvbfe_open(). 241 * @param params Params to set. 242 * @param timeout <0 => wait forever for lock. 0=>return immediately, >0=> 243 * number of milliseconds to wait for a lock. 244 * @return 0 on locked (or if timeout==0 and everything else worked), or 245 * nonzero on failure (including no lock). 246 */ 247 extern int dvbfe_set(struct dvbfe_handle *fehandle, 248 struct dvbfe_parameters *params, 249 int timeout); 250 251 /** 252 * Retrieve information about the frontend. 253 * 254 * @param fehandle Handle opened with dvbfe_open(). 255 * @param querymask ORed bitmask of desired DVBFE_INFO_* values. 256 * @param result Where to put the retrieved results. 257 * @param querytype Type of query requested. 258 * @param timeout Timeout in ms to use if querytype==lockchange (0=>no timeout, <0=> wait forever). 259 * @return ORed bitmask of DVBFE_INFO_* indicating which values were read successfully. 260 */ 261 extern int dvbfe_get_info(struct dvbfe_handle *fehandle, 262 enum dvbfe_info_mask querymask, 263 struct dvbfe_info *result, 264 enum dvbfe_info_querytype querytype, 265 int timeout); 266 267 /** 268 * Get a file descriptor for polling for lock status changes. 269 * 270 * @param fehandle Handle opened with dvbfe_open(). 271 * @return FD for polling. 272 */ 273 extern int dvbfe_get_pollfd(struct dvbfe_handle *handle); 274 275 /** 276 * Tone/Data Burst control 277 * @param fehandle Handle opened with dvbfe_open(). 278 * @param tone, SEC_TONE_ON/SEC_TONE_OFF 279 */ 280 extern int dvbfe_set_22k_tone(struct dvbfe_handle *handle, enum dvbfe_sec_tone_mode tone); 281 282 /** 283 * 22khz Tone control 284 * @param fehandle Handle opened with dvbfe_open(). 285 * @param adapter, minicmd, SEC_MINI_A/SEC_MINI_B 286 */ 287 extern int dvbfe_set_tone_data_burst(struct dvbfe_handle *handle, enum dvbfe_sec_mini_cmd minicmd); 288 289 /** 290 * Voltage control 291 * @param fehandle Handle opened with dvbfe_open(). 292 * @param polarization, SEC_VOLTAGE_13/SEC_VOLTAGE_18/SEC_VOLTAGE_OFF 293 */ 294 extern int dvbfe_set_voltage(struct dvbfe_handle *handle, enum dvbfe_sec_voltage voltage); 295 296 /** 297 * High LNB voltage control (increases voltage by 1v to compensate for long cables) 298 * @param fehandle Handle opened with dvbfe_open(). 299 * @param on 1 to enable, 0 to disable. 300 */ 301 extern int dvbfe_set_high_lnb_voltage(struct dvbfe_handle *fehandle, int on); 302 303 /** 304 * Send a legacy Dish Networks command 305 * @param fehandle Handle opened with dvbfe_open(). 306 * @param cmd, the command to send 307 */ 308 extern int dvbfe_do_dishnetworks_legacy_command(struct dvbfe_handle *handle, unsigned int cmd); 309 310 /** 311 * Send a DiSEqC Command 312 * @param fehandle Handle opened with dvbfe_open(). 313 * @param data, a pointer to am array containing the data to be sent. 314 * @param len Length of data in bytes, max 6 bytes. 315 */ 316 extern int dvbfe_do_diseqc_command(struct dvbfe_handle *handle, uint8_t *data, uint8_t len); 317 318 /** 319 * Read a DISEQC response from the frontend. 320 * 321 * @param fehandle Handle opened with dvbfe_open(). 322 * @param timeout Timeout for DISEQC response. 323 * @param buf Buffer to store response in. 324 * @param len Number of bytes in buffer. 325 * @return >= 0 on success (number of received bytes), <0 on failure. 326 */ 327 extern int dvbfe_diseqc_read(struct dvbfe_handle *fehandle, int timeout, unsigned char *buf, unsigned int len); 328 329 #ifdef __cplusplus 330 } 331 #endif 332 333 #endif // LIBDVBFE_H 334