--- linux_dvb.c.org	2006-02-14 00:00:48.000000000 +0100
+++ linux_dvb.c	2002-01-01 12:04:10.000000000 +0100
@@ -38,6 +38,11 @@
 #include <sys/stat.h>
 #include <sys/poll.h>
 
+//Newcamd
+#include <sys/un.h>
+#include <sys/socket.h>
+//Newcamd
+
 /* DVB Card Drivers */
 #include <linux/dvb/version.h>
 #include <linux/dvb/dmx.h>
@@ -83,7 +88,9 @@
 static int FrontendSetQPSK( access_t * );
 static int FrontendSetQAM( access_t * );
 static int FrontendSetOFDM( access_t * );
-
+//Newcamd
+uint16_t  newcamd_pmt;
+//Newcamd
 /*****************************************************************************
  * FrontendOpen : Determine frontend device information and capabilities
  *****************************************************************************/
@@ -1729,11 +1736,117 @@
 }
 #endif
 
+//Newcamd
+void camd_stop(unsigned int adapter, access_t * p_access)   // newcamd patch
+{
+
+		perror ( "newcamd stoped" );
+
+        struct sockaddr_un servaddr;
+        int camdSocket;
+        unsigned char camdBuffer[6];
+
+        servaddr.sun_family = AF_UNIX;
+        sprintf(servaddr.sun_path, "/tmp/camd.socket%d", adapter);
+        if ((camdSocket = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
+        {
+				perror("[camdConnect] socket");
+                return;
+        }
+        if (connect(camdSocket, (struct sockaddr*) &servaddr, sizeof(servaddr)) < 0)
+        {
+				perror("[camdConnect] connect");
+                close(camdSocket);
+                return;
+        }
+        memset (camdBuffer+1, 0, 5);
+        camdBuffer[0] = 0xff;
+	
+        if (write(camdSocket, camdBuffer, 6) < 0)
+        {
+				perror("[camdConnect] write");
+        }
+
+        if (read(camdSocket, camdBuffer, 2) < 0)
+        {
+				perror("[camdConnect] read reply");
+        }
+		msg_Dbg( p_access, "newcamd stoped" );
+        close(camdSocket);
+}
+
+void camd_start(unsigned short servid, unsigned short pmtpid, unsigned short apid, unsigned int adapter, access_t * p_access)   // newcamd patch
+{
+        struct sockaddr_un servaddr;
+        int camdSocket;
+        unsigned char camdBuffer[6];
+        unsigned short pid;
+
+        servaddr.sun_family = AF_UNIX;
+        sprintf(servaddr.sun_path, "/tmp/camd.socket%d", adapter);
+        if ((camdSocket = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
+        {
+				perror("[camdConnect] socket");
+                return;
+        }
+        if (connect(camdSocket, (struct sockaddr*) &servaddr, sizeof(servaddr)) < 0)
+        {
+				msg_Err( p_access, "Connection to newcamd failed!" );
+				perror("[camdConnect] connect");
+                close(camdSocket);
+                return;
+        }
+        pid = apid;
+
+/* Use the following line, if you want newcamd to demux and watch the pmt, *
+ * because zapit, enigma or vdr don't do it                                */
+        camdBuffer[4] = (pid >> 8) & 0x1f;
+
+/* Use the following line, if newcamd isn't allowed to demux/watch the pmt, *
+ * because zapit, enigma or vdr do it themself, this needs /tmp/pmt.tmp,    *
+ * when starting newcamd                                                    */
+//      camdBuffer[4] = ((pid >> 8) & 0x1f) | 0x80;
+
+        camdBuffer[5] = pid & 0xff;
+        pid = pmtpid;
+        camdBuffer[0] = (pid >> 8) & 0x1f;
+        camdBuffer[1] = pid & 0xff;
+        pid = servid;
+        camdBuffer[2] = pid >> 8;
+        camdBuffer[3] = pid & 0xff;
+        if (write(camdSocket, camdBuffer, 6) < 0)
+        {
+				perror("[camdConnect] write");
+        }
+        if (read(camdSocket, camdBuffer, 2) < 0)
+        {
+                perror("[camdConnect] read reply");
+        }
+		msg_Dbg( p_access, "newcamd started" );
+        close(camdSocket);
+}
+//Newcamd
+
+
 /*****************************************************************************
  * CAMSet :
  *****************************************************************************/
 int E_(CAMSet)( access_t * p_access, dvbpsi_pmt_t *p_pmt )
 {
+//Newcamd
+	unsigned int i_adapter;
+    i_adapter = var_GetInteger( p_access, "dvb-adapter" );	
+	
+	if ( newcamd_pmt != p_pmt->i_program_number )
+	{
+		msg_Dbg( p_access, "Sending parameters to newcamd %d,%d,%d,%d ", p_pmt->i_program_number,0,0,i_adapter );
+
+		newcamd_pmt = p_pmt->i_program_number;
+        camd_stop(i_adapter,p_access);            // newcamd patch
+        camd_start(p_pmt->i_program_number,0,0,i_adapter,p_access);      // newcamd patch
+	}	
+//Newcamd
+
     access_sys_t *p_sys = p_access->p_sys;
 
     if ( p_sys->i_ca_handle == 0 )
