Exemplo n.º 1
0
        /// <summary>
        /// Enters the CI menu
        /// </summary>
        /// <returns></returns>
        public bool EnterCIMenu()
        {
            IKsControl pControl = CiFilter as IKsControl;

            if (pControl == null)
            {
                return(false);
            }

            KSMETHOD KsMethod = new KSMETHOD(KSMETHODSET_DD_CAM_CONTROL,
                                             (Int32)KSMETHOD_DD_CAM_CONTROL.KSMETHOD_DD_CAM_ENTER_MENU,
                                             KSMETHOD_TYPE_SEND);

            Int32 dwReturned = 0;
            Int32 hr         = pControl.KsMethod(ref KsMethod, Marshal.SizeOf(KsMethod),
                                                 IntPtr.Zero, 0,
                                                 ref dwReturned
                                                 );

            if (hr == 0)
            {
                _MenuId = 0; // reset
            }
            return(hr == 0);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sends the ServiceID to CAM to start decryption.
        /// </summary>
        /// <param name="serviceId">Service ID</param>
        /// <returns>true if successful or no CI available</returns>
        public bool SendServiceIdToCam(Int32 serviceId)
        {
            IKsControl pControl = CiFilter as IKsControl;

            if (pControl == null)
            {
                return(true);
            }

            KSMETHOD KsProperty = new KSMETHOD(KSPROPERTYSET_DD_COMMON_INTERFACE,
                                               (Int32)KSPROPERTY_DD_COMMON_INTERFACE.KSPROPERTY_DD_DECRYPT_PROGRAM,
                                               KSPROPERTY_TYPE_SET);
            Int32 paramSize  = Marshal.SizeOf(sizeof(Int32));
            Int32 dwReturned = 0;
            // Initialize unmanged memory to hold the struct.
            IntPtr pSid = Marshal.AllocHGlobal(paramSize);

            Marshal.WriteInt32(pSid, serviceId);
            try
            {
                Int32 hr = pControl.KsProperty(ref KsProperty, Marshal.SizeOf(KsProperty),
                                               pSid, paramSize,
                                               ref dwReturned);
                Log.Log.Debug(
                    FormatMessage(String.Format("--> Setting service id {0} for decrypting returned {1}", serviceId, hr)));
                return(hr == 0);
            }
            finally
            {
                // Free the unmanaged memory.
                Marshal.FreeHGlobal(pSid);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Sends an answer after CI request
        /// </summary>
        /// <param name="Cancel">true to cancel</param>
        /// <param name="Answer">Answer string</param>
        /// <returns></returns>
        public bool SendMenuAnswer(bool Cancel, string Answer)
        {
            IKsControl pControl = CiFilter as IKsControl;

            if (pControl == null)
            {
                return(false);
            }

            // Initialize unmanged memory to hold the struct.
            Int32 answerLength = (String.IsNullOrEmpty(Answer) ? 0 : Answer.Length);
            Int32 bufferSize   = 8 + answerLength + 1;

            if (bufferSize < 12)
            {
                bufferSize = 12;
            }

            IntPtr pReply = Marshal.AllocHGlobal(bufferSize);

            try
            {
                // Copy the struct to unmanaged memory.
                Marshal.WriteInt32(pReply, 0, _MenuId);
                if (answerLength > 0)
                {
                    Marshal.WriteInt32(pReply, 4, (int)Answer.Length);
                    for (int i = 0; i < Answer.Length; i += 1)
                    {
                        Marshal.WriteByte(pReply, 8 + i, (byte)Answer[i]);
                    }
                    Marshal.WriteByte(pReply, 8 + Answer.Length, 0);
                }
                else
                {
                    Marshal.WriteInt32(pReply, 4, 0);
                }

                //DVB_MMI.DumpBinary(pReply, 0, bufferSize);

                KSMETHOD KsMethod = new KSMETHOD(KSMETHODSET_DD_CAM_CONTROL,
                                                 (Int32)KSMETHOD_DD_CAM_CONTROL.KSMETHOD_DD_CAM_ANSWER,
                                                 KSMETHOD_TYPE_SEND);
                Int32 dwReturned = 0;
                Int32 hr         = pControl.KsMethod(ref KsMethod, Marshal.SizeOf(KsMethod),
                                                     pReply, bufferSize,
                                                     ref dwReturned
                                                     );
                return(hr == 0);
            }
            finally
            {
                // Free the unmanaged memory.
                Marshal.FreeHGlobal(pReply);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Resets the CAM.
        /// </summary>
        /// <returns></returns>
        public bool ResetCAM()
        {
            IKsControl pControl = CiFilter as IKsControl;

            if (pControl == null)
            {
                return(false);
            }

            KSMETHOD KsMethod = new KSMETHOD(KSMETHODSET_DD_CAM_CONTROL,
                                             (Int32)KSMETHOD_DD_CAM_CONTROL.KSMETHOD_DD_CAM_RESET,
                                             KSMETHOD_TYPE_SEND);

            Int32 dwReturned = 0;
            Int32 hr         = pControl.KsMethod(ref KsMethod, Marshal.SizeOf(KsMethod),
                                                 IntPtr.Zero, 0,
                                                 ref dwReturned
                                                 );

            return(hr == 0);
        }
Exemplo n.º 5
0
        private bool GetMenuTitle(out DD_CAM_MENU_TITLE MenuTitle)
        {
            MenuTitle = new DD_CAM_MENU_TITLE();

            IKsControl pControl = CiFilter as IKsControl;

            if (pControl == null)
            {
                return(false);
            }

            KSMETHOD KsProperty = new KSMETHOD(KSPROPERTYSET_DD_COMMON_INTERFACE,
                                               (Int32)KSPROPERTY_DD_COMMON_INTERFACE.KSPROPERTY_DD_CAM_MENU_TITLE,
                                               KSPROPERTY_TYPE_GET);
            Int32 ulMenuSize = Marshal.SizeOf(MenuTitle);
            Int32 dwReturned = 0;
            // Initialize unmanged memory to hold the struct.
            IntPtr pTitle = Marshal.AllocHGlobal(Marshal.SizeOf(MenuTitle));

            try
            {
                Int32 hr = pControl.KsProperty(ref KsProperty, Marshal.SizeOf(KsProperty),
                                               pTitle, ulMenuSize,
                                               ref dwReturned
                                               );

                if (hr != 0 || dwReturned != ulMenuSize)
                {
                    return(false);
                }

                MenuTitle = (DD_CAM_MENU_TITLE)Marshal.PtrToStructure(pTitle, typeof(DD_CAM_MENU_TITLE));
                return(true);
            }
            finally
            {
                // Free the unmanaged memory.
                Marshal.FreeHGlobal(pTitle);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Selects a CI menu entry
        /// </summary>
        /// <param name="choice">choice</param>
        /// <returns></returns>
        public bool SelectMenu(byte choice)
        {
            IKsControl pControl = CiFilter as IKsControl;

            if (pControl == null)
            {
                return(false);
            }

            DD_CAM_MENU_REPLY Reply;

            Reply.Id     = _MenuId;
            Reply.Choice = choice;

            // Initialize unmanged memory to hold the struct.
            IntPtr pReply = Marshal.AllocHGlobal(Marshal.SizeOf(Reply));

            try
            {
                // Copy the struct to unmanaged memory.
                Marshal.StructureToPtr(Reply, pReply, false);

                KSMETHOD KsMethod = new KSMETHOD(KSMETHODSET_DD_CAM_CONTROL,
                                                 (Int32)KSMETHOD_DD_CAM_CONTROL.KSMETHOD_DD_CAM_MENU_REPLY,
                                                 KSMETHOD_TYPE_SEND);
                Int32 dwReturned = 0;
                Int32 hr         = pControl.KsMethod(ref KsMethod, Marshal.SizeOf(KsMethod),
                                                     pReply, Marshal.SizeOf(Reply),
                                                     ref dwReturned
                                                     );
                return(hr == 0);
            }
            finally
            {
                // Free the unmanaged memory.
                Marshal.FreeHGlobal(pReply);
            }
        }
Exemplo n.º 7
0
    private bool GetCamMenuText(out DD_CAM_MENU_DATA CiMenu)
    {
      CiMenu = new DD_CAM_MENU_DATA();
      IKsControl pControl = CiFilter as IKsControl;
      if (pControl == null) return false;

      // Initialize unmanged memory to hold the struct.
      Int32 ulMenuSize = 2048;
      IntPtr pCiMenu = Marshal.AllocHGlobal(ulMenuSize);
      try
      {
        KSMETHOD KsMethod = new KSMETHOD(KSMETHODSET_DD_CAM_CONTROL,
                                         (Int32)KSMETHOD_DD_CAM_CONTROL.KSMETHOD_DD_CAM_GET_MENU,
                                         KSMETHOD_TYPE_SEND);
        Int32 dwReturned = 0;
        Int32 hr = pControl.KsMethod(ref KsMethod, Marshal.SizeOf(KsMethod),
                                     pCiMenu, ulMenuSize,
                                     ref dwReturned
          );
        if (hr == 0)
        {
          Int32 offs = 0;
          CiMenu.Id = Marshal.ReadInt32(pCiMenu, offs);
          offs += 4;
          CiMenu.Type = Marshal.ReadInt32(pCiMenu, offs);
          offs += 4;
          CiMenu.NumChoices = Marshal.ReadInt32(pCiMenu, offs);
          offs += 4;
          CiMenu.Length = Marshal.ReadInt32(pCiMenu, offs);
          offs += 4;

          // check if we already received this menu, then ignore it.
          // otherwise we would do an endless processing.
          if (CiMenu.Id == _MenuId)
            return false;

          //DVB_MMI.DumpBinary(pCiMenu, 0, dwReturned);

          CiMenu.Choices = new List<String>();
          for (int i = 0; i < CiMenu.NumChoices + 3; i++)
          {
            IntPtr newPtr = new IntPtr(pCiMenu.ToInt32() + offs);
            String choice = Marshal.PtrToStringAnsi(newPtr);
            switch (i)
            {
              case 0:
                CiMenu.Title = choice;
                break;
              case 1:
                CiMenu.SubTitle = choice;
                break;
              case 2:
                CiMenu.BottomText = choice;
                break;
              default:
                CiMenu.Choices.Add(choice);
                break;
            }
            offs += choice.Length + 1;
          }
          // remember current received menu id
          _MenuId = CiMenu.Id;
        }
        //else
        //  Marshal.ThrowExceptionForHR(hr);

        return hr == 0;
      }
      finally
      {
        // Free the unmanaged memory.
        Marshal.FreeHGlobal(pCiMenu);
      }
    }
Exemplo n.º 8
0
    private bool GetMenuTitle(out DD_CAM_MENU_TITLE MenuTitle)
    {
      MenuTitle = new DD_CAM_MENU_TITLE();

      IKsControl pControl = CiFilter as IKsControl;
      if (pControl == null) return false;

      KSMETHOD KsProperty = new KSMETHOD(KSPROPERTYSET_DD_COMMON_INTERFACE,
                                         (Int32)KSPROPERTY_DD_COMMON_INTERFACE.KSPROPERTY_DD_CAM_MENU_TITLE,
                                         KSPROPERTY_TYPE_GET);
      Int32 ulMenuSize = Marshal.SizeOf(MenuTitle);
      Int32 dwReturned = 0;
      // Initialize unmanged memory to hold the struct.
      IntPtr pTitle = Marshal.AllocHGlobal(Marshal.SizeOf(MenuTitle));
      try
      {
        Int32 hr = pControl.KsProperty(ref KsProperty, Marshal.SizeOf(KsProperty),
                                       pTitle, ulMenuSize,
                                       ref dwReturned
          );

        if (hr != 0 || dwReturned != ulMenuSize)
          return false;

        MenuTitle = (DD_CAM_MENU_TITLE)Marshal.PtrToStructure(pTitle, typeof (DD_CAM_MENU_TITLE));
        return true;
      }
      finally
      {
        // Free the unmanaged memory.
        Marshal.FreeHGlobal(pTitle);
      }
    }
Exemplo n.º 9
0
    /// <summary>
    /// Sends an answer after CI request
    /// </summary>
    /// <param name="Cancel">true to cancel</param>
    /// <param name="Answer">Answer string</param>
    /// <returns></returns>
    public bool SendMenuAnswer(bool Cancel, string Answer)
    {
      IKsControl pControl = CiFilter as IKsControl;
      if (pControl == null) return false;

      // Initialize unmanged memory to hold the struct.
      Int32 answerLength = (String.IsNullOrEmpty(Answer) ? 0 : Answer.Length);
      Int32 bufferSize = 8 + answerLength + 1;

      if (bufferSize < 12) bufferSize = 12;

      IntPtr pReply = Marshal.AllocHGlobal(bufferSize);
      try
      {
        // Copy the struct to unmanaged memory.
        Marshal.WriteInt32(pReply, 0, _MenuId);
        if (answerLength > 0)
        {
          Marshal.WriteInt32(pReply, 4, (int)Answer.Length);
          for (int i = 0; i < Answer.Length; i += 1)
          {
            Marshal.WriteByte(pReply, 8 + i, (byte)Answer[i]);
          }
          Marshal.WriteByte(pReply, 8 + Answer.Length, 0);
        }
        else
        {
          Marshal.WriteInt32(pReply, 4, 0);
        }

        //DVB_MMI.DumpBinary(pReply, 0, bufferSize);

        KSMETHOD KsMethod = new KSMETHOD(KSMETHODSET_DD_CAM_CONTROL,
                                         (Int32)KSMETHOD_DD_CAM_CONTROL.KSMETHOD_DD_CAM_ANSWER,
                                         KSMETHOD_TYPE_SEND);
        Int32 dwReturned = 0;
        Int32 hr = pControl.KsMethod(ref KsMethod, Marshal.SizeOf(KsMethod),
                                     pReply, bufferSize,
                                     ref dwReturned
          );
        return hr == 0;
      }
      finally
      {
        // Free the unmanaged memory.
        Marshal.FreeHGlobal(pReply);
      }
    }
Exemplo n.º 10
0
    /// <summary>
    /// Selects a CI menu entry
    /// </summary>
    /// <param name="choice">choice</param>
    /// <returns></returns>
    public bool SelectMenu(byte choice)
    {
      IKsControl pControl = CiFilter as IKsControl;
      if (pControl == null) return false;

      DD_CAM_MENU_REPLY Reply;

      Reply.Id = _MenuId;
      Reply.Choice = choice;

      // Initialize unmanged memory to hold the struct.
      IntPtr pReply = Marshal.AllocHGlobal(Marshal.SizeOf(Reply));
      try
      {
        // Copy the struct to unmanaged memory.
        Marshal.StructureToPtr(Reply, pReply, false);

        KSMETHOD KsMethod = new KSMETHOD(KSMETHODSET_DD_CAM_CONTROL,
                                         (Int32)KSMETHOD_DD_CAM_CONTROL.KSMETHOD_DD_CAM_MENU_REPLY,
                                         KSMETHOD_TYPE_SEND);
        Int32 dwReturned = 0;
        Int32 hr = pControl.KsMethod(ref KsMethod, Marshal.SizeOf(KsMethod),
                                     pReply, Marshal.SizeOf(Reply),
                                     ref dwReturned
          );
        return hr == 0;
      }
      finally
      {
        // Free the unmanaged memory.
        Marshal.FreeHGlobal(pReply);
      }
    }
Exemplo n.º 11
0
    /// <summary>
    /// Closes the CI menu
    /// </summary>
    /// <returns></returns>
    public bool CloseCIMenu()
    {
      IKsControl pControl = CiFilter as IKsControl;
      if (pControl == null) return false;

      KSMETHOD KsMethod = new KSMETHOD(KSMETHODSET_DD_CAM_CONTROL,
                                       (Int32)KSMETHOD_DD_CAM_CONTROL.KSMETHOD_DD_CAM_CLOSE_MENU,
                                       KSMETHOD_TYPE_SEND);

      Int32 dwReturned = 0;
      Int32 hr = pControl.KsMethod(ref KsMethod, Marshal.SizeOf(KsMethod),
                                   IntPtr.Zero, 0,
                                   ref dwReturned
        );
      return hr == 0;
    }
Exemplo n.º 12
0
    /// <summary>
    /// Sends the ServiceID to CAM to start decryption.
    /// </summary>
    /// <param name="serviceId">Service ID</param>
    /// <returns>true if successful or no CI available</returns>
    public bool SendServiceIdToCam(Int32 serviceId)
    {
      IKsControl pControl = CiFilter as IKsControl;
      if (pControl == null) return true;

      KSMETHOD KsProperty = new KSMETHOD(KSPROPERTYSET_DD_COMMON_INTERFACE,
                                         (Int32)KSPROPERTY_DD_COMMON_INTERFACE.KSPROPERTY_DD_DECRYPT_PROGRAM,
                                         KSPROPERTY_TYPE_SET);
      Int32 paramSize = Marshal.SizeOf(sizeof (Int32));
      Int32 dwReturned = 0;
      // Initialize unmanged memory to hold the struct.
      IntPtr pSid = Marshal.AllocHGlobal(paramSize);
      Marshal.WriteInt32(pSid, serviceId);
      try
      {
        Int32 hr = pControl.KsProperty(ref KsProperty, Marshal.SizeOf(KsProperty),
                                       pSid, paramSize,
                                       ref dwReturned);
        Log.Log.Debug(
          FormatMessage(String.Format("--> Setting service id {0} for decrypting returned {1}", serviceId, hr)));
        return (hr == 0);
      }
      finally
      {
        // Free the unmanaged memory.
        Marshal.FreeHGlobal(pSid);
      }
    }
Exemplo n.º 13
0
        private bool GetCamMenuText(out DD_CAM_MENU_DATA CiMenu)
        {
            CiMenu = new DD_CAM_MENU_DATA();
            IKsControl pControl = CiFilter as IKsControl;

            if (pControl == null)
            {
                return(false);
            }

            // Initialize unmanged memory to hold the struct.
            Int32  ulMenuSize = 2048;
            IntPtr pCiMenu    = Marshal.AllocHGlobal(ulMenuSize);

            try
            {
                KSMETHOD KsMethod = new KSMETHOD(KSMETHODSET_DD_CAM_CONTROL,
                                                 (Int32)KSMETHOD_DD_CAM_CONTROL.KSMETHOD_DD_CAM_GET_MENU,
                                                 KSMETHOD_TYPE_SEND);
                Int32 dwReturned = 0;
                Int32 hr         = pControl.KsMethod(ref KsMethod, Marshal.SizeOf(KsMethod),
                                                     pCiMenu, ulMenuSize,
                                                     ref dwReturned
                                                     );
                if (hr == 0)
                {
                    Int32 offs = 0;
                    CiMenu.Id         = Marshal.ReadInt32(pCiMenu, offs);
                    offs             += 4;
                    CiMenu.Type       = Marshal.ReadInt32(pCiMenu, offs);
                    offs             += 4;
                    CiMenu.NumChoices = Marshal.ReadInt32(pCiMenu, offs);
                    offs             += 4;
                    CiMenu.Length     = Marshal.ReadInt32(pCiMenu, offs);
                    offs             += 4;

                    // check if we already received this menu, then ignore it.
                    // otherwise we would do an endless processing.
                    if (CiMenu.Id == _MenuId)
                    {
                        return(false);
                    }

                    //DVB_MMI.DumpBinary(pCiMenu, 0, dwReturned);

                    CiMenu.Choices = new List <String>();
                    for (int i = 0; i < CiMenu.NumChoices + 3; i++)
                    {
                        IntPtr newPtr = new IntPtr(pCiMenu.ToInt32() + offs);
                        String choice = Marshal.PtrToStringAnsi(newPtr);
                        switch (i)
                        {
                        case 0:
                            CiMenu.Title = choice;
                            break;

                        case 1:
                            CiMenu.SubTitle = choice;
                            break;

                        case 2:
                            CiMenu.BottomText = choice;
                            break;

                        default:
                            CiMenu.Choices.Add(choice);
                            break;
                        }
                        offs += choice.Length + 1;
                    }
                    // remember current received menu id
                    _MenuId = CiMenu.Id;
                }
                //else
                //  Marshal.ThrowExceptionForHR(hr);

                return(hr == 0);
            }
            finally
            {
                // Free the unmanaged memory.
                Marshal.FreeHGlobal(pCiMenu);
            }
        }