roleoroleo / sonoff-hack

Custom firmware for Sonoff GK-200MP2B camera
GNU General Public License v3.0
200 stars 45 forks source link

Onvif on synology surveillance station #16

Closed alekslyse closed 1 month ago

alekslyse commented 3 years ago

Have anyone made this work with synology surveillance station onvif. Onvif works on my phone apps so it’s working, but synology say can’t read capabilities. Any suggestions?

Rtsp works in synology, but would need ptz

roleoroleo commented 3 years ago

It's a known issue. Please, send me a dump of the network traffic during the negotiation, if you are able. This is tcpdump: tcpdump.gz

EpicLPer commented 3 years ago

As a kind of related but somewhat offtopic still reply: Blue Iris was not automatically able to detect the High Quality Stream via the “Find/Inspect” button. Normally afaik that URL should be sent via the ONVIF discovery, right? But PTZ there works just fine :)

alekslyse commented 3 years ago

It's a known issue. Please, send me a dump of the network traffic during the negotiation, if you are able. This is tcpdump: tcpdump.gz

Just a tcp dump from the synology to the camera or a general tcp dump whie trying to add the camera

roleoroleo commented 3 years ago

The traffic from the synology and the camera when you try to add the onvif cam.

alekslyse commented 3 years ago

Here is a tcpdump 192.168.1.204 is the camera. pasword and username is set as test/test

test.pcapng.zip

alekslyse commented 3 years ago

For reference I also took a tcpdump on a onvif camera that works. 192.168.1.52 (NOT this hack, just for a reference of something thats working)

lastestov.pcncap.zip

roleoroleo commented 3 years ago

Thank you. The 1st capture is ok. The 2nd one containts only request packets, reponses are missing.

alekslyse commented 3 years ago

The test.pcapng.zip is the one that doesnt work (error), the second lastestov.pcncap.zip works. The test.pcapng.zip is the sonoff onvif hack

roleoroleo commented 3 years ago

As a kind of related but somewhat offtopic still reply: Blue Iris was not automatically able to detect the High Quality Stream via the “Find/Inspect” button. Normally afaik that URL should be sent via the ONVIF discovery, right? But PTZ there works just fine :)

Onvif discovery should send only the generic onvif url, not the streams.

roleoroleo commented 3 years ago

@alekslyse Please try this binary: onvif_srvd.gz

alekslyse commented 3 years ago

Progress; It now detects the capabilities, but does not get the stream url. Still .204 ip on the camera.

onviftest.pcncap.zip

Screenshot 2020-10-15 at 15 35 47
alekslyse commented 3 years ago

For reference I did two captures, attached. onviftest2.pcncap with 192.168.1.204 with clicking the button test connection producing no picture

the other file onviftestothercam.pcncap with 192.168.1.52 is a known working onvif camera with clicking the test connection producing picture.

Maybe that will clarify what response the two cameras get

Archive 2.zip

roleoroleo commented 3 years ago

In the capture file of the working cam I can't find the response packets. Could you check the capture procedure?

alekslyse commented 3 years ago

In the capture file of the working cam I can't find the response packets. Could you check the capture procedure?

Just a regular sudo /usr/sbin/tcpdump -w /volume1/tmp.pcncap

Its the same on both files. Any arguments I should add?

roleoroleo commented 3 years ago

I don't know what the difference. Try to capture the traffic on the synology, if it's possible.

However I checked the traffic and it seems synology requires dynamic profile creation. This device does not support this function (CreateProfile and DeleteProfile). And I don't understand why synology should ask for this feature... In my opinion it is wrong.

alekslyse commented 3 years ago

its captured on the synology directly. I assume onvif will not work on the synology then?

roleoroleo commented 3 years ago

Onvif it's not a good standard. Each manufacturer creates its own implementation. There are a lot of compatibility problems.

roleoroleo commented 3 years ago

Another try, if you can... onvif_srvd.gz

alekslyse commented 3 years ago

Nothing better. Its a lot of chatter between the cam and the onvif, but when it ask for the add of profile it seems like it gives a 400 bad request back

