参考
一、国标gb28181信令交互流程
通过happytime客户端模拟器实现效果
1、注册
- 客户端发送
REGISTER
信令到服务器 - 服务器需要开启认证,则会返回
401 Unauthorized
,并在WWW-Authenticate
中携带认证相关信息,如果服务器没有开启认证,则直接回复SIP/2.0 200 OK
- 客户端收到
401 Unauthorized
之后,则组装REGISTER
并携带计算好的认证信息Authorization
- 服务端收到
REGISTER
消息,则返回SIP/2.0 200 OK
说明认证注册成功,
注册密码验证原理参考:GB28181 设备注册密码验证算法
交互日志如下:
[2023-05-23 11:02:52] : [INFO] init_local_net, sony
[2023-05-23 11:02:52] : [INFO] init_local_net, hsip.local_ipstr = 192.168.0.102
[2023-05-23 11:02:52] : [INFO] net_buf_init, num = 32
[2023-05-23 11:02:52] : [INFO] hdrv_buf_init, num = 256
[2023-05-23 11:02:52] : [INFO] sip_start, create net rx thread sucessful
[2023-05-23 11:02:52] : [INFO] sip_start, create sip main thread sucessful
[2023-05-23 11:02:52] : [INFO] sip:34020000001110000099@4401007844
[2023-05-23 11:02:52] : [INFO] sip_user_socket_init, sip local port 5066
[2023-05-23 11:02:52] : [INFO] cm_start_reg, sip_user_socket_init finish
[2023-05-23 11:02:52] : [INFO] cm_start_reg, sip_build_register_normal_msg finish
[2023-05-23 11:02:52] : [DEBUG] sip_send_msg, client-->server :
REGISTER sip:44010078442009000089@4401007844 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.102:5066;rport;branch=z9hG4bK504c6
From: <sip:34020000001110000099@4401007844>;tag=00001560
To: <sip:34020000001110000099@4401007844>
Contact: <sip:34020000001110000099@192.168.0.102:5066>
Call-ID: 00002B2300007CBE@192.168.0.102
CSeq: 1 REGISTER
Max-Forwards: 70
Expires: 3600
User-Agent: Happytime GB28181 Device V6.2
Content-Length: 0
[2023-05-23 11:02:52] : [INFO] cm_start_reg, user_tx_free_msg finish
[2023-05-23 11:02:54] : [DEBUG] sip_msg_rx, server-->client :
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 192.168.0.102:5066;rport=15692;received=192.168.0.44;branch=z9hG4bK504c6
From: <sip:34020000001110000099@4401007844>;tag=00001560
To: <sip:34020000001110000099@4401007844>;tag=833794167
Call-ID: 00002B2300007CBE@192.168.0.102
CSeq: 1 REGISTER
Contact: <sip:44010078442009000089@182.xx.xx.73:15692>
User-Agent: EasyGBS v200511
Content-Length: 0
WWW-Authenticate: Digest realm="4401007844",nonce="301745769f4fc5498732b9b40d8febc5"
[2023-05-23 11:02:54] : [DEBUG] sip_send_msg, client-->server :
REGISTER sip:44010078442009000089@4401007844 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.102:5066;rport;branch=z9hG4bK504c9
From: <sip:34020000001110000099@4401007844>;tag=00001560
To: <sip:34020000001110000099@4401007844>
Contact: <sip:34020000001110000099@192.168.0.102:5066>
Call-ID: 00002B2300007CBE@192.168.0.102
CSeq: 2 REGISTER
Max-Forwards: 70
Expires: 3600
User-Agent: Happytime GB28181 Device V6.2
Authorization: Digest username="34020000001110000099",realm="4401007844",nonce="301745769f4fc5498732b9b40d8febc5",response="af4a6f526d4b6fd1781ee32f98b118dd",uri="sip:44010078442009000089@4401007844"
Content-Length: 0
[2023-05-23 11:02:54] : [DEBUG] sip_msg_rx, server-->client :
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.0.102:5066;rport=15692;received=192.168.0.44;branch=z9hG4bK504c9
From: <sip:34020000001110000099@4401007844>;tag=00001560
To: <sip:34020000001110000099@4401007844>;tag=717794764
Call-ID: 00002B2300007CBE@192.168.0.102
CSeq: 2 REGISTER
Contact: <sip:44010078442009000089@182.xx.xx.73:15692>
Expires: 3600
User-Agent: Easy SIP Server
Content-Length: 0
[2023-05-23 11:02:54] : [INFO] reg pass!
2、心跳
- 客户端发起
MESSAGE
信令,并且Content-Type: Application/MANSCDP+xml
,发起keeplive心跳请求 - 服务端收到之后回复
SIP/2.0 200 OK
交互日志如下:
[2023-05-23 11:03:25] : [DEBUG] sip_send_msg, client-->server :
MESSAGE sip:44010078442009000089@4401007844 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.102:5066
From: <sip:34020000001110000099@4401007844>;tag=00004823
To: <sip:44010078442009000089@4401007844>
Call-ID: 00006784000018BE@192.168.0.102
CSeq: 2 MESSAGE
Max-Forwards: 70
User-Agent: Happytime GB28181 Device V6.2
Content-Type: Application/MANSCDP+xml
Content-Length: 170
<?xml version="1.0" encoding="GB2312"?>
<Notify>
<CmdType>Keepalive</CmdType>
<SN>1</SN>
<DeviceID>34020000001110000099</DeviceID>
<Status>OK</Status>
</Notify>
[2023-05-23 11:03:25] : [DEBUG] sip_msg_rx, server-->client :
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.0.102:5066
From: <sip:34020000001110000099@4401007844>;tag=00004823
To: <sip:44010078442009000089@4401007844>;tag=407825634
Call-ID: 00006784000018BE@192.168.0.102
CSeq: 2 MESSAGE
User-Agent: Easy SIP Server
Content-Length: 0
3、查询设备目录 queryCatalog
- 服务端主动下发
MESSAGE
信令并且Content-Type: Application/MANSCDP+xml
,发起Catalog查询请求 - 客户端收到之后先回复
SIP/2.0 200 OK
- 客户端接着发送
MESSAGE
信令并且Content-Type: Application/MANSCDP+xml
,发起Response响应,罗列设备和通道信息 - 服务端收到之后回复
SIP/2.0 200 OK
交互日志如下:
[2023-05-23 11:02:57] : [DEBUG] sip_msg_rx, server-->client :
MESSAGE sip:34020000001110000099@192.168.0.44:15692;transport=udp SIP/2.0
Via: SIP/2.0/UDP 182.xx.xx.73:15692;rport=15692;branch=z9hG4bK269797766
From: <sip:44010078442009000089@4401007844>;tag=430797766
To: <sip:34020000001110000099@4401007844>
Call-ID: 275797766
CSeq: 89325 MESSAGE
Max-Forwards: 70
User-Agent: Easy SIP Server
Content-Type: Application/MANSCDP+xml
Content-Length: 156
<?xml version="1.0" encoding="UTF-8"?>
<Query>
<CmdType>Catalog</CmdType>
<SN>683797766</SN>
<DeviceID>34020000001110000099</DeviceID>
</Query>
[2023-05-23 11:02:57] : [WARN] sip_msg_parse, strlen[160] != ctx len[156]!!!
[2023-05-23 11:02:57] : [INFO] sip_request_rx, from user [44010078442009000089]@[4401007844]
[2023-05-23 11:02:57] : [DEBUG] sip_send_msg, client-->server :
SIP/2.0 200 OK
Via: SIP/2.0/UDP 182.xx.xx.73:15692;rport=15692;branch=z9hG4bK269797766
From: <sip:44010078442009000089@4401007844>;tag=430797766
To: <sip:34020000001110000099@4401007844>;tag=000018be
Call-ID: 275797766
CSeq: 89325 MESSAGE
User-Agent: Happytime GB28181 Device V6.2
Content-Length: 0
[2023-05-23 11:02:5