mirror of
https://github.com/yibaiba/hideck.git
synced 2026-12-06 08:02:21 +00:00
fix(esim): accept ML307C bare logical channel responses
This commit is contained in:
2 files changed
+47
-2
No files matched your search
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user