Reset is required when changing APN

Hi all,

Firstly, I’m a newbie with Embedded Wireless module. Please forgive me if I ask a stupid question.
I’m using SL8082 for my application with a eUICC SIM from a telco provider.

I establish the connection bw SL8082 with my server via HTTP protocol by using WIP Library and Security Library.

After booting up, I used APN1 to connect with server. The application can post/receive data to/from HTTP server. But when I change to APN2(I also re-establish PPP data connection). Application can’t post data to HTTP server anymore (At beginning, I thought it related to SSL session. After that, I try to close and re-establish SSL session again, but It still does not work). Just incase I perform a reset. The APN2 can post/receive data to/from HTTP server.

Note:

  1. APN1 and APN2 were got roaming from telco provider successfully.
  2. When booting up application with APN1, I didn’t perform any communication with HTTP server, then changed to APN2, the application can post/receive data to/from HTTP server with APN2. Then I changed to APN1, it didn’t work again.

This is my code:

void HTTPSSM_SendInternalHttpsPost(int https_id)
{
    memset(sizeString, 0, sizeof(sizeString));
    snprintf(sizeString, sizeof(sizeString), "%lu", Https[idx].last_post_size);

    adl_wdPut2Sleep(ADL_TMR_S_TO_TICK(1000));   /* WD sleeps in order to avoid a reset */
    if (Https[idx].SSLsession != NULL)
    {
#ifdef SSL
#ifdef HANDLE_SSLSESSION
        Https[idx].session_channel = wip_HTTPClientCreateOpts(
                                         NULL, // no handler
                                         NULL, // no context
                                         WIP_COPT_HTTP_HEADER,
                                         "User-Agent",
                                         "WIPHTTP/1.0",
                                         WIP_COPT_HTTP_DATA_ENCOD, FALSE,  
                                         WIP_COPT_HTTPS_SESSION_ID, Https[idx].SSLsession,
                                         WIP_COPT_FINALIZER, finalizerCntr,
                                         WIP_COPT_END);
#endif
#endif
    }
    else if (Https[idx].SSLsession == NULL || Https[idx].session_channel == NULL)
    {
        Https[idx].session_channel = wip_HTTPClientCreateOpts(
                                         NULL, // no handler
                                         NULL, // no context
                                         WIP_COPT_HTTP_HEADER,
                                         "User-Agent",
                                         "WIPHTTP/1.0",
                                         WIP_COPT_HTTP_DATA_ENCOD, FALSE, 
                                         WIP_COPT_FINALIZER, finalizerCntr,
                                         WIP_COPT_END);
    }

    if (Https[idx].session_channel == NULL)
    {
        ERR("cannot create http session channel");
        ErrCode = ACP_ERR_NO_SESSION;
    }

    // HTTP POST command
    // ---------------------------
    Https[idx].data_channel = wip_getFileOpts(Https[idx].session_channel,
                              (ascii *) Https[idx].server_addr,
                              httpssm_ClientDataHandler,
                              &Https[idx],
                              WIP_COPT_HTTP_METHOD,
                              WIP_HTTP_METHOD_POST,
                              WIP_COPT_HTTP_HEADER,
                              "User-Agent",
                              "WIPHTTP/1.0",
                              WIP_COPT_HTTP_HEADER,
                              "Accept",
                              "*/*",
                              WIP_COPT_HTTP_HEADER,
                              "Content-Type",
                              "application/octet-stream",
                              WIP_COPT_HTTP_HEADER,
                              "Content-Length",
                              sizeString,
                              WIP_COPT_FINALIZER, finalizerData,
                              WIP_COPT_END);

    if (Https[idx].data_channel == NULL)
    {
        ERR("cannot create http data channel. session is: 0x%x", Https[idx].session_channel);
        HTTPSSM_notify(Https[idx].id, ACPSVC_HTTPS_CEV_ERR_EVENT); /* trigger a retry  */
    }
}

Although data channel was created, but I didn’t receive any event WIP_CEV_OPEN, WIP_CEV_WRITE with the APN2.
Do you have any idea for this issue?
Thank you for your help,
Tai.

Suggest you trying with http without ssl first.
Also you can capture wireshark log to see what happen in the communication.

Hi jyijyi,

Thanks for your reply.
I tried without ssl, Both APNs work fine with the server.

Also you can capture wireshark log to see what happen in the communication.

I can’t get the log from server due to it is not my server.
But this is log from firmware:
For success connection:

