espressif / esp-protocols

Collection of ESP-IDF components related to networking protocols
191 stars 133 forks source link

SIM7000G connect with user name password and chap auto. (IDFGH-13505) #635

Open Aviarbiser opened 2 months ago

Aviarbiser commented 2 months ago

Answers checklist.

General issue report

Hello, I am using sim7000 with pppos, it working ok if I don't use chap authentication .
I try to find some help or example to do this but I don't find something that work. Is there any working example or any idea how to do this. In the TinyGSM project on Arduino I fixed the AT command in gprsConnectImpl to: sendAT(GF("+CNCFG=1,\""), apn, "\",\"", "\",\"", user, pwd,authentication, '" '); And it works well, maybe it will help solve the problem here too.

david-cermak commented 2 months ago

Hi @Aviarbiser

I'm sorry, we currently don't have an example that demonstrates PPP connection using CHAP authentication method. you have to add a call to esp_netif_ppp_set_auth() before switching to data mode.

#include "esp_netif_ppp.h"
 ...

//
{
    ...
    // before PPPoS connection, but after initializing netif and modem
    esp_netif_ppp_set_auth(esp_netif, NETIF_PPP_AUTHTYPE_CHAP, USERNAME, PASSWORD);
Aviarbiser commented 2 months ago

Hi david,

Thanks for your fast replay. I will test it today and update.

Regards

Avihai Arbiser +972508942777 @.***

From: david-cermak @.> Sent: Monday, August 19, 2024 5:48 PM To: espressif/esp-protocols @.> Cc: Aviahi Arbiser @.>; Mention @.> Subject: Re: [espressif/esp-protocols] SIM7000G connect with user name password and chap auto. (IDFGH-13505) (Issue #635)

Hi @Aviarbiserhttps://github.com/Aviarbiser

I'm sorry, we currently don't have an example that demonstrates PPP connection using CHAP authentication method. you have to add a call to esp_netif_ppp_set_auth() before switching to data mode.

include "esp_netif_ppp.h"

...

//

{

...

// before PPPoS connection, but after initializing netif and modem

esp_netif_ppp_set_auth(esp_netif, NETIF_PPP_AUTHTYPE_CHAP, USERNAME, PASSWORD);

— Reply to this email directly, view it on GitHubhttps://github.com/espressif/esp-protocols/issues/635#issuecomment-2296762390, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AMBOAKYSHAAHCZZVVM7QCLDZSIAQ7AVCNFSM6AAAAABMXWBDWWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJWG43DEMZZGA. You are receiving this because you were mentioned.Message ID: @.**@.>>

Aviarbiser commented 2 months ago

Hi, thanks for your fast replay.

I add this to my code and it not connecting to GRPS (LTE) . I try to change to other SIM card that not use the same APN (using the default "internet") but I don't changed the connection settings like APN ,user , password and chap auth. and the modem is connected and I got IP . as much as I know if you try to connect with wrong APN it will not connect . I try to set the APN with "esp_modem_set_apn(dce, MODEM_PPP_APN);" and it still connect with the wrong APN. I am also not remove "esp_netif_ppp_set_auth(esp_netif, NETIF_PPP_AUTHTYPE_CHAP, "Admin", "1234");" and it was connected . Maybe that's why it doesn't connect with the SIM that uses APN and CHAP. how can I check it ?

Aviarbiser commented 2 months ago

Hello, I do a check with a sniffer (I connect the TX and RX to my PC) to check what the ESP32 send to the modem (SIM7000G). I find that the ESP32 not send the user name and password (and chap auth.) but I send it with command before I do the connect. modem_sendCommand("AT+CGAUTH=1,2,\"user\",\"password\""); and after that I do the connection "esp_modem_set_mode(dce, ESP_MODEM_MODE_DATA);" in the sniffer terminal I see that the esp32 (pppos) connection is ok it return CONNECT 150000000 and is in ppp connection. but in the ESP32 it not return the IP and I get time out

how can I check it?

sniffer terminal RX (command that ESP32 send to the modem) image

sniffer terminal TX (command that ESP32 send to the modem) image

ESP32 terminal image

modem direct connection with terminal image

david-cermak commented 2 months ago

Note that esp_netif_ppp_set_auth() configure the username and password for authentication over PPPoS, while the AT+CGAUTH sets APN credentials via AT commands (not sure if they are the same or which one you should use)

Aviarbiser commented 2 months ago

Ok , but if I see that the modem is connected "ATD*99# return CONNECT 150000000 " why I don't get IP and get timeout?

What I do to check (debug) this problem?

Aviarbiser commented 2 months ago

Hello again, I d more tests , and I see that the modem is connected to the gprs , and the pppos program try to send something (I fink this is a query to check the IP or the connection status). But in the end I get the msg "NO CARRIER" see attached log : CONNECT 150000000 ~?}#?!}!} } }9}"}&} } } } }#}%?#}%}%}&?‘??}'}"}(}"&}3?}#?!}"}?} }4}"}&} } } } }%}&?¨\8}'}"}(}"} },?}#?!}!}!} }4}"}&} } } } }%}&?‘??}'}"}(}"?},?}#?!}+}"} }(?‘??¶?€!

 ƒ ‚  ?~ NO CARRIER any suggestion?
david-cermak commented 2 months ago

You can debug this further by setting

CONFIG_LWIP_PPP_DEBUG_ON=y
CONFIG_LWIP_DEBUG=y

and check the CHAP related logs (which are more readable than the plain text you posted above) here's an example of logs if the authentication failed:

2024-08-23 17:20:35 ppp: auth protocols: CHAP=1 CHAP_MD5=1
2024-08-23 17:20:35 sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x6ec82c38> <pcomp> <accomp>]
2024-08-23 17:20:35 pppos_write[1]: len=24
2024-08-23 17:20:35 ppp_start[1]: finished
2024-08-23 17:20:35 pppos_input[1]: got 2 bytes
2024-08-23 17:20:35 pppos_input[1]: got 43 bytes
2024-08-23 17:20:35 rcvd [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0x6ec82c38> <pcomp> <accomp>]
[PPPD:]b'sent [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0x6ec82c38> <pcomp> <accomp>]'
[PPPD:]b'sent [LCP ConfReq id=0x1 <asyncmap 0x0> <auth chap MD5> <magic 0xb06349ed> <pcomp> <accomp>]'
2024-08-23 17:20:37 pppos_input[1]: got 2 bytes
2024-08-23 17:20:37 pppos_input[1]: got 52 bytes
2024-08-23 17:20:37 rcvd [LCP ConfReq id=0x1 <asyncmap 0x0> <auth chap MD5> <magic 0xb06349ed> <pcomp> <accomp>]
2024-08-23 17:20:37 sent [LCP ConfAck id=0x1 <asyncmap 0x0> <auth chap MD5> <magic 0xb06349ed> <pcomp> <accomp>]
2024-08-23 17:20:37 pppos_write[1]: len=29
2024-08-23 17:20:37 netif_set_mtu[1]: mtu=1500
2024-08-23 17:20:37 pppos_send_config[1]: out_accm=0 0 0 0
2024-08-23 17:20:37 ppp_send_config[1]
2024-08-23 17:20:37 pppos_recv_config[1]: in_accm=0 0 0 0
2024-08-23 17:20:37 ppp_recv_config[1]
2024-08-23 17:20:37 ppp phase changed[1]: phase=7
2024-08-23 17:20:37 pppos_input[1]: got 49 bytes
2024-08-23 17:20:37 rcvd [LCP EchoReq id=0x0 magic=0xb06349ed]
2024-08-23 17:20:37 sent [LCP EchoRep id=0x0 magic=0x6ec82c38]
2024-08-23 17:20:37 pppos_write[1]: len=12
2024-08-23 17:20:37 rcvd [CHAP Challenge id=0x41 <12e26dd58e7267cd0e4accb0c4269a85>, name = "david-work"]
2024-08-23 17:20:37 sent [CHAP Response id=0x41 <4c610091605268c298d0ab1aeaeb9527>, name = "myclient"]
2024-08-23 17:20:37 pppos_write[1]: len=33
2024-08-23 17:20:37 pppos_input[1]: got 61 bytes
2024-08-23 17:20:37 rcvd [CHAP Failure id=0x41 "Access denied"]
2024-08-23 17:20:37 CHAP authentication failed: Access denied
2024-08-23 17:20:37 CHAP authentication f[PPPD:]b'rcvd [LCP ConfAck id=0x1 <asyncmap 0x0> <auth chap MD5> <magic 0xb06349ed> <pcomp> <accomp>]'
ailed
2024-08-23 17:20:38 ppp phase changed[1]: phase=11
2024-08-23 17:20:38 ppp phase changed[1]: phase=6
2024-08-23 17:20:38 pppos_send_config[1]: out_accm=FF FF FF FF
2024-08-23 17:20:38 ppp_send_config[1]
2024-08-23 17:20:38 pppos_recv_config[1]: in_accm=0 0 0 0
2024-08-23 17:20:38 ppp_recv_config[1]
2024-08-23 17:20:38 sent [LCP TermReq id=0x2 "Failed to authenticate ourselves to peer"]
2024-08-23 17:20:38 pppos_write[1]: len=48
2024-08-23 17:20:38 rcvd [LCP TermReq id=0x2 "Authentication failed"]
2024-08-23 17:20:38 sent [LCP TermAck id=0x2]
2024-08-23 17:20:38 pppos_write[1]: len=8
2024-08-23 17:20:38 pppos_input[1]: got 2 bytes
2024-08-23 17:20:38 pppos_input[1]: got 16 bytes
2024-08-23 17:20:38 rcvd [LCP TermAck id=0x2]
2024-08-23 17:20:38 ppp phase changed[1]: phase=12
2024-08-23 17:20:38 Connection terminated.
2024-08-23 17:20:38 ppp_link_terminated[1]
2024-08-23 17:20:38 ppp_link_end[1]
2024-08-23 17:20:38 ppp phase changed[1]: phase=0
2024-08-23 17:20:38 E (3208) esp-netif_lwip-ppp: Failed authentication challenge
2024-08-23 17:20:38 I (3218) esp_modem_netif: PPP state changed event 7
2024-08-23 17:20:38 I (3218) pppd_test: PPP state changed event 7

Have you enabled the CHAP option is menuconfig? CONFIG_LWIP_PPP_CHAP_SUPPORT (you'd see an error message if you didn't and tried to setup authentication options) Also, please check with your provider how you're supposed to authenticate (using PPP CHAP method or via AT commands AT+CGAUTH)?

PS: I'm adding more tests including CHAP authentication in https://github.com/espressif/esp-protocols/pull/640

david-cermak commented 2 months ago

And here's how it looks like if the authentication succeeds: https://github.com/espressif/esp-protocols/actions/runs/10528192870/job/29173244199?pr=640#step:5:217 (I'll have to still update it to run both methods) (you can run the test locally: https://github.com/espressif/esp-protocols/tree/master/components/esp_modem/test/target, just need a usb2serial (e.g. esp_prog) and running pytest)

Aviarbiser commented 2 months ago

Thank I will check and update

Aviarbiser commented 2 months ago

After further investigation, I discovered that the issue was related to the SIM7000 module. I have since replaced it with a SIM7600 module, and I am pleased to report that everything is now functioning perfectly.

Thank you for your support and assistance.

Best regards,