s3n0 / e2scripts

some helpful scripts (Python or Shell) for Enigma2
16 stars 13 forks source link

Can you write a script that can reset a CI-Module / ci0 ? #5

Closed CornFlakes999 closed 1 year ago

CornFlakes999 commented 1 year ago

Hi, First off: I'm sorry I opened this as an "issue" as this is more of an feature request. I was trying to make a script to automatically reset a CI Module, but I had no luck so far. Thru a Google search I came upon your scripts. Currently it's possible to reset a CI Module by going to Menu > Settings > Decryption & Parental Control > Common Interface and then selecting "Reset" on either Slot1 or Slot2. Since going thru the menus is a little cumbersome and I would like to automate it, I was hoping for a script that can be run with a CronTimer. On Google and various GitHub pages I found stuff like "eDVBCI_UI.getInstance().setReset(slot)" and `int eDVBCIInterfaces::reset(int slotid) { eDVBCISlot *slot;

if( (slot = getSlot(slotid)) == 0 )
    return -1;

return slot->reset();

}` but I'm not code-smart enough to turn this into a script. Do you know if this can be done?

Thanks

s3n0 commented 1 year ago

Hi.

  1. the source code you attach is the C-language, which is used mainly at the system level in Linux set-top boxes... however, in the case of Enigma2 (GUI), in Linux set-top boxes, the Python language is used

  2. I don't know what exactly is meant by the term "CI+ Module reset" ... or ... for what purpose you need it ? maybe there is a solution on a completely different basis 🤔

  1. what I am writing are only Shell (Linux) and Python scripts... of course you can reset the CI+ interface also via a shell-script, but you have to find some way for this reset, via Linux Shell (for example, maybe it can be done with using the OpenWebif interface in Linux set-top boxes ?! I don't really know... I didn't look it up 😏)
CornFlakes999 commented 1 year ago

Hi,

Thanks for your answer. Let's see:

  1. Sorry I wasn't aware this was the wrong programming language. Maybe this one helps » https://github.com/openatv/enigma2/blob/7.0/lib/python/Screens/Ci.py This one should be Python (hopefully?). It's the whole menu that is (via gui) accessible on Setup > Common Interface. On Line 521 of that is the Code that initiates the "reset" when you click on it on the menu.
  2. To explain better. CI Reset basically reloads the Modul. It kinda does the same as if you were to pull and re-insert the module (It's not CI+ specific, works on CI or rather any Common Interface-Module). Enigma2 has it in it's menu structure to select "reset" which kinda does this in a software kind of way [hope that explanation is better ..]
  3. Together with a friend I found a solution that would be a shell command (that can also be issues directly thru Terminal in open Webif), sadly it only appears to work on Gigablue Boxes, not VU.

If anything still isn't explained well enough (or if there is no shell / phython option) let me know. And thanks again for responding so far!

s3n0 commented 1 year ago

What exactly did the solution look like for the linux shell that you mention - for the purpose of resetting the CI (interface or module)?

CornFlakes999 commented 1 year ago

This is the Shell command that works on Gigablue » sg_reset -d /dev/ci0 -N -v As far as I understand (I'm not a coder in any language, but can kinda understand how stuff works or what code means when I read it) this code simply resets the whole ci0 device in enigma2/linux regardless of the fact of a module is present or not. On Gigablue Boxes I (and a friend) tested, this worked. However on VU devices this code errored and gave a "not supported" I assume that on VU Devices the Common Interface adapter is not a SCSI device ... Also if you have a Enigma2 Box at hand, you can find the "reset" Option provided in the GUI under Menu > Setup > Decryption > Common Interface > Reset. If you don't have a box and/or module handy, I can also film it off my TV screen. Basically the reset option helps if the module isn't working correctly and saves the need to physically remove/reinsert it. And I was hoping for something automatic, so I can run it as a crontimer every day at night. Hope this makes sense!

CornFlakes999 commented 1 year ago

Just saw an earlier questions of yours I didn't answer. From what I know, it doesn't matter if the scripts resets the modul itself (like in the gui option) or if the whole adapter resets. As far as I know for the module both would have the same result as if I were to remove and reinsert it.

The purpose for it is also (mostly) simple. The modul itself works great in Enigma2. But some channels stop after 24H (maybe you heard of the swiss Kabelio module). To make them work again, one either has to restart the CI+ Helper if installed, select "Reset" in the Common Interface Setup Menu in Enigma or remove and reinsert it. Basically anything that causes the menu to init.

s3n0 commented 1 year ago

Invoking a Python script (source code) other than in the internal structure of Enigma2 / Python and also outside the operation of the Enigma2-GUI itself is a bit more difficult.

The Python source code what you link to me, works a little differently. It imports and uses the source code (module) that goes into the "enigma" core (a binary file, originaly written in C-language), after it is compiled - from here: https://github.com/openatv/enigma2/tree/master/lib/dvb_ci There are functions for controlling the DVB CI, at the level of the operating system (hardware or via "system drivers").

That's complicated system programming. I don't want to do that :). I haven't done "system programming" for perhaps 20 long years :). So I probably can't advise you with a system approach to resetting / restarting DVB CI.

By the way ...

This tool sg_reset is also found in OpenATV 7.2. I own a Formuler F4-Turbo and a Vu+ Solo SE V2 and both have OpenATV 7.2 running. It works on both. I tried using the command you mentioned and it works.

You can try the linux shell command: sg_reset --help And then also your command: sg_reset -d /dev/ci0 -N -v If there is an error SG_SCSI_RESET not suppoprted, then you have to look for causes and other solutions :).

