tcap

package module
v1.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2025 License: MIT Imports: 7 Imported by: 0

README

go-tcap

A robust ASN.1 TCAP (Transaction Capabilities Application Part) implementation from ITU-T Q.773 (06/97).

Go CI Go Reference Go Report Card Go Version

Quality Gate Status Coverage Bugs Vulnerabilities

Overview

Package tcap provides handling of TCAP (Transaction Capabilities Application Part) in SS7/SIGTRAN protocol stack.

TCAP is an ASN.1-based protocol used in telecommunications networks for SS7-SIGTRAN information exchange between applications. It's commonly used in mobile networks for operations like SMS delivery, subscriber information retrieval, and authentication.

The TCAP structures in this library are directly defined based on the ASN.1 definition from ITU-T Q.773 (06/97). This implementation does not use any ASN.1 files or ASN.1 parsers, making it easy to use and integrate.

Installation

go get github.com/gomaja/go-tcap

Features

Transaction Portion
Message Types
Message type Supported?
Unidirectional Yes
Begin Yes
End Yes
Continue Yes
Abort Yes
Fields
Tag Supported?
Originating Transaction ID Yes
Destination Transaction ID Yes
P-Abort Cause Yes
Component Portion
Component types
Component type Supported?
Invoke Yes
Return Result (Last) Yes
Return Result (Not Last) Yes
Return Error Yes
Reject Yes
Dialogue Portion
Dialogue types
Dialogue type Supported?
Dialogue Request (AARQ-apdu) Yes
Dialogue Response (AARE-apdu) Yes
Dialogue Abort (ABRT-apdu) Yes
Unidirectional Dialogue (AUDT-apdu) Yes
Elements
Tag Type Supported?
Object Identifier Structured Yes
Dialogue PDU Structured Yes
Object Identifier Unstructured Yes
Unidirectional Dialogue PDU Unstructured Yes

API Documentation

Main Types
  • TCAP: The main structure representing a TCAP message
  • BeginTCAP, EndTCAP, ContinueTCAP, AbortTCAP, UnidirectionalTCAP: Different TCAP message types
  • ComponentTCAP: Represents the component portion of a TCAP message
  • DialogueTCAP: Represents the dialogue portion of a TCAP message

Common Use Cases

This library can be used to implement various SS7/SIGTRAN protocols that use TCAP, such as:

  • MAP (Mobile Application Part)
  • CAP (CAMEL Application Part)
  • INAP (Intelligent Network Application Part)

Common operations include:

  • SMS delivery and routing
  • Subscriber information retrieval
  • Authentication and authorization
  • Call handling and routing

Author

Marwan Jadid

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

View Source
const (
	// ASN.1 field omission indicator
	// Used throughout the codebase to indicate optional fields should be omitted
	FieldOmissionValue = 255

	// Transaction ID constraints per ITU-T Q.773
	MinTransactionIDLength = 1
	MaxTransactionIDLength = 4

	// Invoke ID constraints (signed 8-bit integer range)
	MinInvokeID = -128
	MaxInvokeID = 127

	// ASN.1 tag values
	ExternalConstructorTag = 0x28 // EXTERNAL with constructor
	SequenceConstructorTag = 0x30 // SEQUENCE with constructor

	// Protocol version for TCAP dialogue
	DefaultProtocolVersion = 0x80 // 128 decimal
)
View Source
const (
	IndefiniteLengthErrorString = "indefinite length found (not DER)"
)

ASN1 standard package error string

Variables

View Source
var (
	// DefaultDialogueAsId represents the standard TCAP dialogue object identifier
	DefaultDialogueAsId = []int{0, 0, 17, 773, 1, 1, 1}

	// DefaultAcnPrefix represents the prefix for the Application Context Name (ACN) in TCAP dialogue identifiers.
	DefaultAcnPrefix = []int{0, 4, 0, 0, 1, 0}
)

Dialogue ASN.1 Object Identifier constants

View Source
var (
	// ErrInvalidInput indicates invalid input data
	ErrInvalidInput = errors.New("invalid input data")

	// ErrEmptyData indicates empty or nil data
	ErrEmptyData = errors.New("empty data provided")

	// ErrUnmarshalFailed indicates ASN.1 unmarshal failure
	ErrUnmarshalFailed = errors.New("failed to unmarshal ASN.1 data")

	// ErrMarshalFailed indicates ASN.1 marshal failure
	ErrMarshalFailed = errors.New("failed to marshal ASN.1 data")

	// ErrInvalidTransactionID indicates invalid transaction ID
	ErrInvalidTransactionID = errors.New("invalid transaction ID")

	// ErrInvalidInvokeID indicates invalid invoke ID
	ErrInvalidInvokeID = errors.New("invalid invoke ID")
)

Error types for better error handling and debugging

Functions

This section is empty.

Types

type AAREapduTCAP

type AAREapduTCAP struct {
	ProtocolVersionPadded  *uint8
	AcnVersion             []int
	Result                 uint8
	ResultSourceDiagnostic AssociateSourceDiagnostic
	UserInformation        []byte
}

