# apply from source tree with patch -p1 -b < ./add_DiSEQ_to_tune.patch
--- ./tune.c	Thu Jan 16 08:51:41 2003
+++ ./tune.c	Sat Feb 22 01:15:39 2003
@@ -36,10 +36,66 @@
 #include <ost/sec.h>
 #include <ost/frontend.h>
 #endif
-
 #include "tune.h"
 
+/* added by Ivan Gerasimov geri_bul@yahoo.com */
+/* DiSEQ -addons-1-BEGIN*/
+/* used example from szap.c by Metzler Bros*/
+/* LNB hi/lo band switch frequency in kHz */
+#define SWITCHFREQ 11700000
+/* LNB hi/lo band local oscillator frequencies in kHz */
+#define LOF_HI 10600000
+#define LOF_LO 9750000
+
+#ifndef TRUE
+#define TRUE (1==1)
+#endif
+#ifndef FALSE
+#define FALSE (1==0)
+#endif
+/* DiSEQ -addons-1-END*/
+
+struct diseqc_cmd
+    {
+    struct dvb_diseqc_master_cmd cmd;
+    uint32_t wait;
+    };
+      
+void diseqc_send_msg(int fd, fe_sec_voltage_t v, struct diseqc_cmd *cmd, fe_sec_tone_mode_t t, fe_sec_mini_cmd_t b)
+    {
+    ioctl(fd, FE_SET_TONE, SEC_TONE_OFF);
+    ioctl(fd, FE_SET_VOLTAGE, v);
+    usleep(15 * 1000);
+    ioctl(fd, FE_DISEQC_SEND_MASTER_CMD, &cmd->cmd);
+    usleep(cmd->wait * 1000);
+    usleep(15 * 1000);
+    ioctl(fd, FE_DISEQC_SEND_BURST, b);
+    usleep(15 * 1000);
+    ioctl(fd, FE_SET_TONE, t);
+    }
+
+/* digital satellite equipment control,
+ * specification is available from http://www.eutelsat.com/
+ */
+    static int diseqk(int secfd, int sat_no, int pol, int hi_lo)
+        {
+	struct diseqc_cmd cmd = { {{0xe0, 0x10, 0x38, 0xf0, 0x00, 0x00}, 4}, 0 };
+
+    /* param: high nibble: reset bits, low nibble set bits,
+     * bits are: option, position, polarizaion, band
+     */
+    cmd.cmd.msg[3] = 0xf0 | (((sat_no * 4) & 0x0f) | (hi_lo ? 1 : 0) | (pol ? 0 : 2));
+
+    diseqc_send_msg(secfd, pol ? SEC_VOLTAGE_13 : SEC_VOLTAGE_18,
+		    &cmd, hi_lo ? SEC_TONE_ON : SEC_TONE_OFF,
+    		    (sat_no / 4) % 2 ? SEC_MINI_B : SEC_MINI_A);
+
+    return TRUE;
+    }
+/* DiSEQ -addons-1-END*/
 #ifndef NEWSTRUCT
+
+
 int OSTSelftest(int fd)
 {
     int ans;
@@ -352,7 +408,12 @@
 }
 #endif
 
-int tune_it(int fd_frontend, int fd_sec, unsigned int freq, unsigned int srate, char pol, int tone, fe_spectral_inversion_t specInv, unsigned int diseqc,fe_modulation_t modulation,fe_code_rate_t HP_CodeRate,fe_transmit_mode_t TransmissionMode,fe_guard_interval_t guardInterval, fe_bandwidth_t bandwidth) {
+
+/* name changed by Ivan Gerasimov geri_bul@yahoo.com */
+/* DiSEQ -addons-2-BEGIN*/
+/* see the end of the file :) */
+int do_tune_it(int fd_frontend, int fd_sec, unsigned int freq, unsigned int srate, char pol, int tone, fe_spectral_inversion_t specInv, unsigned int diseqc,fe_modulation_t modulation,fe_code_rate_t HP_CodeRate,fe_transmit_mode_t TransmissionMode,fe_guard_interval_t guardInterval, fe_bandwidth_t bandwidth)
+    {
   int res;
 #ifdef NEWSTRUCT
   struct dvb_frontend_parameters feparams;
@@ -484,7 +545,8 @@
 #endif
 
 #ifdef NEWSTRUCT
-  #warning DISEQC is unimplemented for NEWSTRUCT
+#warning DISEQC was unimplemented for NEWSTRUCT, now added
+
 #else
       if (diseqc > 0) {
         struct secCommand scmd;
@@ -543,4 +605,12 @@
 #endif
 
   return(check_status(fd_frontend,&feparams,tone));
-}
+    }/*tune_it*/
+
+/* first - DiSEQ, second - tuning, as in the example of szap.c by Metzler Bros, added by Ivan Gerasimov*/
+int tune_it(int fd_frontend, int fd_sec, unsigned int freq, unsigned int srate, char pol, int tone, fe_spectral_inversion_t specInv, unsigned int diseqc,fe_modulation_t modulation,fe_code_rate_t HP_CodeRate,fe_transmit_mode_t TransmissionMode,fe_guard_interval_t guardInterval, fe_bandwidth_t bandwidth)
+    {
+    fprintf(stderr,"tuning DiSEQ by Ivan %s\n", diseqk(fd_frontend, diseqc, (pol == 'h' || pol=='H')?1:0, (freq >= SWITCHFREQ))?"OK":"FALL"  );
+    do_tune_it(fd_frontend, fd_sec, freq, srate,  pol,  tone, specInv, diseqc, modulation, HP_CodeRate, TransmissionMode, guardInterval, bandwidth);
+    }/* do_tune_it */
+/* DiSEQ -addons-2-END*/
