tpdu

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2020 License: MIT Imports: 12 Imported by: 19

Documentation

Overview

Package tpdu provides the TPDU type and conversions to and from its binary form.

Index

Constants

View Source
const (

	// FoMTIMask masks the bit for the TP-MTI field
	FoMTIMask = 0x3

	// FoMTIShift defines the shift required to move the MTI field to/from bit 0
	FoMTIShift = 0

	// FoMMS defines the TP-MMS More Messages to Send bit
	//
	// Only applies to SMS-DELIVER and SMS-STATUS-REPORT
	FoMMS = 0x4

	// FoRD defines the TP-RD Reject Duplicates bit
	//
	// Only applies to SMS-SUBMIT
	FoRD = 0x4

	// FoLP defines the TP-LP Loop Prevention bit
	//
	// Only applies to SMS-DELIVER and SMS-STATUS-REPORT
	FoLP = 0x8

	// FoVPFMask masks the bit for the TP-VPF field
	//
	// Only applies to SMS-SUBMIT
	FoVPFMask = 0x18

	// FoVPFShift defines the shift required to move the VPF field to/from bit 0
	FoVPFShift = 3

	// FoSRI defines the TP-SRI bit
	//
	// Only applies to SMS-DELIVER
	FoSRI = 0x20

	// FoSRR defines the TP-SRR bit
	//
	// Only applies to the SMS-SUBMIT and SMS-COMMAND
	FoSRR = 0x20

	// FoSRQ defines the TP-SRQ bit
	//
	// Only applies to the SMS-STATUS-REPORT
	FoSRQ = 0x20

	// FoUDHI defines the TP-UDHI bit
	FoUDHI = 0x40

	// FoRP defines the TP-RP bit
	//
	// Only applies to the SMS-SUBMIT and SMS-DELIVER
	FoRP = 0x80
)
View Source
const (

	// PiPID indicates a TP-PID field is present in the TPDU
	PiPID = 1 << iota

	// PiDCS indicates a TP-DCS field is present in the TPDU
	PiDCS

	// PiUDL indicates a TP-UDL field is present in the TPDU
	PiUDL
)
View Source
const MaxUDL = 140

MaxUDL is the maximum number of octets that can be encoded into the UD. Note that for 7bit encoding this can result in up to 160 septets.

Variables

View Source
var (
	// ErrInvalid indicates the value of a field provided to an encoder is not valid.
	ErrInvalid = errors.New("invalid")

	// ErrOddUCS2Length indicates the length of a binary array containing UCS2
	// characters has an uneven length, and so has split a UCS2 character.
	ErrOddUCS2Length = errors.New("odd UCS2 length")

	// ErrOverlength indicates the binary provided contains more bytes than
	// expected by the TPDU decoder.
	ErrOverlength = errors.New("overlength")

	// ErrMissing indicates a field requiored to marshal an object is missing.
	ErrMissing = errors.New("missing")

	// ErrNonZero indicates a field which is expected to be zeroed, but contains
	// non-zero data.
	ErrNonZero = errors.New("non-zero fill")

	// ErrUnderflow indicates the binary provided does not contain
	// sufficient bytes to correctly decode the TPDU.
	ErrUnderflow = errors.New("underflow")
)
View Source
var With16BitConcatRef = func(so *segmentationConfig) {
	so.ief = newInfoElement16bit
}

With16BitConcatRef specifies the usage of concat IEs with 16 bit reference numbers (ID=8).

By default 8bit reference numbers are used.

View Source
var WithAllCharsets = AllCharsetsOption{}

WithAllCharsets makes all possible character sets available to encode or decode.

This is equivalent to calling WithCharset with all possible NationalLanguageIdentifiers, in increasing order.

Functions

func DecodeUserData added in v0.2.0

func DecodeUserData(ud UserData, udh UserDataHeader, alpha Alphabet, options ...UDDecodeOption) ([]byte, error)

DecodeUserData converts TPDU UD into the corresponding UTF8 message.

The UD is expected to be unpacked, as stored in TPDU UD. If the UD is GSM7 encoded then it is translated to UTF8 with the default character set, or with the character set specified in the UDH, assuming the corresponding language has been registered with the UDDecoder. If the UDH specifies a character set that has not been registered then the translation will fall back to the default character set.

func EncodeError

func EncodeError(f string, e error) error

EncodeError creates an encodeError which identifies the field being encoded.

If the provided error is a nested encodeError then the error is returned as is rather than wrapping it.

func EncodeUserData added in v0.2.0

func EncodeUserData(msg []byte, options ...UDEncodeOption) (UserData, UserDataHeader, Alphabet)