onvif20.pcncap.zip

alekslyse commented 3 years ago

onvif device manager on windows wont even connect to the camera so something is strange

alekslyse commented 3 years ago

I see another strange thing; If I reboot the camera, and after the voice; If I use onvif device manager on windows and click refresh I get into the onvif settings when the camera start to turn at bootup. After its done turning no more onvif or able to connect anymore

roleoroleo commented 3 years ago

The versions I'm sending you are experimental. There is an alpha implementation of event management. So it's not stable. Use it only to test the synology.

One more time around the block: onvif_srvd.gz I changed the soap fault returned with CreateProfile and DeleteProfile. I added the GetGuaranteedNumberOfVideoEncoderInstances function.

roleoroleo commented 3 years ago

If this doesn't work I don't know ho to solve the issue. Probably I need to create a fake CreateProfile function.

alekslyse commented 3 years ago

The versions I'm sending you are experimental. There is an alpha implementation of event management. So it's not stable. Use it only to test the synology.

One more time around the block: onvif_srvd.gz I changed the soap fault returned with CreateProfile and DeleteProfile. I added the GetGuaranteedNumberOfVideoEncoderInstances function.

That seemed to turn off the whole onvif. It could not find the cam on port 80 or load anything

roleoroleo commented 3 years ago

I will check it.

roleoroleo commented 3 years ago

I fixed a lot of bugs: onvif_srvd.gz

alekslyse commented 3 years ago

No still no connection. another dump here. with the two last releases the onvif communication is never happening.

No much exciting in the log, still with filter ip.src == 192.168.1.204 or ip.dst == 192.168.1.204 - just communication failures (its the correct ip etc - can control through web ui)

Just for a ps I do NOT think synology support onvif 1.0 or 1.1, but those should be very old. I dont know what version this one is using.

onvif50.pcncap.zip

roleoroleo commented 3 years ago

I tested it again and it works (apart from a memory leak problem). Try to run it manually with --no_fork and --no_close options.

alekslyse commented 3 years ago

Im not sure how you mean with running it manually? how?

roleoroleo commented 3 years ago

Connect to the cam with ssh and run the following commands:

killall onvif_srvd
. /mnt/mmc/sonoff-hack/script/env.sh
onvif_srvd --no_fork --no_close --pid_file /var/run/onvif_srvd.pid --model "Sonoff Hack" --manufacturer Sonoff --firmware_ver 0.0.3 --hardware_id GK-200MP2B --serial_num a6300087b8 --ifs eth0 --port 80 --scope onvif://www.onvif.org/Profile/S --name Profile_0 --width 1920 --height 1080 --url rtsp://hack:hack@%s/av_stream/ch0 --snapurl http://%s:8080/cgi-bin/snapshot.sh --type H264 --name Profile_1 --width 640 --height 360 --url rtsp://hack:hack@%s/av_stream/ch1 --snapurl http://%s:8080/cgi-bin/snapshot.sh --type H264 --ptz --move_left "/mnt/mmc/sonoff-hack/bin/ptz -a left" --move_right "/mnt/mmc/sonoff-hack/bin/ptz -a right" --move_up "/mnt/mmc/sonoff-hack/bin/ptz -a up" --move_down "/mnt/mmc/sonoff-hack/bin/ptz -a down" --move_stop "/mnt/mmc/sonoff-hack/bin/ptz -a stop" --move_preset "/mnt/mmc/sonoff-hack/bin/ptz -f /mnt/mmc/sonoff-hack/etc/ptz_presets.conf -a go_preset -n %t" --set_preset "/mnt/mmc/sonoff-hack/bin/ptz -f /mnt/mmc/sonoff-hack/etc/ptz_presets.conf -a set_preset -e %n -n %t"
alekslyse commented 3 years ago

I just get a segment error

Screenshot 2020-10-19 at 13 42 26
alekslyse commented 3 years ago

without --no_fork no segment error, but still no onvif

roleoroleo commented 3 years ago

