mirror of git://git.sysmocom.de/ofono
ppp: implement ppp_packet_new
This commit is contained in:
parent
0d8b86ed79
commit
3fff4c49c8
|
@ -84,6 +84,21 @@ void ppp_debug(GAtPPP *ppp, const char *str)
|
||||||
ppp->debugf(str, ppp->debug_data);
|
ppp->debugf(str, ppp->debug_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ppp_header *ppp_packet_new(gsize infolen, guint16 protocol)
|
||||||
|
{
|
||||||
|
struct ppp_header *ppp_packet;
|
||||||
|
|
||||||
|
ppp_packet = g_try_malloc0(infolen + sizeof(*ppp_packet));
|
||||||
|
if (ppp_packet == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
ppp_packet->proto = htons(protocol);
|
||||||
|
ppp_packet->address = PPP_ADDR_FIELD;
|
||||||
|
ppp_packet->control = PPP_CTRL;
|
||||||
|
|
||||||
|
return ppp_packet;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Silently discard packets which are received when they shouldn't be
|
* Silently discard packets which are received when they shouldn't be
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -114,3 +114,4 @@ void ppp_lcp_finished_notify(GAtPPP *ppp);
|
||||||
void ppp_set_recv_accm(GAtPPP *ppp, guint32 accm);
|
void ppp_set_recv_accm(GAtPPP *ppp, guint32 accm);
|
||||||
void ppp_set_xmit_accm(GAtPPP *ppp, guint32 accm);
|
void ppp_set_xmit_accm(GAtPPP *ppp, guint32 accm);
|
||||||
void ppp_set_mtu(GAtPPP *ppp, const guint8 *data);
|
void ppp_set_mtu(GAtPPP *ppp, const guint8 *data);
|
||||||
|
struct ppp_header *ppp_packet_new(gsize infolen, guint16 protocol);
|
||||||
|
|
|
@ -83,12 +83,10 @@ static void chap_process_challenge(struct ppp_chap *chap, const guint8 *packet)
|
||||||
*/
|
*/
|
||||||
digest_len = g_checksum_type_get_length(chap->method);
|
digest_len = g_checksum_type_get_length(chap->method);
|
||||||
response_length = digest_len + sizeof(*header) + 1;
|
response_length = digest_len + sizeof(*header) + 1;
|
||||||
ppp_packet = g_try_malloc0(response_length + sizeof(struct ppp_header));
|
ppp_packet = ppp_packet_new(response_length, CHAP_PROTOCOL);
|
||||||
if (!ppp_packet)
|
if (!ppp_packet)
|
||||||
goto challenge_out;
|
goto challenge_out;
|
||||||
|
|
||||||
/* add our protocol information */
|
|
||||||
ppp_packet->proto = htons(CHAP_PROTOCOL);
|
|
||||||
response = (struct chap_header *) &ppp_packet->info;
|
response = (struct chap_header *) &ppp_packet->info;
|
||||||
if (response) {
|
if (response) {
|
||||||
response->code = RESPONSE;
|
response->code = RESPONSE;
|
||||||
|
|
|
@ -204,13 +204,10 @@ static struct pppcp_packet *pppcp_packet_new(struct pppcp_data *data,
|
||||||
struct ppp_header *ppp_packet;
|
struct ppp_header *ppp_packet;
|
||||||
guint16 packet_length = bufferlen + sizeof(*packet);
|
guint16 packet_length = bufferlen + sizeof(*packet);
|
||||||
|
|
||||||
ppp_packet = g_try_malloc0(packet_length + sizeof(*ppp_packet));
|
ppp_packet = ppp_packet_new(packet_length, data->driver->proto);
|
||||||
if (!ppp_packet)
|
if (!ppp_packet)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* add our protocol information */
|
|
||||||
ppp_packet->proto = htons(data->driver->proto);
|
|
||||||
|
|
||||||
/* advance past protocol to add CP header information */
|
/* advance past protocol to add CP header information */
|
||||||
packet = (struct pppcp_packet *) (ppp_packet->info);
|
packet = (struct pppcp_packet *) (ppp_packet->info);
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@ struct ppp_net {
|
||||||
GIOChannel *channel;
|
GIOChannel *channel;
|
||||||
gint watch;
|
gint watch;
|
||||||
gint mtu;
|
gint mtu;
|
||||||
|
struct ppp_header *ppp_packet;
|
||||||
};
|
};
|
||||||
|
|
||||||
gboolean ppp_net_set_mtu(struct ppp_net *net, guint16 mtu)
|
gboolean ppp_net_set_mtu(struct ppp_net *net, guint16 mtu)
|
||||||
|
@ -95,23 +96,21 @@ static gboolean ppp_net_callback(GIOChannel *channel, GIOCondition cond,
|
||||||
{
|
{
|
||||||
struct ppp_net *net = (struct ppp_net *) userdata;
|
struct ppp_net *net = (struct ppp_net *) userdata;
|
||||||
GIOStatus status;
|
GIOStatus status;
|
||||||
gchar buf[MAX_PACKET + sizeof(struct ppp_header)];
|
|
||||||
gsize bytes_read;
|
gsize bytes_read;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
struct ppp_header *ppp = (struct ppp_header *) buf;
|
gchar *buf = (gchar *) net->ppp_packet->info;
|
||||||
|
|
||||||
if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP))
|
if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (cond & G_IO_IN) {
|
if (cond & G_IO_IN) {
|
||||||
/* leave space to add PPP protocol field */
|
/* leave space to add PPP protocol field */
|
||||||
status = g_io_channel_read_chars(channel,
|
status = g_io_channel_read_chars(channel, buf, net->mtu,
|
||||||
buf + sizeof(struct ppp_header), net->mtu,
|
&bytes_read, &error);
|
||||||
&bytes_read, &error);
|
if (bytes_read > 0)
|
||||||
if (bytes_read > 0) {
|
ppp_transmit(net->ppp, (guint8 *) net->ppp_packet,
|
||||||
ppp->proto = htons(PPP_IP_PROTO);
|
bytes_read);
|
||||||
ppp_transmit(net->ppp, (guint8 *) buf, bytes_read);
|
|
||||||
}
|
|
||||||
if (status != G_IO_STATUS_NORMAL && status != G_IO_STATUS_AGAIN)
|
if (status != G_IO_STATUS_NORMAL && status != G_IO_STATUS_AGAIN)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -135,6 +134,12 @@ struct ppp_net *ppp_net_new(GAtPPP *ppp)
|
||||||
if (net == NULL)
|
if (net == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
net->ppp_packet = ppp_packet_new(MAX_PACKET, PPP_IP_PROTO);
|
||||||
|
if (net->ppp_packet == NULL) {
|
||||||
|
g_free(net);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* open a tun interface */
|
/* open a tun interface */
|
||||||
fd = open("/dev/net/tun", O_RDWR);
|
fd = open("/dev/net/tun", O_RDWR);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
|
@ -176,6 +181,8 @@ error:
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
g_free(net->if_name);
|
||||||
|
g_free(net->ppp_packet);
|
||||||
g_free(net);
|
g_free(net);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -185,6 +192,7 @@ void ppp_net_free(struct ppp_net *net)
|
||||||
g_source_remove(net->watch);
|
g_source_remove(net->watch);
|
||||||
g_io_channel_unref(net->channel);
|
g_io_channel_unref(net->channel);
|
||||||
|
|
||||||
|
g_free(net->ppp_packet);
|
||||||
g_free(net->if_name);
|
g_free(net->if_name);
|
||||||
g_free(net);
|
g_free(net);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue