Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify ISAPI to reliably open connections #967

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions pkg/isapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,17 @@ func (c *Client) Dial() (err error) {
}

func (c *Client) Open() (err error) {
link := c.url + "/ISAPI/System/TwoWayAudio/channels/" + c.channel
// Hikvision ISAPI may not accept a new open request if the previous one was not closed (e.g.
// using the test button on-camera or via curl command) but a close request can be sent even if
// the audio is already closed. So, we send a close request first and then open it again. Seems
// janky but it works.

err = c.Close()
if err != nil {
return err
}

link := c.url + "/ISAPI/System/TwoWayAudio/channels/" + c.channel
req, err := http.NewRequest("PUT", link+"/open", nil)
if err != nil {
return err
Expand Down Expand Up @@ -124,8 +133,8 @@ func (c *Client) Open() (err error) {
}

func (c *Client) Close() (err error) {
link := c.url + "/ISAPI/System/TwoWayAudio/channels/" + c.channel + "/close"
req, err := http.NewRequest("PUT", link+"/open", nil)
link := c.url + "/ISAPI/System/TwoWayAudio/channels/" + c.channel
req, err := http.NewRequest("PUT", link+"/close", nil)
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/tcp/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ func Do(req *http.Request) (*http.Response, error) {
)
case "auth":
nc := "00000001"
cnonce := "00000001" // TODO: random...
// TODO: Random cnonce
// Here is temp static cnonce of required 32 bytes
cnonce := "ZDlmODczZTk2NjQyZTQ4OGQ5ZGEzOTI3YTc5Y2Q0ZGM="
response := HexMD5(ha1, nonce, nc, cnonce, qop, ha2)
header = fmt.Sprintf(
`Digest username="%s", realm="%s", nonce="%s", uri="%s", qop=%s, nc=%s, cnonce="%s", response="%s"`,
Expand Down