Added APN parse.
This commit is contained in:
parent
2eb21228e3
commit
225a0d2264
@ -110,14 +110,28 @@ func (c *conn) checkReqs() error {
|
|||||||
|
|
||||||
func (c *conn) ConfigurePPP() error {
|
func (c *conn) ConfigurePPP() error {
|
||||||
// Get provider name and its APN
|
// Get provider name and its APN
|
||||||
// AT+CSPN
|
resp, err := c.port.Send("AT+CSPN?")
|
||||||
provider := ""
|
if err != nil {
|
||||||
|
return fmt.Errorf("AT+CSPN? request: %w", err)
|
||||||
|
}
|
||||||
|
if !resp.Check() {
|
||||||
|
return fmt.Errorf("failed to check SIM provider")
|
||||||
|
}
|
||||||
|
strs := strings.Split(string(resp), "\"")
|
||||||
|
if len(strs) < 3 {
|
||||||
|
return fmt.Errorf("parse AT+CSPN response: %s", string(resp))
|
||||||
|
}
|
||||||
|
provider := strs[1]
|
||||||
apn := apns[provider]
|
apn := apns[provider]
|
||||||
if apn == "" {
|
if apn == "" {
|
||||||
return fmt.Errorf("no apn for provider: %s", provider)
|
return fmt.Errorf("no apn for provider: %s", provider)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make config
|
||||||
|
c.logger.Printf("Config values: %s, %s, %d", apn, c.port.GetName(), c.port.GetBaudrate())
|
||||||
config := fmt.Sprintf(pppConfig, apn, c.port.GetName(), c.port.GetBaudrate())
|
config := fmt.Sprintf(pppConfig, apn, c.port.GetName(), c.port.GetBaudrate())
|
||||||
|
|
||||||
|
// Write to file
|
||||||
f, err := os.OpenFile("etc/ppp/pears/"+pppConfigName, os.O_CREATE, 0666)
|
f, err := os.OpenFile("etc/ppp/pears/"+pppConfigName, os.O_CREATE, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("open ppp config file %w", err)
|
return fmt.Errorf("open ppp config file %w", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user