EncodeUserData converts a UTF8 message into corresponding TPDU User Data.

Note that the UD size is not limited to the size available in a single TPDU, and so may need to be segmented into several concatenated messages. Encode attempts to pick the most compact alphabet for the given message. It assumes GSM7 is the most compact, and, if the default character set is insufficient, tries combinations of supported language character sets, in the order they were added to the UDEncoder.

This is not optimal as it performs language selection on the whole message, rather than determining the best for each segment in turn. (which is totally allowed as stated in 3GPP TS 23.040 9.2.3.24.15 + 16), but this may be a safer approach - to allow for the decoder being non-compliant, and the benefit of per-segment language encoding is minimal. In most cases there is no benefit at all.

Failing GSM7 conversion it falls back to UCS2/UTF16.

Types

type Address

type Address struct {
	TOA  byte
	Addr string
}

Address represents a phone number.

func NewAddress

func NewAddress(options ...AddressOption) Address

NewAddress creates an Address and initialises the TOA.

func (*Address) MarshalBinary

func (a *Address) MarshalBinary() (dst []byte, err error)

MarshalBinary marshals an Address into binary.

It returns the marshalled address and any error detected while marshalling.

func (Address) Number

func (a Address) Number() string

Number returns the stringified number corresponding to the Address.

func (Address) NumberingPlan

func (a Address) NumberingPlan() NumberingPlan

NumberingPlan extracts the NPI field from the TOA.

func (*Address) SetNumber added in v0.2.0

func (a *Address) SetNumber(number string)

SetNumber sets the address to the international number.

The number may be optionally prefixed with '+'.

func (*Address) SetNumberingPlan

func (a *Address) SetNumberingPlan(np NumberingPlan)

SetNumberingPlan sets the NPI field in the TOA.

func (*Address) SetTypeOfNumber

func (a *Address) SetTypeOfNumber(ton TypeOfNumber)

SetTypeOfNumber sets the TON field in the TOA.

func (Address) TypeOfNumber

func (a Address) TypeOfNumber() TypeOfNumber

TypeOfNumber extracts the TON field from the TOA.

func (*Address) UnmarshalBinary

func (a *Address) UnmarshalBinary(src []byte) (int, error)

UnmarshalBinary unmarshals an Address from a binary TPDU.

It returns the number of bytes read from the source, and any error detected while unmarshalling.

type AddressOption added in v0.2.0

type AddressOption func(Address) Address

AddressOption returns a new Address with an option applied.

func FromNumber added in v0.2.0

func FromNumber(number string) AddressOption

FromNumber creates an AddressOption thats sets the address to the international number.

The number may be optionally prefixed with '+'.

type AllCharsetsOption added in v0.2.0

type AllCharsetsOption struct{}

AllCharsetsOption specifies that all character sets are available for encoding and decoding.

type Alphabet

type Alphabet int

Alphabet defines the encoding of the SMS User Data, as defined in 3GPP TS 23.038 Section 4.

const (
	// Alpha7Bit indicates that the UD is encoded using GSM 7 bit encoding.
	// The character set used for the decoding is determined from the UDH.
	Alpha7Bit Alphabet = iota

	// Alpha8Bit indicates that the UD is encoded as raw 8bit data.
	Alpha8Bit

	// AlphaUCS2 indicates that the UD is encoded as UCS-2 (16bit) characters.
	AlphaUCS2

	// AlphaReserved indicates the alphabet is not defined.
	AlphaReserved
)

type CharsetOption added in v0.2.0

type CharsetOption struct {
	// contains filtered or unexported fields
}

CharsetOption adds the locking and shift character sets available for encoding and decoding.

These are in addition to the default character set.

func WithCharset added in v0.2.0

func WithCharset(nli ...int) CharsetOption

WithCharset sets the set of character sets available to encode or decode.

These are in addition to the default character set.

type Counter added in v0.2.0

type Counter interface {
	Count() int
}

Counter provides a reference couunter that is incremented every time Count is called.

type DAOption added in v0.2.0

type DAOption struct {
	// contains filtered or unexported fields
}

DAOption specifies the DA for the TPDU.

func WithDA added in v0.2.0

func WithDA(addr Address) DAOption

WithDA creates a DAOption to apply to a TPDU.

func (DAOption) ApplyTPDUOption added in v0.2.0

func (o DAOption) ApplyTPDUOption(t *TPDU) error

ApplyTPDUOption applies the DA to the TPDU.

type DCS

type DCS byte

DCS represents the SMS Data Coding Scheme field as defined in 3GPP TS 23.040 Section 4.