I also think there should be a solution for this problem other than such a hard reset of the hardware module (HardCAM).

CI modules are designed to run independently. Are you not also using a SoftCAM that would try to gain access to this HardCAM device of yours (/dev/ci0) ?

CornFlakes999 commented 1 year ago

I have to go to work in a few minutes, so I keep this message short and answer properly later tonight. The sg_reset command seem to be present on my VU Ultimo 4k too. (OpenATV 7.0 on all devices) The problem is, that it does not reset like on the Gigablue. On the Gigablue typing » sg_reset -d /dev/ci0 -N -v « Gives this output: sg_reset: starting device reset sg_reset: completed device reset But on the Vu Ultimo 4K (and a non 4K Ultimo I have for testing) the output is: sg_reset: starting device reset sg_reset: SG_SCSI_RESET not supported (for value=0x101) sg_reset: SG_SCSI_RESET failed: Invalid argument

Yes, I also have a SoftCAM installed (OScam) but as far as I know OScam can't/doesn't touch the ci0 and ci1 devices, only cards on sci0, sci1 etc. But I can be mistaken here. In either case, if I reset the module via the GUI, oscam doesn't restart or reacts in any case, so as far as I can tell it doesn't try to access the Common Interface Controller or any inserted CI-Module.

I also think there should be a solution for this problem other than such a hard reset of the hardware module (HardCAM).

I also agree that an option that isn't hard resetting the controller is better. Something Software based would be best. That's why I hoped maybe you know something or have an idea, since you you - in contrast to me - can code. I wan't aware that the code in the CI.py is that complex. I was under the impression that someone with more knowledge than me could isolate the "reset" part or it, so it can be run directly. But I understand that if it that interchanged with the System code it's better not to mess with that! That's why I asked :) The only thing I did was use python a few months back to modify the AutoTimer plugin haha

CornFlakes999 commented 1 year ago

Then... also try this one command instead: sg_reset -d /dev/dvb/adapter0/ci0 -N -v

That device I know doesn't exist on my VU. The only ones I have (within the /dev/dvb/adapter0/ are ca0, ca1 and a few more numbers (no typo, it's cA not cI) As far as I know that ca0 device is the one that OScam is using, I seem to recall that I saw that in a log file once...

s3n0 commented 1 year ago