2019/11/13;18:12:43:976;001;ADL;1;[SSL] subevh_handshake function 2 
2019/11/13;18:12:43:976;002;ADL;1;[SSL] subevh_handshake function 6 
2019/11/13;18:12:43:976;003;ADL;1;[SSL] subevh_handshake: WIP_CEV_OPEN
2019/11/13;18:12:43:976;004;ADL;1;[SSL] Handshaking waiting for more network exchanges (state==0)
2019/11/13;18:12:48:714;002;ADL;1;[SSL] subevh_handshake function 5 
2019/11/13;18:12:48:714;003;ADL;1;[SSL] subevh_handshake: WIP_CEV_OPEN
2019/11/13;18:12:48:714;004;ADL;1;[SSL] [BIO =>] read 5 bytes on TCP
2019/11/13;18:12:48:714;005;ADL;1;[SSL] [BIO =>] read 1 bytes on TCP
2019/11/13;18:12:48:714;006;ADL;1;[SSL] [BIO =>] read 5 bytes on TCP
2019/11/13;18:12:48:715;001;ADL;1;[SSL] [BIO =>] read 80 bytes on TCP
2019/11/13;18:12:48:715;002;ADL;1;[SSL] Handshaking completed state(0)
2019/11/13;18:12:48:715;003;ADL;1;[req_event] WIP_CEV_OPEN
2019/11/13;18:12:48:715;004;ADL;1;[req_event] WIP_CEV_WRITE
2019/11/13;18:12:48:715;005;ADL;1;[SSL] writeOpts: 203 bytes written
2019/11/13;18:12:48:715;006;ADL;1;203 data written
2019/11/13;18:12:48:715;007;ADL;8;INFO httpssm_ClientDataHandler 885 WIP_CEV_OPEN
2019/11/13;18:12:48:716;001;ADL;8;DEBUG httpssm_ClientDataHandler 910 WIP_CEV_WRITE event
2019/11/13;18:12:48:716;002;ADL;8;INFO httpssm_ClientDataHandler 921 SSLsessionPtr: 297943580
2019/11/13;18:12:48:716;003;ADL;1;[SSL] writeOpts: 199 bytes written
2019/11/13;18:12:48:716;004;ADL;8;DEBUG httpssm_ClientDataHandler 987 towrite: 199 bytes, written: 199 bytes<LF>
2019/11/13;18:12:48:717;001;ADL;8;INFO httpssm_ClientDataHandler 1003 WIP_CEV_WRITE(a) pPtr:199 ,cPtr:199, sz:199, sentsz:199

For failure connection:

2019/11/13;18:16:38:406;001;ADL;1;[SSL] subevh_handshake function 1 
2019/11/13;18:16:38:406;002;ADL;1;[req_event] WIP_CEV_ERROR
2019/11/13;18:16:38:406;003;ADL;1;[HTTP] error -986 @ 11c258a8
2019/11/13;18:16:38:406;004;ADL;1;[HTTP] channel closed by server
2019/11/13;18:16:38:410;001;ADL;8;ERR httpssm_ClientDataHandler 1208 WIP_CEV_ERROR -986<LF>

Do you mean without ssl, you can change apn1 and apn2 and establish http connection without resetting module?
If so, that means you did not handle ssl library well.

You can also try https with apn1 , and then stop and delete the session, stop the gprs bearer, restart the gprs with apn1, establish https, if it does not work, that means this is not related apn1 and apn2.

Hi jyijyi,

Do you mean without ssl, you can change apn1 and apn2 and establish http connection without resetting module?
If so, that means you did not handle ssl library well.

Yes, I think so.

You can also try https with apn1 , and then stop and delete the session, stop the gprs bearer, restart the gprs with apn1, establish https, if it does not work, that means this is not related apn1 and apn2.

I already tried these step when changing an APN, If I change to APN 2, the communication will not work. Then I change back to APN1 without reset, the communication works OK.
Seem like the server had stored something abbout APN or IP address.

So you confirm problem is from ssl library, right?
How do you stop the ssl library? Did you delete the ssl session?

Preformatted text`So you confirm problem is from ssl library, right?

Yes. I think I did not handle ssl library well

How do you stop the ssl library? Did you delete the ssl session?

I get SSL session by wip_SSLGetSessionFromHTTPSDataChannel, release the session by wip_SSLReleaseSession and close the SSL by wip_SSLClose(). All return value are successfully.

did you follow the user guide SSL_UGD.pdf Section 6.1. Typical Call Sequence to use WIP_COPT_FINALIZER ???

Hi,

You can see in my code in first post, I use wip_HTTPClientCreateOpts instead of wip_SSLClientCreateOpts. and use wip_SSLGetSessionFromHTTPSDataChannel(ev->channel) in the channel in evh to get ssl session.
My concern is, is wip_SSLReleaseSession release the ssl session when channel was closed.

you can have a look on the sample code wipssl_https_client().
There is a function closeAndClean() which might help you.

Thanks for your support.

you can have a look on the sample code wipssl_https_client().
There is a function closeAndClean() which might help you.

I followed the steps in this sample. wip_SSLClose returns OK. But it still not work when I change to APN2 without reset. But if I change back to APN1 without reset, the communication works OK.

Maybe you can also try the extended AT application and try with those SSL commands and see if there is any clue.

Hi jyijyi,

Thanks for your support.
I think the rootcause may be using SSL with HTTP ver 1.1. If the server and proxy is not changed, the TCP connection will be kept alive. When I perform a reset. TCP/IP stack will be reinit and start to handshake again, that is reason the communication is OK.