fix(esim): accept ML307C bare logical channel responses

This commit is contained in:
Jiahui Zhu committed 2026-11-20 12:37:59 +08:00
1 parent 7e577d2793
commit 41a78ae1db
2 files changed
+47 -2

No files matched your search

+20 -2
View File
@@ -548,11 +548,11 @@ func ParseUSBNetMode(resp string) (int, error) {
}
// parseCCHO 解析 AT+CCHO 响应,提取逻辑通道号
// 响应格式: +CCHO: <channel>
// 响应格式: +CCHO: <channel>。ML307C 返回单行裸通道号。
func parseCCHO(resp string) (int, bool) {
line, ok := findLineWithPrefix(resp, "+CCHO:")
if !ok {
return -1, false
return parseBareCCHO(resp)
}
parts := strings.Split(line, ":")
if len(parts) < 2 {
@@ -566,6 +566,24 @@ func parseCCHO(resp string) (int, bool) {
return -1, false
}
func parseBareCCHO(resp string) (int, bool) {
var channel int
for _, line := range splitLines(resp) {
if line == "" || line == "OK" {
continue
}
value, err := strconv.ParseUint(line, 10, 8)
if channel != 0 || err != nil || value == 0 {
return -1, false
}
channel = int(value)
}
if channel == 0 {
return -1, false
}
return channel, true
}
// parseCGLA 解析 AT+CGLA 响应,提取 APDU 响应
// 响应格式: +CGLA: <len>,"<apdu>"
func parseCGLA(resp string) (string, bool) {
+27
View File
@@ -214,3 +214,30 @@ func TestParseCOPSOperator(t *testing.T) {
})
}
}
func TestParseCCHO(t *testing.T) {
tests := []struct {
name string
resp string
channel int
}{
{name: "prefixed", resp: "\r\n+CCHO: 2\r\nOK\r\n", channel: 2},
{name: "ML307C", resp: "\r\n2\r\nOK\r\n", channel: 2},
{name: "terminal stripped", resp: "2", channel: 2},
{name: "only OK", resp: "OK", channel: -1},
{name: "bare followed by ERROR", resp: "2\nERROR", channel: -1},
{name: "command rejected", resp: "+CME ERROR: 3", channel: -1},
{name: "multiple numbers", resp: "2\n3\nOK", channel: -1},
{name: "number with suffix", resp: "2,3\nOK", channel: -1},
{name: "basic channel", resp: "0\nOK", channel: -1},
{name: "out of range", resp: "258\nOK", channel: -1},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
channel, ok := parseCCHO(tt.resp)
if channel != tt.channel || ok != (tt.channel > 0) {
t.Fatalf("parseCCHO(%q) = (%d, %t), want (%d, %t)", tt.resp, channel, ok, tt.channel, tt.channel > 0)
}
})
}
}