const (
	// Dcs8BitData is a DCS indicating 8 bit data
	Dcs8BitData DCS = 0x04

	// DcsUCS2Data is a DCS indicating UCS2 data
	DcsUCS2Data DCS = 0x08
)

func (DCS) Alphabet

func (d DCS) Alphabet() (Alphabet, error)

Alphabet returns the alphabet used to encode the User Data according to the DCS.

The DCS is assumed to be defined as per 3GPP TS 23.038 Section 4.

func (DCS) ApplyTPDUOption added in v0.2.0

func (d DCS) ApplyTPDUOption(t *TPDU) error

ApplyTPDUOption applies the DCS value to the TPDU DCS field.

func (DCS) Class

func (d DCS) Class() (MessageClass, error)

Class returns the MessageClass indicated by the DCS. The DCS is assumed to be defined as per 3GPP TS 23.038 Section 4.

func (DCS) Compressed

func (d DCS) Compressed() bool

Compressed indicates whether the text is compressed using the algorithm defined in 3GPP TS 23.024, as determined from the DCS.

The DCS is assumed to be defined as per 3GPP TS 23.038 Section 4.

func (DCS) String added in v0.2.0

func (d DCS) String() string

func (DCS) WithAlphabet

func (d DCS) WithAlphabet(a Alphabet) (DCS, error)

WithAlphabet sets the Alphabet bits of the DCS, given the state of the other bits.

An error is returned if the state is incompatible with setting the alphabet.

func (DCS) WithClass

func (d DCS) WithClass(c MessageClass) (DCS, error)

WithClass sets the MessageClass bits of the DCS, given the state of the other bits.

An error is returned if the state is incompatible with setting the message class.

type DecodeError

type DecodeError struct {
	Field  string
	Offset int
	Err    error
}

DecodeError contains the details of an error detected whilew decoding a TPDU.

func NewDecodeError added in v0.2.0

func NewDecodeError(f string, o int, e error) DecodeError

NewDecodeError creates a decodeError which identifies the field being decoded, and the offset into the byte array where the field starts.

If the provided error is a nested decodeError then the offset is updated to provide the offset from the beginning of the enclosing field, and the field names are combined in outer.inner format.

func (DecodeError) Error added in v0.2.0

func (e DecodeError) Error() string

type Direction

type Direction int

Direction indicates the direction that the SMS TPDU is carried.

const (
	// MT indicates that the SMS TPDU is intended to be received by the MS.
	MT Direction = iota

	// MO indicates that the SMS TPDU is intended to be sent by the MS.
	MO
)

func (Direction) ApplyTPDUOption added in v0.2.0

func (d Direction) ApplyTPDUOption(t *TPDU) error

ApplyTPDUOption sets the direction of the TPDU.

type EnhancedValidityPeriodFormat

type EnhancedValidityPeriodFormat byte

EnhancedValidityPeriodFormat identifies the subformat of the ValidityPeriod when encoded to binary in enhanced format, as per 3GPP TS 23.038 Section 9.2.3.12.3

const (
	// EvpfNotPresent indicates no VP is present.
	EvpfNotPresent EnhancedValidityPeriodFormat = iota

	// EvpfRelative indicates the VP is stored in relative format as per 3GPP
	// TS 23.038 Section 9.2.3.12.1.
	EvpfRelative

	// EvpfRelativeSeconds indicates the VP is stored in relative format as an
	// integer number of seconds, from 0 to 255.
	EvpfRelativeSeconds

	// EvpfRelativeHHMMSS indicates the VP is stored in relative format as a
	// period of hours, minutes and seconds in semioctet format as per SCTS
	// time.
	EvpfRelativeHHMMSS
)

func EnhancedFormat added in v0.2.0

func EnhancedFormat(efi byte) EnhancedValidityPeriodFormat

EnhancedFormat extracts the format field from the EFI.

func (EnhancedValidityPeriodFormat) String added in v0.2.0

func (evpf EnhancedValidityPeriodFormat) String() string

type ErrUnsupportedSmsType added in v0.2.0

type ErrUnsupportedSmsType byte

ErrUnsupportedSmsType indicates the type of TPDU being decoded is not unsupported by the decoder.

func (ErrUnsupportedSmsType) Error added in v0.2.0

func (e ErrUnsupportedSmsType) Error() string

type FirstOctet added in v0.2.0

type FirstOctet byte

FirstOctet is the first byte of a SMS-TPDU.

func (FirstOctet) LP added in v0.2.0

func (f FirstOctet) LP() bool

