1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
package main
import (
"encoding/binary"
"encoding/hex"
"flag"
"fmt"
"log"
"net"
)
var service = flag.String("service", "192.168.240.20:33333", "PBX CTI Service")
func init() {
flag.Parse()
}
/* A-ASSOCIATE Request
*
* 60 23 AARQ-apdu
* 80 02 07 08 protocol-version { version1 }
* A1 07 application-context-name
* 06 05 2B 0C 00 81 5A { 1 3 12 0 218 }
* BE 14 user-information
* 28 12
* 06 07 2B 0C 00 82 1D 81 48 derect-reference { 1 3 12 0 285 200 }
* A0 07 single-ASN1-type
* (ACSEUserInfomrationForCSTA)
* A0 05 newDefinition
* 03 03 00 08 00 cSTAVersion { versionFive }
*/
var associate = []byte{
0x60, 0x23,
0x80, 0x02, 0x07, 0x80,
0xA1, 0x07,
0x06, 0x05, 0x2B, 0x0C, 0x00, 0x81, 0x5A,
0xBE, 0x14,
0x28, 0x12,
0x06, 0x07, 0x2B, 0x0C, 0x00, 0x82, 0x1D, 0x81, 0x48,
0xA0, 0x07,
0xA0, 0x05,
0x03, 0x03, 0x00, 0x08, 0x00,
}
/* A-ACCOCIATE Result
* 61 2F AARE-apdu
* 80 02 07 80 protocol-version { version1 }
* A1 07 application-context-name
* 06 05 2B 0C 00 81 5A { 1 3 12 0 218 }
* A2 03 result
* 02 01 00 accepted
* A3 05 result-source-diagnostic
* A1 03 acse-service-user
* 02 01 00 no-reason-given
* BE 14 user-information
* 28 12
* 06 07 2B 0C 00 82 1D 81 48 direct-reference { 1 3 120 285 200 }
* A0 07 single-ASN1-type
* (ACSEUserInformationForCSTA)
* A0 05 newDefinition
* 03 03 00 08 00 cSTAVersion { versionFive }
*/
/* A-REJECT
* 61 19 AARE-apdu
* 80 02 07 80 protocol-version { version1 }
* A1 07 application-context-name
* 06 05 2B 0C 00 81 5A { 1 3 12 0 218 }
* A2 03 result
* 02 01 01 rejected-permanent
* A3 05 result-source-diagnostic
* A1 03 acse-service-user
* 02 01 01 no-reason-given
*/
/* A-RELEASE Request
*
* 62 00 RLRQ-apdu
*/
var release = []byte{0x62, 0x00}
/* A-RELEASE Result
*
* 63 00 RLRE-apdu
*/
/* SystemStatus Request
* A1 0C ROSE-Invoke
* 02 01 01 invokeId present: 1
* 02 02 00 D3 opcode local: 211
* 30 03 SystemStatusArgiment
* 0A 01 02 systemStatus normal
*/
/* SystemStatus Result
* A2 0B ROSE-ReturnResult
* 02 01 01 invokeId present: 1
* 30 06 SystemStatusResult
* 02 02 00 D3 opcode local: 211
* 05 00 noData
*/
var status = []byte{
0xA2, 0x0B,
0x02, 0x01, 0x01,
0x30, 0x06,
0x02, 0x02, 0x00, 0xD3,
0x05, 0x00,
}
/* A-ABORT
* 64 03 ABRT-apdu
* 80 01 00 ABRT-source: acse-service-user
*/
var nbo = binary.BigEndian // Network Byte Order
func send(c net.Conn, b []byte) {
size := int16(len(b))
if err := binary.Write(c, nbo, size); err != nil {
log.Fatal(err)
}
if err := binary.Write(c, nbo, b); err != nil {
log.Fatal(err)
}
}
func recv(c net.Conn) []byte {
var size int16
if err := binary.Read(c, nbo, &size); err != nil {
log.Fatal(err)
}
r := make([]byte, size)
if err := binary.Read(c, nbo, r); err != nil {
log.Fatal(err)
}
return r
}
func dump(b []byte, dir string) {
log.Println(dir)
fmt.Println(hex.Dump(b))
}
func Associate(c net.Conn) {
dump(associate, ">>> Send associate")
send(c, associate)
in := recv(c)
dump(in, "<<< Recv associate")
}
func Release(c net.Conn) {
dump(release, ">>> Send release")
send(c, release)
in := recv(c)
dump(in, "<<< Recv release")
}
func Status(c net.Conn) {
in := recv(c)
dump(in, "<<< Recv status")
out := status
out[4] = in[4]
dump(out, ">>> Send status")
send(c, out)
}
func main() {
conn, err := net.Dial("tcp", *service)
if err != nil {
log.Fatal(err)
}
defer conn.Close()
Associate(conn)
defer Release(conn)
for i := 0; i < 3; i++ {
Status(conn)
}
}
|