dvbfe.h 8.8 KB

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