LP returns true if the TP-LP flag is set.

func (FirstOctet) MMS added in v0.2.0

func (f FirstOctet) MMS() bool

MMS returns true if the TP-MMS flag is set.

func (FirstOctet) MTI added in v0.2.0

func (f FirstOctet) MTI() MessageType

MTI returns the message type field.

func (FirstOctet) RD added in v0.2.0

func (f FirstOctet) RD() bool

RD returns true if the TP-RD flag is set.

func (FirstOctet) RP added in v0.2.0

func (f FirstOctet) RP() bool

RP returns true if the TP-RP flag is set.

func (FirstOctet) SRI added in v0.2.0

func (f FirstOctet) SRI() bool

SRI returns true if the TP-SRI flag is set.

func (FirstOctet) SRQ added in v0.2.0

func (f FirstOctet) SRQ() bool

SRQ returns true if the TP-SRQ flag is set.

func (FirstOctet) SRR added in v0.2.0

func (f FirstOctet) SRR() bool

SRR returns true if the TP-SRR flag is set.

func (FirstOctet) UDHI added in v0.2.0

func (f FirstOctet) UDHI() bool

UDHI returns true if the TP-UDHI flag is set.

func (FirstOctet) VPF added in v0.2.0

VPF returns the TP-VPF field.

func (FirstOctet) WithMTI added in v0.2.0

func (f FirstOctet) WithMTI(mti MessageType) FirstOctet

WithMTI returns a FirstOctet with the TP-MTI field set.

func (FirstOctet) WithVPF added in v0.2.0

WithVPF returns a FirstOctet with the TP-VPF field set.

type InformationElement

type InformationElement struct {
	ID   byte
	Data []byte
}

InformationElement represents one of the information elements contained in the User Data Header.

type LockingCharsetOption added in v0.2.0

type LockingCharsetOption struct {
	// contains filtered or unexported fields
}

LockingCharsetOption adds to the locking character sets available for encoding and decoding.

These are in addition to the default character set.

func WithLockingCharset added in v0.2.0

func WithLockingCharset(nli ...int) LockingCharsetOption

WithLockingCharset sets the set of locking character sets available to encode or decode.

These are in addition to the default character set.

type MessageClass

type MessageClass int

MessageClass indicates the class of the message as specified in 3GPP TS 23.038 Section 4.

const (
	// MClass0 is a flash message which is not to be stored in memory.
	MClass0 MessageClass = iota

	// MClass1 is an ME specific message.
	MClass1

	// MClass2 is a SIM/USIM specific message.
	MClass2

	// MClass3 is a TE specific message.
	MClass3

	// MClassUnknown indicates no message class is set.
	MClassUnknown
)

type MessageType

type MessageType int

MessageType identifies the type of TPDU encoded in a binary stream, as defined in 3GPP TS 23.040 Section 9.2.3.1. Note that the direction of the TPDU must also be known to determine how to interpret the TPDU.

const (
	// MtDeliver identifies the message as a SMS-Deliver or SMS-Deliver-Report
	// TPDU.
	MtDeliver MessageType = iota

	// MtSubmit identifies the message as a SMS-Submit or SMS-Submit-Report
	// TPDU.
	MtSubmit

	// MtCommand identifies the message as a SMS-Command or SMS-Status-Report
	// TPDU.
	MtCommand

	// MtReserved identifies the message as an unknown type of SMS TPDU.
	MtReserved
)

func (MessageType) ApplyTPDUOption added in v0.2.0

func (mti MessageType) ApplyTPDUOption(t *TPDU) error

ApplyTPDUOption sets the TPDU MTI.

func (MessageType) String added in v0.2.0

func (mti MessageType) String() string

type NumberingPlan

type NumberingPlan int

NumberingPlan corresponds to bits 4,3,2,1 of the Address TOA field. i.e. 1yyyxxxx as defined in 3GPP TS 23.040 Section 9.1.2.5

const (
	// NpUnknown indicates the numbering plan is unknown.
	NpUnknown NumberingPlan = iota

	// NpISDN indicates the number is in ISDN/E.164 format.
	NpISDN

	// NpData indicates a data numbering plan (X.121).
	NpData

	// NpTelex indicates a telex numbering plan.
	NpTelex

	// NpScSpecificA indicates a service center specific numbering plan.
	NpScSpecificA

	// NpScSpecificB indicates a service center specific numbering plan.
	NpScSpecificB

	// NpNational indicates a national numbering plan.
	NpNational

	// NpPrivate indicates a private numbering plan.
	NpPrivate

	// NpErmes indicates the ERMES (ETSI DE/PS 3 01-3) numbering plan.
	NpErmes

	// NpExtension is reserved for future extensions.
	NpExtension = 0x0f
)

