ppp: set address and control field
PATCH 1/1 ppp: set address and control field
Before sending to hdlc, set the address and control field. Fix hardcode of ppp header size.
--- gatchat/gatppp.c | 9 +++++++-- gatchat/ppp.h | 4 ++++ gatchat/ppp_auth.c | 2 +- gatchat/ppp_cp.c | 6 ++---- gatchat/ppp_net.c | 3 ++- 5 files changed, 16 insertions(+), 8 deletions(-)
gatchat/gatppp.c +7 -2
@@ -148,7 +148,8 @@ static void ppp_receive(const unsigned char *buf, gsize len, void *data)*/ void ppp_transmit (GAtPPP *ppp,guint8 *packet,guint infolen) { -guint16 proto =get_host_short (packet); +struct ppp_header *header = (struct ppp_header *) packet; +guint16 proto =ppp_proto (packet);guint8 code;gboolean lcp = (proto ==LCP_PROTOCOL );guint32 xmit_accm =0 ;
@@ -167,7 +168,11 @@ void ppp_transmit(GAtPPP *ppp, guint8 *packet, guint infolen)g_at_hdlc_set_xmit_accm (ppp->hdlc, ~0U ); } -if (g_at_hdlc_send (ppp->hdlc, packet, infolen +2 ) == FALSE) + header->address =PPP_ADDR_FIELD ; + header->control =PPP_CTRL ; + +if (g_at_hdlc_send (ppp->hdlc, packet, + infolen +sizeof (*header)) == FALSE)g_print ("Failed to send a frame\n" );if (lcp)
gatchat/ppp.h +4 -0
@@ -26,11 +26,15 @@#define IPCP_PROTO 0x8021#define PPP_IP_PROTO 0x0021#define MD5 5 +#define PPP_ADDR_FIELD 0xff +#define PPP_CTRL 0x03struct ppp_chap ;struct ppp_net ;struct ppp_header { +guint8 address; +guint8 control;guint16 proto;guint8 info[0 ]; } __attribute__((packed));
gatchat/ppp_auth.c +1 -1
@@ -83,7 +83,7 @@ static void chap_process_challenge(struct ppp_chap *chap, const guint8 *packet)*/ digest_len =g_checksum_type_get_length (chap->method); response_length = digest_len +sizeof (*header) +1 ; - ppp_packet =g_try_malloc0 (response_length +2 ); + ppp_packet =g_try_malloc0 (response_length +sizeof (struct ppp_header ));if (!ppp_packet) goto challenge_out;
gatchat/ppp_cp.c +2 -4
@@ -61,10 +61,8 @@ static const char *pppcp_event_strings[] = {g_free (str); \ }while (0 ); -#define PPP_HEADROOM 2 -#define pppcp_to_ppp_packet (p) \ - (((guint8 *) p) - PPP_HEADROOM) + (((guint8 *) p) - sizeof(struct ppp_header))#define INITIAL_RESTART_TIMEOUT 3/* restart interval in seconds */ #define MAX_TERMINATE 2
@@ -206,7 +204,7 @@ static struct pppcp_packet *pppcp_packet_new(struct pppcp_data *data,struct ppp_header *ppp_packet;guint16 packet_length = bufferlen +sizeof (*packet); - ppp_packet =g_try_malloc0 (packet_length +2 ); + ppp_packet =g_try_malloc0 (packet_length +sizeof (*ppp_packet));if (!ppp_packet)return NULL ;
gatchat/ppp_net.c +2 -1
@@ -105,7 +105,8 @@ static gboolean ppp_net_callback(GIOChannel *channel, GIOCondition cond,if (cond &G_IO_IN ) {/* leave space to add PPP protocol field */ - status =g_io_channel_read_chars (channel, buf +2 , net->mtu, + status =g_io_channel_read_chars (channel, + buf +sizeof (struct ppp_header ), net->mtu, &bytes_read, &error);if (bytes_read >0 ) { ppp->proto =htons (PPP_IP_PROTO );
Signature · 1 line
1.6.6.1
Hi Kristen,
Quoted 2 lines
Before sending to hdlc, set the address and control field. Fix hardcode of ppp header size.
Patch has been applied with one minor modification:
gatchat/ppp.h line 30
Quoted 2 lines
gatchat/ppp.h +2
-0+#define PPP_ADDR_FIELD 0xff +#define PPP_CTRL 0x03
These really should be private.
gatchat/ppp_auth.c static void chap_process_challenge(struct ppp_chap *chap, · line 88
Quoted 8 lines
gatchat/ppp_auth.c +1
-1@@ -83,7 +83,7 @@ static void chap_process_challenge(struct ppp_chap *chap,const guint8 *packet) */ digest_len =g_checksum_type_get_length (chap->method); response_length = digest_len +sizeof (*header) +1 ; - ppp_packet =g_try_malloc0 (response_length +2 ); + ppp_packet =g_try_malloc0 (response_length +sizeof (struct ppp_header ));if (!ppp_packet) goto challenge_out;
Can we make this function use pppcp_packet_new or similar?
Regards,
-Denis