type AARQapduTCAP

type AARQapduTCAP struct {
	ProtocolVersionPadded *uint8
	AcnVersion            []int
	UserInformation       []byte
}

type ABRTapduTCAP

type ABRTapduTCAP struct {
	AbortSource     uint8
	UserInformation []byte
}

type AbortTCAP

type AbortTCAP struct {
	Dtid        TransactionID
	PAbortCause *uint8
	UAbortCause *DialogueTCAP
}

func (*AbortTCAP) Marshal added in v1.1.0

func (tcAbort *AbortTCAP) Marshal() ([]byte, error)

func (*AbortTCAP) MessageType added in v1.1.0

func (tcAbort *AbortTCAP) MessageType() MessageType

type AssociateSourceDiagnostic

type AssociateSourceDiagnostic struct {
	DialogueServiceUser     *uint8
	DialogueServiceProvider *uint8
}

type BeginOption added in v1.0.0

type BeginOption func(*BeginTCAP) error

BeginOption represents a functional option for configuring Begin TCAP messages

func WithBeginDialogueObject added in v1.0.0

func WithBeginDialogueObject(dialogue *DialogueTCAP) BeginOption

WithBeginDialogueObject adds a dialogue object to a Begin TCAP message

func WithBeginDialogueRequest added in v1.1.0

func WithBeginDialogueRequest(acn, acnVersion int) BeginOption

WithBeginDialogueRequest adds a dialogue to a Begin TCAP message

func WithBeginInvoke added in v1.0.0

func WithBeginInvoke(invID int, opCode uint8, payload []byte) BeginOption

WithBeginInvoke adds an Invoke component to a Begin TCAP message

type BeginTCAP

type BeginTCAP struct {
	Otid       TransactionID
	Dialogue   *DialogueTCAP
	Components *ComponentTCAP
}

func (*BeginTCAP) Marshal added in v1.1.0

func (tcBegin *BeginTCAP) Marshal() ([]byte, error)

func (*BeginTCAP) MessageType added in v1.1.0

func (tcBegin *BeginTCAP) MessageType() MessageType

type ComponentTCAP

type ComponentTCAP struct {
	Invoke              *InvokeTCAP
	ReturnResultLast    *ReturnResultTCAP
	ReturnError         *ReturnErrorTCAP
	Reject              *RejectTCAP
	ReturnResultNotLast *ReturnResultTCAP

	// Linked list here to include presence of more than one component
	MoreComponents *ComponentTCAP
}

ComponentTCAP will have only one field fulfilled and the others will be nil, except MoreComponents may exist additionally to any other field

func (*ComponentTCAP) TreatRecursiveMoreComponents

func (components *ComponentTCAP) TreatRecursiveMoreComponents(cmpnt *asn1tcapmodel.ComponentPortion)

type ContinueOption added in v1.0.0

type ContinueOption func(*ContinueTCAP) error

ContinueOption represents a functional option for configuring Continue TCAP messages

func WithContinueDialogueObject added in v1.0.0

func WithContinueDialogueObject(dialogue *DialogueTCAP) ContinueOption

WithContinueDialogueObject adds a dialogue object to a Continue TCAP message

func WithContinueDialogueRequest added in v1.1.0

func WithContinueDialogueRequest(acn, acnVersion int) ContinueOption

WithContinueDialogueRequest adds a dialogue to a Continue TCAP message

func WithContinueDialogueResponse added in v1.1.0

func WithContinueDialogueResponse(acn, acnVersion int) ContinueOption

WithContinueDialogueResponse adds a dialogue to a Continue TCAP message

func WithContinueInvoke added in v1.0.0

func WithContinueInvoke(invID int, opCode uint8, payload []byte) ContinueOption

WithContinueInvoke adds an Invoke component to a Continue TCAP message

func WithContinueReturnResultLast added in v1.0.0

func WithContinueReturnResultLast(invID int, opCode *uint8, payload []byte) ContinueOption

WithContinueReturnResultLast adds a ReturnResultLast component to a Continue TCAP message

type ContinueTCAP

type ContinueTCAP struct {
	Otid       TransactionID
	Dtid       TransactionID
	Dialogue   *DialogueTCAP
	Components *ComponentTCAP
}

func (*ContinueTCAP) Marshal added in v1.1.0

func (tcContinue *ContinueTCAP) Marshal() ([]byte, error)

func (*ContinueTCAP) MessageType added in v1.1.0

func (tcContinue *ContinueTCAP) MessageType() MessageType

type DialogueTCAP

type DialogueTCAP struct {
	DialogAsId []int

	DialogueRequest  *AARQapduTCAP
	DialogueResponse *AAREapduTCAP
	DialogueAbort    *ABRTapduTCAP
}

func NewDialogueResponseFromDialogueRequest added in v1.1.0

func NewDialogueResponseFromDialogueRequest(dialogueRQ *DialogueTCAP) (dialogueRE *DialogueTCAP, err error)

type EndOption added in v1.0.0

type EndOption func(*EndTCAP) error

EndOption represents a functional option for configuring End TCAP messages

func WithEndDialogueObject added in v1.0.0

