spec-socket.c 1.24 KB
Newer Older
1 2 3
/*
 * Alessandro Rubini for CERN, 2011 -- GNU LGPL v2.1 or later
 */
4
#include <pptp/pptp.h>
5 6 7 8 9 10 11 12 13 14 15
#include "spec.h"
#include "include/gpio.h"

int spec_errno;

/* This function should init the minic and get the mac address */
int spec_open_ch(struct pp_instance *ppi)
{
	uint8_t fake_addr[] = {0x00, 0x10, 0x20, 0x30, 0x40, 0x50};

	ep_init(fake_addr);
16
	ep_enable(1, 1);
17 18
	minic_init();

19 20
	memcpy(NP(ppi)->ch[PP_NP_GEN].addr, fake_addr, 6);
	memcpy(NP(ppi)->ch[PP_NP_EVT].addr, fake_addr, 6);
21 22 23 24 25 26 27

	return 0;
}

/* To receive and send packets, we call the minic low-level stuff */
int spec_recv_packet(struct pp_instance *ppi, void *pkt, int len)
{
28
	static int led;
29 30 31 32 33 34

	led ^= 1; /* blink one led at each rx event */
	gpio_out(GPIO_PIN_LED_LINK, led);
	return minic_rx_frame(pkt, pkt + 14, len - 14, NULL);
}

35
int spec_send_packet(struct pp_instance *ppi, void *pkt, int len, int chtype)
36
{
37
	static int led;
38 39 40 41 42 43 44

	led ^= 1; /* blink the other led at each tx event */
	gpio_out(GPIO_PIN_LED_STATUS, led);
	return minic_tx_frame(pkt, pkt + 14, len, NULL);
}

int pp_recv_packet(struct pp_instance *ppi, void *pkt, int len)
45
	__attribute__((alias("spec_recv_packet")));
46
int pp_send_packet(struct pp_instance *ppi, void *pkt, int len, int chtype)
47
	__attribute__((alias("spec_send_packet")));