Yes, it is true that SoftwareCAM and HardwareCAM work separately. But OSCam handles these CAMs as well and can even work with them somehow (if I'm not mistaken). Here is a small example and proof that OSCam also looks at these HardwareCAMs: https://www.linuxsat-support.com/thread/88049-oscam-and-ci-module/

I deleted the previous message about /dev/dvb/adapter0/* because I'm not sure it will work with that.

I really don't know. You can try to stop OSCam (/etc/init.d/softcam stop) and then use the HardCAM reset command again.

BTW, in my Vu+ Solo SE V2 this sg_reset works (I use OpenATV 7.2 in it and also CCcam-2.3.0):

root@vusolose:~# sg_reset -d /dev/ci0 -N -v
sg_reset: starting device reset
sg_reset: completed device reset
root@vusolose:~# 
CornFlakes999 commented 1 year ago

Thanks again for your effort and tips. Sorry for the delayed response, but after work I tried and do some more research. Sadly as it appears now (and with what I learned from you) there is no easy way to achieve what I'm looking for ... I tried the sg_reset command again, both with oscam turned off (and even uninstalled) but for some reason on the VU Ultimo 4K it always results in the error I posted a few messages earlier. There is only one last option I think I can try (and maybe you have some advice on that too), is by using the hotkey feature and modify it's default behavior. First I came across this: https://github.com/openhdf/enigma2/blob/master/lib/python/Screens/Hotkey.py In there I can see that I can map the "CI Setup Menu" to a hotkey [line 278] (in my case I used "Yellow", so in my enigma2 config I now have this set » config.misc.ButtonSetup.yellow=Module/Screens.Ci/CiSelection At least now I have access to the CI Setup Menu with a single button. What I'm reasearching/trying now - and maybe you have some knowledge about it - is, if I can set the "Reset" Option from that Menu directly onto the hotkey by adding something like /1 or /Reset behind it. A few lines down, this seem to be the pattern for the Standby/Shutdown Menu options like Module/Screens.Standby/TryQuitMainloop/3 and Module/Screens.Standby/Standby among a few others. With the "just CI Setup Menu" I currently made this .sh script to follow a key sequence: #!/bin/sh wget -q -O - http://127.0.0.1/api/remotecontrol?command=400 # Yellow - The HotKey wget -q -O - http://127.0.0.1/api/remotecontrol?command=108 # Arrow Down - Select Menu Option wget -q -O - http://127.0.0.1/api/remotecontrol?command=352 # OK - Confirm Reset wget -q -O - http://127.0.0.1/api/remotecontrol?command=174 # Exit - Close Menu In itself this script works and can be set as an CronTimer, however it isn't fail-safe. For example: If at the time of the execution the EPG is open, the behavior of the Yellow Key (my HotKey) would still default to EPG Search. So instead of opening the CI Setup Menu, it does the EPG Search, Moves one down and OK and Exit on that. Similar with other Screens open...

Either I find a solution to make this behaviour "Global and no matter what" or I'm out of ideas, at which point I think I have to accept that I can't find a working solution for my Vu Ultimo 4K.

In any case, I thank you for your help and tips! It's too bad, that restarting Enigma (init 4 and init 3) also stops running recordings or I would simply use that...

s3n0 commented 1 year ago

Hi.

Calling Enigma2 / Python modules other than through the tree structure of this Enigma2 / Python is a bit more complicated. This is because there are various dependencies on other, including included and nested modules, in this code structure.

It can be done, but in a difficult way.

It would be simpler to make a primitive plugin that will check the time and simply restart your DVB CI interface at a certain time. Plugin in python code, i.e. it will be embedded in Enigma2 / Python code. And thus, without any problems, this plugin can handle all relevant services, functions or algorithms (modules + their classes) in the Enigma2 / Python complete structure.

A simple plugin is not a problem to create if you want.

You only set on/off in it and also set the time there.

You don't use Skype by any chance ? You can also write to me via Skype.

I no longer use modern communication applications (WhatsApp, Discord, Telegram, Viber, Messenger, etc.) or even dead ones, of which there are several (IRC client/server, Skype, ICQ). There are more and more of them and I'm tired of always installing and registering for more and new ones :). Moreover, it is still not guaranteed that the person in question will use the same 2-3 communication clients that I use :). So I only have Skype primarily :).

CornFlakes999 commented 1 year ago

Hi again,

oh wow. The plugin idea sounds interesting. I don't know how to write a whole plugin in Python, so I myself didn't think of that haha. What I did once was modify a handful of values in the .py files that manage timers and autotimer, so I can set start/end times with seconds and not just hours and minutes. But If you can do that, that would be awesome!!!

Yeah, a plugin that is just an toggle that fires at a preset or selectable time to restart that DVB-CI interface sounds exactly like what would do the trick here (:

As for communicating, honestly I haven't even heard of any of these "modern" applications too except WhatsApp. What I do have it the good old email? Skype I think I had once, but would need to install it first and find out what my username was... If email works, I think I can write it down here (and once you got it remove it again, so it's not all open on the internet). WhatsApp as the only modern app thingy would work as well, but if skype is preferred I could check and see what my login was there.

Thanks in advance!

s3n0 commented 1 year ago

Or if you want, a shell script function for RCU control with the help of OpenWebif, I already have it ready :). But that's quite "amateur" in my opinion. Although it works correctly.


#### webif_rc - WebIf Remote Control
#### a function for calling any RCU button - via the OpenWebif (Enigma2 Web-GUI)
#### usage syntax:      webif_rc "keycode:pause:repeat" "keycode:pause:repeat" "keycode:pause:repeat" "end"
#### Remote Control Unit - ID code list :   https://github.com/openatv/enigma2/blob/7.0/lib/python/keyids.py
webif_rc()
{
   arr=("$@")
   i="0"
   #echo ${arr[@]}
   until [ ${arr[i]} == "end" ] || [ $i -gt 100 ]
   do
      key=$(  echo ${arr[i]} | cut -f1 -d ':'  )
      tim=$(  echo ${arr[i]} | cut -f2 -d ':' | cut -f1 -d ':'  )
      rep=$(  echo ${arr[i]} | cut -f3 -d ':'  )
      #rep=${!rep}   # convert string to value
      #echo --- $i --- ${arr[i]} ------------ key=$key -- time=$tim -- repeat=$rep
      until [ $rep == "0" ]
      do
         wget -q -O - http://127.0.0.1/web/remotecontrol?command=$key > /dev/null 2>&1
         sleep 0.1s
         sleep $tim
         rep=$[$rep-1]
      done
      i=$[$i+1]
   done
}

# example:

webif_rc "364:2.0:1" "158:0.1:1"  "108:0.5:4" "352:0.8:1" "108:0.3:1" "352:2.0:1" "103:0.5:2" "352:0.5:1" "end"
####      FAV         Recall       DOWN x 4    OK          DOWN        OK          UP x 2      OK
CornFlakes999 commented 1 year ago

I think the plugin idea to restart the DVBCI at a fixed or selectable time would be the best! Seems more failsafe and straight forward. Also you can publish the plugin here and I'm sure there are many more that have a use out of it. I think I mentioned it in a previous message, for me the use of it is to get a Swiss Kabelio Module working properly. Contrary to most oder CI/CI+ Module, it needs to do an handshake with the host device roughly every 24H. This isn't needed or implemented in any enigma2 image. The work around it to, as I said, either remove and reinsert the module or do anything else to have it power cycle (for example a full GUI or Box restart works too, but has is drawbacks) So a plugin that does a simple restart of the DVB-CI seems like the best solution (also since in this way it wouldn't impact much other stuff that might be going on in the Box - like recordings, Oscam etc.) You want my email for communication?

s3n0 commented 1 year ago

I'll try to make a plugin quickly... from an already made and simple plugin designed for refreshing the EPG. I made the EPG plugin a long time ago and replaced it later with a Python script (because that's better and it can also be done via a shell script). I will use the old simple plugin algorithm. I will try to remake / develop the plugin for you.

CornFlakes999 commented 1 year ago

Wow! Thanks so much already. And no rush. I'm happy about it any time (: If you want/need to hardcode a time of day into it, anything between 02:00 - 03:00 would be best.

s3n0 commented 1 year ago

OK, the plugin "CAMautorestart" is ready... you can try it... just copy it to the folder: /usr/lib/enigma2/python/Plugins/Extensions/ ... then restart the Enigma2-GUI

EDIT:

I created the IPK and DEB installers. Of course, I also added them to Github. It will probably be better this way.

CornFlakes999 commented 1 year ago

Awesome!! I'll download and test it now. I'll let you know soon (:

CornFlakes999 commented 1 year ago

This Plugin is exactly what I was hoping for!!! Installed it and tried with the "Launch Now" Option. Within seconds after execution I got the "CI Message" Intializing from the Module, just like if the modul has just been inserted. I've set the Auto Time to 02:55 (night) and repeat every 1 day! I'd be happy to give another feedback tomorrow, after the first automatic restart, but this seem to be exactly what I was looking for. I never imagined this can be done as a plugin, but yeah now that I also saw the code on here it makes. Basically you took the reset command I was referring too in earlier messages and instead of putting it as a script or similar you made a plugin around it. And with the option to set the time it is like 110% (= Thank you so much! I'll also let my friend know about this too now, so he can test it as well!

Btw. if you have a donation account for your developemnt stuff here or elsewhere let me know. I'd be happy to send you something as compensation for your work next week (once I get my paycheck) After all you basically made a plugin for me now! I'm very grateful!

s3n0 commented 1 year ago

I don't have an official donate account. In addition, Enigma2 is distributed as a free project, and everything else that does not provide extra-paid services should be distributed accordingly. So even this plugin using Enigma2 code should be distributed as open source (free). You can pay for free time... but you don't have to :). It only cost me 1-2 hours of work since I rebuilt my older plugin (EPG Download & Replace)... so that's all OK :).

Please test the plugin and in case of any error, you can write a new ISSUE... but... please in the "e2plugins" subdirectory on my github and not in the "e2scripts" :).