lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] (no subject)


From: Saïd BENAISSA
Subject: [lwip-users] (no subject)
Date: Mon, 13 Jul 2020 15:19:11 +0200

I have configured my lwip with sarar514 dial-up, thats works fine for data mode. I have tried to use pppos (using lwip). after activation of options in the file "lwip/src/include/netif/ppp/ppp_opts.h".
 I solved the problem of includes file by finding out that all I had to do was to enable PPP support and authentication methods in the lwip ppp_opts.h .

Can you help me how figure out  PPPoS ? Can you check please where i made error ?
-----------------------------------

AT+CREG?


AT+CGDCONT=1,"IP","telenor.iot","0.0.0.0",0,0


AT+CGPADDR=1
                                                                                                                         
                                                                                                                         
ATD*99***1#                                                                                                              
                                                                                                                         
                                                                                                                         
step 1 
-----------------------------------------
/*
* =====================================================================================
*
* Filename: main-controller.c
*
* Description: Implementation of the main controller
*
* Version: 1.0
* Created: 05/14/2020 08:12:56 PM
* Revision: none
* Compiler: gcc
* Organization:
*
* =====================================================================================
*/
#include "main-controller.h"
#include <FreeRTOS.h>
#include <task.h>
#include "usart.h"
#include "timeouts.h"

/* Tasks */
TaskHandle_t task1Handle = NULL;
void task1(void *p)
{

int count = 0;
while (1)
{
printf("task 1 -------------:%D \r\n", count++);
vTaskDelay(1000);
}
}

/* PPPOS */

#ifndef PPPOS_SUPPORT
#define PPPOS_SUPPORT 1
#endif /* PPPOS_SUPPORT */

#if PPPOS_SUPPORT
#include "netif/ppp/ppp.h"
#include "netif/ppp/pppos.h"
#include "netif/ppp/pppapi.h"
#include "lwip/tcpip.h"
#include "lwip/priv/tcpip_priv.h"

#include "lwip/dns.h"
#include "lwip/dhcp.h"
#include <string.h>

#include "lwip/sio.h"
#define PPP_PTY_TEST
#endif /* PPPOS_SUPPORT */

#include "pppos_example.h"

#include <stdio.h>

#if PPPOS_SUPPORT
ppp_pcb *ppp = NULL;
struct netif ppp_netif;
bool ppp_conn_success = false;

/* PPPOS STATUS CALLBACK */

void status_cb(ppp_pcb *pcb, int err_code, void *ctx)
{
struct netif *pppif = ppp_netif(pcb);
LWIP_UNUSED_ARG(ctx);

switch (err_code)
{
case PPPERR_NONE:
{
#if LWIP_DNS
const ip_addr_t *ns;
#endif /* LWIP_DNS */
printf("status_cb: Connected\n");
#if PPP_IPV4_SUPPORT
printf(" our_ipaddr = %s\n", ipaddr_ntoa(&pppif->ip_addr));
printf(" his_ipaddr = %s\n", ipaddr_ntoa(&pppif->gw));
printf(" netmask = %s\n", ipaddr_ntoa(&pppif->netmask));
ppp_conn_success = true;
#if LWIP_DNS
ns = (ip_addr_t *)dns_getserver(0);
printf(" dns1 = %s\n", ipaddr_ntoa(ns));
ns = (ip_addr_t *)dns_getserver(1);
printf(" dns2 = %s\n", ipaddr_ntoa(ns));
#endif /* LWIP_DNS */
#endif /* PPP_IPV4_SUPPORT */
#if PPP_IPV6_SUPPORT
printf(" our6_ipaddr = %s\n", ip6addr_ntoa(netif_ip6_addr(pppif, 0)));
#endif /* PPP_IPV6_SUPPORT */
break;
}
case PPPERR_PARAM:
{
printf("status_cb: Invalid parameter\n");
break;
}
case PPPERR_OPEN:
{
printf("status_cb: Unable to open PPP session\n");
break;
}
case PPPERR_DEVICE:
{
printf("status_cb: Invalid I/O device for PPP\n");
break;
}
case PPPERR_ALLOC:
{
printf("status_cb: Unable to allocate resources\n");
break;
}
case PPPERR_USER:
{
printf("status_cb: User interrupt\n");
break;
}
case PPPERR_CONNECT:
{
printf("status_cb: Connection lost\n");
break;
}
case PPPERR_AUTHFAIL:
{
printf("status_cb: Failed authentication challenge\n");
break;
}
case PPPERR_PROTOCOL:
{
printf("status_cb: Failed to meet protocol\n");
break;
}
case PPPERR_PEERDEAD:
{
printf("status_cb: Connection timeout\n");
break;
}
case PPPERR_IDLETIMEOUT:
{
printf("status_cb: Idle Timeout\n");
break;
}
case PPPERR_CONNECTTIME:
{
printf("status_cb: Max connect time reached\n");
break;
}
case PPPERR_LOOPBACK:
{
printf("status_cb: Loopback detected\n");
break;
}
default:
{
printf("status_cb: Unknown error code %d\n", err_code);
break;
}
}

/*
* This should be in the switch case, this is put outside of the switch
* case for example readability.
*/

if (err_code == PPPERR_NONE)
{
return;
}

/* ppp_close() was previously called, don't reconnect */
if (err_code == PPPERR_USER)
{
/* ppp_free(); -- can be called here */
return;
}
ppp_conn_success = false;
/*
* Try to reconnect in 30 seconds, if you need a modem chatscript you have
* to do a much better signaling here ;-)
*/
ppp_connect(pcb, 30);
/* OR ppp_listen(pcb); */
}

