aboutsummaryrefslogtreecommitdiff
path: root/acse/acse.go
blob: 3f882e77bc0418778d5b6878e4007f5f46e0782b (plain)
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
package acse

import (
	"dim13.org/asn1/csta"
	"github.com/dim13/asn1"
)

// 2.2.0.0.1

// A-ASSOCIATE Request
// Application Constructed implicit 0
type AARQ struct {
	asn1.Tag               `asn1:"application,tag:0"`
	ProtocolVersion        asn1.BitString        `asn1:"tag:0"`           // 0 implicit BitString
	ApplicationContextName asn1.ObjectIdentifier `asn1:"tag:1,explicit"`  // 1
	UserInformation        UserInformation       `asn1:"tag:30,optional"` // 30 implicit
}

type UserInformation struct {
	External `asn1:"instance"`
}

// A-ASSOCIATE Result (Result == 0)
// A-REJECT (Result == 1)
// Application Constructed implicit 1
type AARE struct {
	asn1.Tag               `asn1:"application,tag:1"`
	ProtocolVersion        asn1.BitString        `asn1:"tag:0"`           // 0 implicit BitString
	ApplicationContextName asn1.ObjectIdentifier `asn1:"tag:1,explicit"`  // 1
	Result                 int                   `asn1:"tag:2,explicit"`  // 2
	ResultSourceDiagnostic AcseServiceUser       `asn1:"tag:3,explicit"`  // 3
	UserInformation        UserInformation       `asn1:"tag:30,optional"` // 30 implicit
}

type AcseServiceUser struct {
	asn1.Tag `asn1:"tag:1"`
	Reason   int
}

// A-RELEASE Request
// Application Constructed implicit 2
type RLRQ struct {
	asn1.Tag `asn1:"application,tag:2"`
}

// A-RELEASE Result
// Application Constructed implicit 3
type RLRE struct {
	asn1.Tag `asn1:"application,tag:3"`
}

// ABRT Source
const (
	ABRTServiceUser = iota
	ABRTServiceProvider
)

// A-ABORT
// Application Constructed implicit 4
type ABRT struct {
	asn1.Tag    `asn1:"application,tag:4"`
	AbortSource int `asn1:"tag:0"` // 0 implicit
}

type External struct {
	DirectReference asn1.ObjectIdentifier           `asn1:"optional"`
	Encoding        csta.ACSEUserInformationForCSTA `asn1:"tag:0,optional"`
}

var Version1 = asn1.BitString{Bytes: []byte{0x80}, BitLength: 1}

func Associate() ([]byte, error) {
	aarq := AARQ{
		ProtocolVersion:        Version1,
		ApplicationContextName: csta.CSTA,
		UserInformation: UserInformation{
			External{
				DirectReference: csta.OID,
				Encoding: csta.ACSEUserInformationForCSTA{
					csta.NewDefinition{
						CSTAVersion: csta.Version5,
					},
				},
			},
		},
	}
	return asn1.Marshal(aarq)
}

const (
	AssociateResultAccepted = iota
	AssociateResultRejectedPermanent
	AssociateResultRejectedTransient
)

func AssociateResult(b []byte) (int, error) {
	aare := AARE{}
	_, err := asn1.Unmarshal(b, &aare)
	if err != nil {
		return 0, err
	}
	return aare.Result, nil
}