Strange behavior.

alekslyse commented 3 years ago

Yeah. Could it be because I set it up in the app first? The old rtsp stream still works. I tried to reinstall your hack (format sd), but still same issue.

alekslyse commented 3 years ago

Some progress; Your latest file does not work, it just give segmentation failure. (im using wifi). changed the start file to the wifi and serial just to be sure but still segmentation failure. If your camera works on the latest file your sent; how do you setup your camera? wifi / eth / username / password / setup via app. I even tried to reset the camera with your latest, and still it does not even start the onvif server

I has to set username and password to hack for the profiles to work at all

The second to last where you removed the profile thing it does a bit more now. It accepts the profiles, but errors in "Max number of profiles reached"

I also added the console dump with the ps -l after reset of camera and your latest file as well as wireshark dump where it say profiles reached. If we can bypass the profiles reached I think we are on the right path.

SOAP 1.2 fault SOAP-ENV:Receiver[ter:Action] "Max number of profiles reached." Detail: [no detail]

console.txt onvif100.pcncap.zip

roleoroleo commented 3 years ago

The message "Max number of profiles reached." is normal. It's the response of the cam when the client tries to create a dynamic profile (not supported). Segfault is not normal... I will check your capture file.

alekslyse commented 3 years ago

I have no idea what else to do. I have reset the camera, wifi and ethernet, reset your hack etc. with the last one onvif does not start at all. the previous ones it starts and the command works. Its just the last one

roleoroleo commented 3 years ago

If you try the cam with odm, does it work?

alekslyse commented 3 years ago

Not with the last release as it doesn’t start auto or manually. Second to last release it works for 2-3 seconds after the swirling of the camera on boot if I keep clicking connect, then it doesn’t work anymore in odm. Synology recognises second to last too, but dont get the rtsm stream so cant go beyond the setup screen the no more profile gives a internal error

roleoroleo commented 3 years ago

I don't understand. With the last version, does the process crash immediately or after a discovery? The capture you posted contains a long dialog between the client and the cam and it seems that the cam crashes after the CreateProfile message. I'm probably confusing the various versions.

alekslyse commented 3 years ago

Sorry about that. Latest version doesn’t start automatically or by cli (segmentation fault). With that installed its no service running at boot. The latest wireshark is from the second to last. Second to last start automatically and by cli tested both methods

roleoroleo commented 3 years ago

Try this please: onvif_srvd.gz

alekslyse commented 3 years ago

same error. no onvif server started on camera boot, and manual give segment failure. It has to be something that got removed from now the third to last (as the third to last it booted the onvif server etc)

roleoroleo commented 3 years ago

Try to run it with strace: strace.gz

roleoroleo commented 3 years ago

Try to update all with the new 0.0.7

alekslyse commented 3 years ago

I start to wonder if its something wrong with the camera. You guys are running stock cameras or have you done any firmware hacks / opened the cameras before doing this? I assumed it was just uploading it to the camera and boot it (even tried to reset it, plus using ethernet)

Even with .7 onvif wont start at boot. Here is the ps list right after boot

Screenshot 2020-10-23 at 17 46 08 Screenshot 2020-10-23 at 17 44 01

trace.txt

alekslyse commented 3 years ago

strace on the onvif command, plus pictures of the camera info

Screenshot 2020-10-23 at 18 15 53 Screenshot 2020-10-23 at 18 15 49

trace.txt

alekslyse commented 3 years ago

And here is trace with no fork

trace_no_fork.txt

roleoroleo commented 3 years ago

@alekslyse Try this. onvif_srvd.gz

I removed the threads related to event management. If doesn't work, please try again with strace using -f option.

alekslyse commented 3 years ago

Now the onvif starts again, and synology go through its init tests (check capabilities etc), but does not get the rtsp stream and errors out in the profile max. Attached is pcap.

P.S Ip changed so filter in wireshark now is ip.src == 192.168.1.209 or ip.dst == 192.168.1.209

Also did a trace from terminal

trace_new.txt onvif200.pcncap.zip