type OAOption added in v0.2.0

type OAOption struct {
	// contains filtered or unexported fields
}

OAOption specifies the OA for the TPDU.

func WithOA added in v0.2.0

func WithOA(addr Address) OAOption

WithOA creates a OAOption to apply to a TPDU.

func (OAOption) ApplyTPDUOption added in v0.2.0

func (o OAOption) ApplyTPDUOption(t *TPDU) error

ApplyTPDUOption applies the OA to the TPDU.

type Option added in v0.2.0

type Option interface {
	ApplyTPDUOption(*TPDU) error
}

Option applies a construction option to a TPDU.

type PI added in v0.2.0

type PI byte

PI is the parameter indicator bitfield.

func (PI) DCS added in v0.2.0

func (p PI) DCS() bool

DCS returns true if a DCS field is present in the TPDU.

func (PI) PID added in v0.2.0

func (p PI) PID() bool

PID returns true if a PID field is present in the TPDU.

func (PI) String added in v0.2.0

func (p PI) String() string

func (PI) UDL added in v0.2.0

func (p PI) UDL() bool

UDL returns true if a UDL, and hence a UD, field is present in the TPDU.

type SegmentationOption added in v0.2.0

type SegmentationOption func(*segmentationConfig)

SegmentationOption provides an option to modify the behaviour of segmentation.

func WithConcatRef added in v0.2.0

func WithConcatRef(cr Counter) SegmentationOption

WithConcatRef provides a generator to provide the reference for concatenation IEs.

By default the field is set to 1, which is only suitable for one-off messages.

func WithMR added in v0.2.0

func WithMR(mr Counter) SegmentationOption

WithMR provides an MR generator to provide the TP-MR field for TPDUs.

By default the MR is copied from the template TPDU.

type ShiftCharsetOption added in v0.2.0

type ShiftCharsetOption struct {
	// contains filtered or unexported fields
}

ShiftCharsetOption adds the shift character sets available for encoding and decoding.

These are in addition to the default character set.

func WithShiftCharset added in v0.2.0

func WithShiftCharset(nli ...int) ShiftCharsetOption

WithShiftCharset sets the set of shift character sets available to encode or decode.

These are in addition to the default character set.

type SmsType added in v0.2.0

type SmsType int

SmsType indicates the type of SMS TPDU type represented by the TPDU.

const (
	// SmsDeliver indiates the TPDU represents a SMS-DELIVER
	SmsDeliver SmsType = iota

	// SmsDeliverReport indiates the TPDU represents a SMS-DELIVER-REPORT
	SmsDeliverReport

	// SmsSubmitReport indiates the TPDU represents a SMS-SUBMIT-REPORT
	SmsSubmitReport

	// SmsSubmit indiates the TPDU represents a SMS-SUBMIT
	SmsSubmit

	// SmsStatusReport indiates the TPDU represents a SMS-STATUS-REPORT
	SmsStatusReport

	// SmsCommand indiates the TPDU represents a SMS-COMMAND
	SmsCommand
)

func (SmsType) ApplyTPDUOption added in v0.2.0

func (st SmsType) ApplyTPDUOption(t *TPDU) error

ApplyTPDUOption sets the TPDU direction and MTI to match the SmsType.

func (SmsType) Direction added in v0.2.0

func (st SmsType) Direction() Direction

Direction returns the direction corresponding to the SmsType.

func (SmsType) MTI added in v0.2.0

func (st SmsType) MTI() MessageType

MTI returns the MessageType corresponding to the SmsType.

func (SmsType) String added in v0.2.0

func (st SmsType) String() string

type TPDU

