ppp: set address and control field

Before sending to hdlc, set the address and control field.
Fix hardcode of ppp header size.
This commit is contained in:
Kristen Carlson Accardi 2010-05-10 13:06:37 -07:00 committed by Denis Kenzior
parent f13d5e2bad
commit 125fc62526
5 changed files with 16 additions and 8 deletions

View File

@ -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)

View File

@ -26,11 +26,15 @@
#define IPCP_PROTO 0x8021
#define PPP_IP_PROTO 0x0021
#define MD5 5
#define PPP_ADDR_FIELD 0xff
#define PPP_CTRL 0x03
struct ppp_chap;
struct ppp_net;
struct ppp_header {
guint8 address;
guint8 control;
guint16 proto;
guint8 info[0];
} __attribute__((packed));

View File

@ -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;

View File

@ -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;

View File

@ -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);