/* PPPOS SERIAL OUTPUT CALLBACK */
// uint32_t output_cb(ppp_pcb *pcb, u8_t *data, uint32_t len, void *ctx) {
// for (int i = 0; i < len; i++){
// while (!(usart_is_tx_ready(SARA_SERIAL)));
// usart_write(SARA_SERIAL, data[i]);
// printf("%c", data[i]);
// }
// printf("\r\n\r\n");
// }

// uint32_t output_cb(ppp_pcb *pcb, u8_t *data, uint32_t len, void *ctx) {
// PRINT( true, data, len );
// extern UART_HandleTypeDef huart3;
// UartSendData( &huart3, data, len );
// return len;
// }

uint32_t output_cb(ppp_pcb *pcb, uint8_t *data, uint32_t len, void *ctx)
{
/* Iterate through the array and send the bytes */
// // Activate data mode ATD*99***1#
// uint32_t at_ppp_cmd[] = {'A', 'T', 'D', '*', '9', '9', '*', '*', '*', '1','#', '\r', '\n'};
saraR412m_connect(data, len);
// saraR412m_read(len);
delay_ms(4000);
return len;
}

/*** PPP READ FCT MUST BE LIKE THIS **/
// void PppRead( void const * argument ){
// DataType ppp_data;
// for(;;){
// if( ppp ){
// if( QueueNotEmpty( &seqCQueue ) ){
// if( QueueDelete( &seqCQueue, &ppp_data ) ){
// PRINT( false, ppp_data.index, ppp_data.size );
// taskENTER_CRITICAL();
// pppos_input_tcpip(ppp, ppp_data.index, ppp_data.size );//0x7e
// taskEXIT_CRITICAL();
// }
// }
// osDelay( 1 );
// }
// }
// }

/*
* === FUNCTION ======================================================================
* Name: mainController_init(void)
* Description: Initialize the main controller
* =====================================================================================
*/
void mainController_init(void)
{
saraR412m_init(); // Initialize sara
mainController_loop(); // start loop
}

/*
* === FUNCTION ======================================================================
* Name: mainController_loop(void)
* Description: Just a loop to keep the chip going.
* =====================================================================================
*/
void mainController_loop(void)
{

while (1)
{
delay_ms(500);
uint32_t ans[32];
// Network registration status, 1 means network registration URC +CREG: <stat> enabled
uint32_t at_is_nreg[] = {'A', 'T', '+', 'C', 'R', 'E', 'G', '=', '1', '\r', '\n'};
saraR412m_connect(at_is_nreg, sizeof(at_is_nreg) / sizeof(at_is_nreg[0]));
// saraR412m_read(ans);
delay_ms(2000);

// Check Network registration status AT+CREG:
uint32_t at_is_check_nreg[] = {'A', 'T', '+', 'C', 'R', 'E', 'G', '?', '\r', '\n'};
saraR412m_connect(at_is_check_nreg, sizeof(at_is_check_nreg) / sizeof(at_is_check_nreg[0]));
// saraR412m_read(ans);
delay_ms(2000);

// Set the APN for the Telenor NBIoT sim cards Set up PDP context. Refer to the service provider for APN info
uint32_t at_pdp_cmd[] = {'A', 'T', '+', 'C', 'G', 'D', 'C', 'O', 'N', 'T', '=', '1', ',', '"', 'I', 'P', '"', ',', '"', 't', 'e', 'l', 'e', 'n', 'o', 'r', '.', 'i', 'o', 't', '"', ',', '"', '0', '.', '0', '.', '0', '.', '0', '"', ',', '0', ',', '0', '\r', '\n'};
saraR412m_connect(at_pdp_cmd, sizeof(at_pdp_cmd) / sizeof(at_pdp_cmd[0]));
// saraR412m_read(ans);
delay_ms(4000);

// Get the assigned IP Address
uint32_t at_ip_cmd[] = {'A', 'T', '+', 'C', 'G', 'P', 'A', 'D', 'D', 'R', '=', '1', '\r', '\n'};
saraR412m_connect(at_ip_cmd, sizeof(at_ip_cmd) / sizeof(at_ip_cmd[0]));
// saraR412m_read(ans);
delay_ms(1000);

// Activate data mode ATD*99***1#
uint32_t at_ppp_cmd[] = {'A', 'T', 'D', '*', '9', '9', '*', '*', '*', '1', '#', '\r', '\n'};
saraR412m_connect(at_ppp_cmd, sizeof(at_ppp_cmd) / sizeof(at_ppp_cmd[0]));
// saraR412m_read(ans);
delay_ms(4000);

// // // xTaskCreate(task1, "FirstTask",200, (void*) 0, 1, &task1Handle);
// // // vTaskStartScheduler();
uint8_t ctx = 0;
// // delay_ms(4000);
// uint32_t data[] = {'A', 'T', 'D', '*', '9', '9', '*', '*', '*', '1','#', '\r', '\n'};
// output_cb(ppp, (uint8_t *) data, 24, &ctx);
// // output_cb( ppp, (uint8_t *) data, 24, &ctx );
// delay_ms(4000);

// tcpip_init(NULL,NULL);
tcp_init();

ppp = (&ppp_netif, output_cb, status_cb, &ctx);
printf("step 1 \n\r");
delay_ms(4000);

if (ppp_connect(ppp, 0) != ERR_OK)
{
printf("ppp connect failed\r\n");
while (1)
;
}
printf("step 2 \n\r");
ppp_set_default(ppp);
printf("step 3 \n\r");

return ctx;
}
}

#endif /* PPPOS_SUPPORT */



Said BENAISSA
+47 939 91 338

reply via email to

[Prev in Thread] Current Thread [Next in Thread]