admin管理员组文章数量:1400776
I have been trying to encode to byte the message string "Severe Earthquake expected immediately" into the NGAPPDU message WarningMessageContents which by definition in the specification ETSI TS 138 413 V17.11.0 (2025-01) is WarningMessageContents ::= OCTET STRING (SIZE(1..9600)) but was having issue, wireshark is showing error and is about the decoded content. The page number is calculated correctly. Could anyone help me figure out what I might be missing in the code below. Other specification of the coding scheme can be found in section 5 of ETSI TS 123 038 V17.0.0 (2022-04), thanks in advance.
const (
MaxCBSPageSize = 82 // Bytes per page (after GSM 7-bit encoding)
MaxPages = 15 // 3GPP TS 23.041 limit
MaxMessageBytes = 9600 // Total CBS message size limit
)
type WarningMessageContents struct {
Value aper.OctetString `aper:"sizeLB:1,sizeUB:9600"`
}
type OctetString []byte
// Function to encode CBS message according to ETSI TS 123 041
func EncodeCBSWarningMessage(message string) (*ngapType.WarningMessageContents, error) {
// Calculate number of pages
messageLen := len(message)
numPages := (messageLen + MaxCBSPageSize - 1) / MaxCBSPageSize // Ceiling division
// Strict validation for maximum pages
if numPages > 15 {
return nil, fmt.Errorf("too many CBS pages (must be <= 15), found: %d", numPages)
}
// Validate total size
if messageLen < 1 || messageLen > 9600 {
return nil, errors.New("warning message size out of range (must be between 1 and 9600 bytes)")
}
// Build CBS formatted message
cbsMessage := make([]byte, 0, messageLen+numPages*5) // Pre-allocate with some extra space
// First byte is Total Number of Pages
cbsMessage = append(cbsMessage, byte(numPages))
// Split message into pages
for i := 0; i < numPages; i++ {
start := i * MaxCBSPageSize
end := start + MaxCBSPageSize
if end > messageLen {
end = messageLen
}
// Precise page header according to CBS specifications
pageHeader := []byte{
byte(i + 1), // Page Number (1-based)
0x01, // Data Coding Scheme (GSM 7-bit)
0x00, // Language Group (English)
}
// Append page header
cbsMessage = append(cbsMessage, pageHeader...)
// Append page content
cbsMessage = append(cbsMessage, []byte(message[start:end])...)
}
// Create WarningMessageContents
return &ngapType.WarningMessageContents{
Value: aper.OctetString(cbsMessage),
}, nil
}
本文标签: goHow to encode NGAPPDU WarningMessageContentsStack Overflow
版权声明:本文标题:go - How to encode NGAPPDU WarningMessageContents - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744183687a2594188.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论