-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtcap.go
61 lines (53 loc) · 1.04 KB
/
tcap.go
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
package tcapflow
import (
"encoding/asn1"
"strconv"
)
// ASN1 handling
const (
TCbeginApp = 2 // [APPLICATION 2] Begin,
TCendApp = 4 // [APPLICATION 4] End,
TCcontinueApp = 5 // [APPLICATION 5] Continue,
TCabortApp = 7 // [APPLICATION 7] Abort,
)
func TCprocName(tag int) string {
switch tag {
case TCbeginApp:
return "BEGIN"
case TCendApp:
return "END"
case TCcontinueApp:
return "CONTINUE"
case TCabortApp:
return "ABORT"
default:
return strconv.Itoa(tag)
}
}
func DecodeTCAP(data []byte) (tag int, otid asn1.RawValue, dtid asn1.RawValue, dialoguePortion asn1.RawValue, components asn1.RawValue, err error) {
var tmp asn1.RawValue
// Unpack the choice and ignore it for now
_, err = asn1.Unmarshal(data, &tmp)
if err != nil {
return
}
data = tmp.Bytes
tag = tmp.Tag
for len(data) > 0 {
data, err = asn1.Unmarshal(data, &tmp)
if err != nil {
return
}
switch tmp.Tag {
case 8:
otid = tmp
case 9:
dtid = tmp
case 11:
dialoguePortion = tmp
case 12:
components = tmp
}
}
return
}