type TPDU struct {
	// Direction indicates whether the TPDU is mobile originated (MO) or
	// terminated (MT).
	Direction Direction

	// FirstOctet is the first octet of all TPDUs.
	FirstOctet FirstOctet

	// OA contains the TP-OA Originating Address field.
	//
	// Only applies to SMS-DELIVER
	OA Address

	// FCS contains the TP-FCS Failure Cause field.
	//
	// Only applies to SMS-DELIVER-REPORT and SMS-SUBMIT-REPORT
	FCS byte

	// MR contains the TP-MP Message Reference field.
	//
	// Only applies to SMS-COMMAND, SMS-SUBMIT and SMS-STATUS-REPORT
	MR byte

	// CT contains the TP-CT Command Type field.
	//
	// Only applies to SMS-COMMAND
	CT byte

	// MN contains the TP-MN Message Number field.
	//
	// Only applies to SMS-COMMAND
	MN byte

	// DA contains the TP-DA Destination Address field.
	//
	// Only applies to SMS-COMMAND and SMS-SUBMIT
	DA Address

	// RA contains the TP-RA Recipient Address field.
	//
	// Only applies to SMS-STATUS-REPORT
	RA Address

	// PI contains the TP-PI Parameter Indicator field.
	//
	//  Only applies to SMS-DELIVER-REPORT and SMS-SUBMIT-REPORT
	PI PI

	// SCTS contains the TP-SCTS Service Center Time Stamp field.
	//
	// The SCTS timestamp indicates the time the SMS was sent.
	// The time is the originator's local time, the timezone of which may
	// differ from the receiver's.
	//
	// Only applies to SMS-DELIVER, SMS-SUBMIT-REPORT and SMS-STATUS-REPORT
	SCTS Timestamp

	// DT contains the TP-DT Discharge Time field.
	//
	// Only applies to SMS-STATUS-REPORT
	DT Timestamp

	// ST contains the TP-ST Status field.
	//
	// Only applies to SMS-STATUS-REPORT
	ST byte

	// PID contains the TP-PID field.
	PID byte

	// DCS contains the TP-DCS Data Coding Scheme field.
	DCS DCS

	// VP contains the TP-VP Validity Period field.
	//
	//  Only applies to SMS-SUBMIT
	VP ValidityPeriod

	// UDH contains the TP-UDH User Data Header field.
	UDH UserDataHeader

	// UD contains the short message from the User Data.
	//
	// It does not include the User Data Header, which is provided separately
	// in the UDH.
	// The interpretation of UD depends on the Alphabet:
	// For Alpha7Bit, UD is an array of GSM7 septets, each septet stored in the
	// lower 7 bits of a byte.
	//  These have NOT been converted to the corresponding UTF8.
	//  Use the gsm7 package to convert to UTF8.
	// For AlphaUCS2, UD is an array of UCS2 characters packed into a byte
	// array in Big Endian.
	//  These have NOT been converted to the corresponding UTF8.
	//  Use the usc2 package to convert to UTF8.
	// For Alpha8Bit, UD contains the raw octets.
	UD UserData
}

TPDU represents all SMS TPDUs.

func New added in v0.2.0

func New(options ...Option) (*TPDU, error)

New creates a new TPDU

func NewDeliver

func NewDeliver(options ...Option) (*TPDU, error)

NewDeliver creates a new TPDU of type SmsDeliver.

func NewSubmit

func NewSubmit(options ...Option) (*TPDU, error)

NewSubmit creates a new TPDU of type SmsSubmit.

func (*TPDU) Alphabet

func (t *TPDU) Alphabet() (Alphabet, error)

Alphabet returns the alphabet field from the DCS of the SMS TPDU.

func (*TPDU) ConcatInfo added in v0.2.0

func (t *TPDU) ConcatInfo() (segments, seqno, mref int, ok bool)

ConcatInfo extracts the segmentation info contained in the provided User Data Header.

func (*TPDU) IsSingleSegment added in v0.2.0

func (t *TPDU) IsSingleSegment() bool

IsSingleSegment returns true unless the TPDU is part of a multi-part message.

func (*TPDU) MTI

func (t *TPDU) MTI() MessageType

MTI returns the MessageType from the first octet of the SMS TPDU.

func (*TPDU) MarshalBinary added in v0.2.0

func (t *TPDU) MarshalBinary() (dst []byte, err error)

MarshalBinary marshals a SMS TPDU into the corresponding byte array.

func (TPDU) Segment added in v0.2.0

func (t TPDU) Segment(msg []byte, options ...SegmentationOption) []TPDU

Segment returns the set of SMS TPDUs required to transmit the message.

The TPDU acts as the template for the generated TPDUs and provides all the fields in the resulting TPDUs, other than the UD, which is populated using the message. For multi-part messages, the UDH provided in the TPDU is extended with a concatenation IE. The TPDU UDH must not contain a concatenation IE (ID 0 or 8) or the resulting TPDUs will be non-conformant.

func (*TPDU) SetDCS added in v0.2.0

func (t *TPDU) SetDCS(dcs byte)

SetDCS sets the dcs field and the corresponding bit of the PI.

func (*TPDU) SetPID added in v0.2.0

func (t *TPDU) SetPID(pid byte)

SetPID sets the TPDU pid field and the corresponding bit of the PI.

func (*TPDU) SetSmsType added in v0.2.0

func (t *TPDU) SetSmsType(st SmsType) error

SetSmsType returns the type of SMS-TPDU this TPDU represents.

func (*TPDU) SetUD added in v0.2.0

func (t *TPDU) SetUD(ud UserData)

SetUD sets the TPDU ud field and the corresponding bit of the PI.

func (*TPDU) SetUDH

func (t *TPDU) SetUDH(udh UserDataHeader)

SetUDH sets the User Data Header of the TPDU and the TP-UDHI flag.

func (*TPDU) SetVP added in v0.2.0

func (t *TPDU) SetVP(vp ValidityPeriod)

SetVP sets the validity period and the corresponding VPF bits in the firstOctet.

func (*TPDU) SmsType added in v0.2.0

func (t *TPDU) SmsType() SmsType

SmsType returns the type of SMS-TPDU this TPDU represents.

func (*TPDU) UDBlockSize added in v0.2.0

func (t *TPDU) UDBlockSize() int

UDBlockSize returns the maximum size of a block of UserData that can fit in this TPDU.

The interpretation of the size depends on the encoding - for 7bit encoding it is the number of septets. For all other encodings it is the number of octets.

func (*TPDU) UDHI

func (t *TPDU) UDHI() bool

UDHI returns the User Data Header Indicator bit from the SMS TPDU first octet.

This is generally the same as testing the length of the udh - unless the dcs has been intentionally overwritten to create an inconsistency.

func (*TPDU) UDHL added in v0.2.0

func (t *TPDU) UDHL() int

UDHL returns the encoded length of the UDH, not including the UDHL itself.

func (*TPDU) UnmarshalBinary added in v0.2.0

func (t *TPDU) UnmarshalBinary(src []byte) (err error)

UnmarshalBinary unmarshals a SMS TPDU from the corresponding byte array.

In the case of error the TPDU will be partially unmarshalled, up to the point that the decoding error was detected.

type Timestamp

type Timestamp struct {
	time.Time
}

Timestamp represents a SCTS timestamp, as defined in 3GPP TS 23.040 Section 9.2.3.11.

func (*Timestamp) MarshalBinary

func (t *Timestamp) MarshalBinary() (dst []byte, err error)

MarshalBinary encodes the SCTS timestamp into binary.

func (Timestamp) String added in v0.2.0

func (t Timestamp) String() string

func (*Timestamp) UnmarshalBinary

func (t *Timestamp) UnmarshalBinary(src []byte) error

UnmarshalBinary decodes the SCTS timestamp from binary.

type TypeOfNumber

type TypeOfNumber int

TypeOfNumber corresponds to bits 6,5,4 of the Address TOA field.

i.e. 1xxxyyyy, as defined in 3GPP TS 23.040 Section 9.1.2.5.

const (
	// TonUnknown indicates the type of the number is unknown.
	TonUnknown TypeOfNumber = iota

	// TonInternational indicates the number is international.
	TonInternational

	// TonNational indicates the number is national.
	TonNational

	// TonNetworkSpecific indicates the number is specific to the carrier network.
	TonNetworkSpecific

	// TonSubscriberNumber indicates the number is a subscriber number.
	TonSubscriberNumber

	// TonAlphanumeric indicates the number is in alphanumeric format.
	TonAlphanumeric

	// TonAbbreviated indicates the number is in abbreviated format.
	TonAbbreviated

	// TonExtension is reserved for future extension.
	TonExtension
)

type UDDecodeOption added in v0.2.0

type UDDecodeOption interface {
	// contains filtered or unexported methods
}

UDDecodeOption provides behavioural modifiers for DecodeUserData, specifically the character sets available to decode GSM7.

type UDEncodeOption added in v0.2.0

type UDEncodeOption interface {
	// contains filtered or unexported methods
}

UDEncodeOption provides behavioural modifiers for EncodeUserData, specifically the locking and shift character sets available, in addition to the default character set.

type UDHOption added in v0.2.0

type UDHOption struct {
	// contains filtered or unexported fields
}

UDHOption specifies the UDH for the TPDU.

func WithUDH added in v0.2.0

func WithUDH(udh UserDataHeader) UDHOption

WithUDH creates a UDHOption to apply to a TPDU.

func (UDHOption) ApplyTPDUOption added in v0.2.0

func (o UDHOption) ApplyTPDUOption(t *TPDU) error

ApplyTPDUOption applies the UDH to the TPDU.

type UserData

type UserData []byte

UserData represents the User Data field as defined in 3GPP TS 23.040 Section 9.2.3.24.

The UserData is comprised of an optional User Data Header and a short message field.

type UserDataHeader