func WithEndDialogueObject(dialogue *DialogueTCAP) EndOption

WithEndDialogueObject adds a dialogue object to an End TCAP message

func WithEndDialogueResponse added in v1.1.0

func WithEndDialogueResponse(acn, acnVersion int) EndOption

WithEndDialogueResponse adds a dialogue to an End TCAP message

func WithEndReturnError added in v1.2.2

func WithEndReturnError(invID int, errorCode uint8, parameter []byte) EndOption

WithEndReturnError adds a ReturnError component to an End TCAP message

func WithEndReturnResultLast added in v1.0.0

func WithEndReturnResultLast(invID int, opCode *uint8, payload []byte) EndOption

WithEndReturnResultLast adds a ReturnResultLast component to an End TCAP message

type EndTCAP

type EndTCAP struct {
	Dtid       TransactionID
	Dialogue   *DialogueTCAP
	Components *ComponentTCAP
}

func (*EndTCAP) Marshal added in v1.1.0

func (tcEnd *EndTCAP) Marshal() ([]byte, error)

func (*EndTCAP) MessageType added in v1.1.0

func (tcEnd *EndTCAP) MessageType() MessageType

type InvokeTCAP

type InvokeTCAP struct {
	InvokeID  int // integer value range -128 to 127
	LinkedID  *int
	OpCode    uint8
	Parameter []byte
}

type MessageType added in v1.1.0

type MessageType string
const (
	MessageTypeUnidirectional MessageType = "Unidirectional"
	MessageTypeBegin          MessageType = "Begin"
	MessageTypeEnd            MessageType = "End"
	MessageTypeContinue       MessageType = "Continue"
	MessageTypeAbort          MessageType = "Abort"
)

type ParseError added in v0.4.0

type ParseError struct {
	Op    string // operation that failed
	Field string // field that caused the error
	Err   error  // underlying error
}

ParseError represents a parsing error with additional context

func (*ParseError) Error added in v0.4.0

func (e *ParseError) Error() string

func (*ParseError) Unwrap added in v0.4.0

func (e *ParseError) Unwrap() error

type RejectTCAP

type RejectTCAP struct {
	DerivableOrNotDerivable *uint8 // if value is nil means it is NotDerivable
	GeneralProblem          *uint8
	InvokeProblem           *uint8
	ReturnResultProblem     *uint8
	ReturnErrorProblem      *uint8
}

type ReturnErrorTCAP

type ReturnErrorTCAP struct {
	InvokeID  int // integer value range -128 to 127
	ErrorCode uint8
	Parameter []byte
}

type ReturnResultTCAP

type ReturnResultTCAP struct {
	InvokeID  int // integer value range -128 to 127
	OpCode    *uint8
	Parameter []byte
}

type TCAP

type TCAP interface {
	Marshal() ([]byte, error)
	MessageType() MessageType
}

TCAP represents a CHOICE of TCAP message types such as Unidirectional, Begin, End, Continue, or Abort.

func NewBegin

func NewBegin(otid []byte, options ...BeginOption) (TCAP, error)

NewBegin creates a Begin TCAP message using the options pattern Parameters:

  • otid: Originating Transaction ID, size from 1 to 4 bytes in BigEndian format.

func NewContinue

func NewContinue(otid []byte, dtid []byte, options ...ContinueOption) (TCAP, error)

NewContinue creates a Continue TCAP message using the options pattern Parameters:

  • otid: Originating Transaction ID, size from 1 to 4 bytes in BigEndian format.
  • dtid: Destination Transaction ID, size from 1 to 4 bytes in BigEndian format.

func NewEnd added in v1.0.0

func NewEnd(dtid []byte, options ...EndOption) (TCAP, error)

NewEnd creates an End TCAP message using the options pattern

func ParseAny

func ParseAny(b []byte) (TCAP, error)

func ParseDER

func ParseDER(b []byte) (TCAP, error)

ParseDER takes a slice of byte, without a tag and length. A tag byte and length byte are added at the beginning internally to satisfy asn1 Unmarshal behavior for completeness It parses on DER encoded asn1 structs, the encoding/asn1 package parses on DER (indefinite length is not supported)

type TransactionID

type TransactionID []byte

TransactionID size from 1 up to 4 bytes in BigEndian format

type UnidirectionalTCAP

type UnidirectionalTCAP struct {
	Dialogue   *DialogueTCAP
	Components ComponentTCAP
}

func (*UnidirectionalTCAP) Marshal added in v1.1.0

func (tcUnidirectional *UnidirectionalTCAP) Marshal() ([]byte, error)

func (*UnidirectionalTCAP) MessageType added in v1.1.0

func (tcUnidirectional *UnidirectionalTCAP) MessageType() MessageType

type ValidationError added in v0.4.0

type ValidationError struct {
	Field string
	Value interface{}
	Err   error
}

ValidationError represents a validation error with context

func (*ValidationError) Error added in v0.4.0

func (e *ValidationError) Error() string

func (*ValidationError) Unwrap added in v0.4.0

func (e *ValidationError) Unwrap() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL