-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathnet.c
112 lines (92 loc) · 2.46 KB
/
net.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "pktdrv.h"
#include <hal/xbox.h>
#include <lwip/api.h>
#include <lwip/arch.h>
#include <lwip/debug.h>
#include <lwip/dhcp.h>
#include <lwip/init.h>
#include <lwip/netif.h>
#include <lwip/opt.h>
#include <lwip/sys.h>
#include <lwip/tcpip.h>
#include <netif/etharp.h>
#include <pbkit/pbkit.h>
#include <protobuf-c/protobuf-c.h>
#include <stdlib.h>
#include <xboxkrnl/xboxkrnl.h>
#include <hal/debug.h>
#include "net.h"
#define USE_DHCP 1
#define PKT_TMR_INTERVAL 5 /* ms */
#define DEBUGGING 0
struct netif nforce_netif, *g_pnetif;
extern err_t nforceif_init(struct netif *netif);
#if LWIP_NETCONN
static void packet_timer(void *arg);
static void tcpip_init_done(void *arg);
int net_init(void)
{
sys_sem_t init_complete;
const ip4_addr_t *ip;
static ip4_addr_t ipaddr, netmask, gw;
#if DEBUGGING
asm volatile ("jmp .");
debug_flags = LWIP_DBG_ON;
#else
debug_flags = 0;
#endif
#if USE_DHCP
IP4_ADDR(&gw, 0,0,0,0);
IP4_ADDR(&ipaddr, 0,0,0,0);
IP4_ADDR(&netmask, 0,0,0,0);
#else
IP4_ADDR(&gw, 10,0,1,1);
IP4_ADDR(&ipaddr, 10,0,1,7);
IP4_ADDR(&netmask, 255,255,255,0);
#endif
/* Initialize the TCP/IP stack. Wait for completion. */
sys_sem_new(&init_complete, 0);
tcpip_init(tcpip_init_done, &init_complete);
sys_sem_wait(&init_complete);
sys_sem_free(&init_complete);
g_pnetif = netif_add(&nforce_netif, &ipaddr, &netmask, &gw,
NULL, nforceif_init, ethernet_input);
if (!g_pnetif) {
debugPrint("netif_add failed\n");
return 1;
}
netif_set_default(g_pnetif);
netif_set_up(g_pnetif);
#if USE_DHCP
dhcp_start(g_pnetif);
#endif
packet_timer(NULL);
#if USE_DHCP
debugPrint("Waiting for DHCP...\n");
while (dhcp_supplied_address(g_pnetif) == 0)
NtYieldExecution();
debugPrint("DHCP bound!\n");
#endif
debugPrint("\n");
debugPrint("IP address.. %s\n", ip4addr_ntoa(netif_ip4_addr(g_pnetif)));
debugPrint("Mask........ %s\n", ip4addr_ntoa(netif_ip4_netmask(g_pnetif)));
debugPrint("Gateway..... %s\n", ip4addr_ntoa(netif_ip4_gw(g_pnetif)));
debugPrint("\n");
return 0;
}
void net_shutdown(void)
{
Pktdrv_Quit();
}
static void tcpip_init_done(void *arg)
{
sys_sem_t *init_complete = arg;
sys_sem_signal(init_complete);
}
static void packet_timer(void *arg)
{
LWIP_UNUSED_ARG(arg);
Pktdrv_ReceivePackets();
sys_timeout(PKT_TMR_INTERVAL, packet_timer, NULL);
}
#endif /* LWIP_NETCONN*/