type UserDataHeader []InformationElement

UserDataHeader represents the header section of the User Data as defined in 3GPP TS 23.040 Section 9.2.3.24.

func (UserDataHeader) ConcatInfo

func (udh UserDataHeader) ConcatInfo() (segments, seqno, mref int, ok bool)

ConcatInfo extracts the segmentation info contained in the provided User Data Header.

If the UDH contains no segmentation information then ok is false and zero values are returned. The returned values do not distinguish between 8bit and 16bit message reference numbers.

func (UserDataHeader) ConcatInfo16

func (udh UserDataHeader) ConcatInfo16() (segments, seqno, mref int, ok bool)

ConcatInfo16 extracts the segmentation info contained in the provided User Data Header, for the 16bit message reference case.

If the UDH contains no segmentation information then ok is false and zero values are returned.

func (UserDataHeader) ConcatInfo8

func (udh UserDataHeader) ConcatInfo8() (segments, seqno, mref int, ok bool)

ConcatInfo8 extracts the segmentation info contained in the provided User Data Header, for the 8bit message reference case.

If the UDH contains no segmentation information then ok is false and zero values are returned.

func (UserDataHeader) IE

IE returns the last instance of the IE with the given id in the UDH.

If no such IE is found then the function returns false.

func (UserDataHeader) IEs

func (udh UserDataHeader) IEs(id byte) []InformationElement

IEs returns all instances of the IEs with the given id in the UDH.

func (UserDataHeader) MarshalBinary

func (udh UserDataHeader) MarshalBinary() ([]byte, error)

MarshalBinary marshals the User Data Header, including the UDHL, into binary.

func (UserDataHeader) UDHL

func (udh UserDataHeader) UDHL() int

UDHL returns the encoded length of the UDH, not including the UDHL itself.

func (*UserDataHeader) UnmarshalBinary

func (udh *UserDataHeader) UnmarshalBinary(src []byte) (int, error)

UnmarshalBinary reads the InformationElements from the binary User Data Header.

The src contains the complete UDH, including the UDHL and all IEs. The function returns the number of bytes read from src, and any error detected while unmarshalling.

type ValidityPeriod

type ValidityPeriod struct {
	Format   ValidityPeriodFormat
	Time     Timestamp     // for VpfAbsolute
	Duration time.Duration // for VpfRelative and VpfEnhanced
	EFI      byte          // enhanced functionality indicator - first octet of enhanced format
}

ValidityPeriod represents the validity period as defined in 3GPP TS 34.040 Section 9.2.3.12.

func (*ValidityPeriod) MarshalBinary

func (v *ValidityPeriod) MarshalBinary() ([]byte, error)

MarshalBinary marshals a ValidityPeriod.

func (*ValidityPeriod) SetAbsolute

func (v *ValidityPeriod) SetAbsolute(t Timestamp)

SetAbsolute sets the validity period to an absolute time.

func (*ValidityPeriod) SetEnhanced

func (v *ValidityPeriod) SetEnhanced(d time.Duration, efi byte)

SetEnhanced sets the validity period to an enhnaced format as determined from the functionality identifier (efi).

func (*ValidityPeriod) SetRelative

func (v *ValidityPeriod) SetRelative(d time.Duration)

SetRelative sets the validity period to a relative time.

func (*ValidityPeriod) UnmarshalBinary

func (v *ValidityPeriod) UnmarshalBinary(src []byte, vpf ValidityPeriodFormat) (int, error)

UnmarshalBinary unmarshals a ValidityPeriod stored in the given format.

Returns the number of bytes read from the src, and any error detected during the unmarshalling.

type ValidityPeriodFormat

type ValidityPeriodFormat byte

ValidityPeriodFormat identifies the format of the ValidityPeriod when encoded to binary.

const (
	// VpfNotPresent indicates no VP is present.
	VpfNotPresent ValidityPeriodFormat = iota

	// VpfEnhanced indicates the VP is stored in enhanced format as per 3GPP TS
	// 23.038 Section 9.2.3.12.3.
	VpfEnhanced

	// VpfRelative indicates the VP is stored in relative format as per 3GPP TS
	// 23.038 Section 9.2.3.12.1.
	VpfRelative

	// VpfAbsolute indicates the VP is stored in absolute format as per 3GPP TS
	// 23.038 Section 9.2.3.12.2. The absolute format is the same format as the
	// SCTS.
	VpfAbsolute
)

func (ValidityPeriodFormat) String added in v0.2.0

func (vpf ValidityPeriodFormat) String() string

Jump to

Keyboard shortcuts

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