1: /*
2: * Guitar-ZyX(tm)::MasterControlProgram - portable guitar F/X controller
3: * Copyright (C) 2009 Douglas McClendon
4: *
5: * This program is free software: you can redistribute it and/or modify
6: * it under the terms of the GNU General Public License as published by
7: * the Free Software Foundation, version 3 of the License.
8: *
9: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program. If not, see <http://www.gnu.org/licenses/>.
16: */
17: /*
18: #############################################################################
19: #############################################################################
20: #
21: # gzmcpc::network: network functions
22: #
23: #############################################################################
24: ##
25: ## Copyright 2008-2009 Douglas McClendon <dmc AT filteredperception DOT org>
26: ##
27: #############################################################################
28: #############################################################################
29: #
30: */
31:
32: #ifndef _NDS_CLIENT_NETWORK_H
33: #define _NDS_CLIENT_NETWORK_H
34:
35:
36:
37:
38:
39: #define WSCANNING_TIMEOUT_S 7
40:
41: #define WASSOCIATING_TIMEOUT_S 42
42:
43: #define BCAST_LISTEN_TIMEOUT_S 3600
44:
45:
46: #define ZYX_AP_NAME "unset"
47:
48:
49: #define GZMPCD_CMD_PORTNUM 24642
50:
51: #define GZMPCD_BCAST_PORTNUM 24642
52: #define DEFAULT_NETWORK_EVENT_RATE 60
53:
54:
55: #define SSID_MAXLEN 63
56:
57:
58:
59:
60: #include "gzmcp_protocol.h"
61:
62: #include <dswifi9.h>
63:
64: #include "time.h"
65:
66:
67:
68:
69: typedef enum {
70: NSM_START,
71: NSM_OFFLINE,
72: NSM_WSCANNING,
73: NSM_WASSOCIATING,
74: NSM_BCAST_LISTEN,
75: NSM_UNCONNECTED,
76: NSM_CONNECTED,
77: NSM_HANDSHAKE_SENT,
78: NSM_ONLINE,
79: } network_state_mode;
80:
81:
82:
83:
84: void gzmcpc_init_wifi(void);
85:
86: void gzmcpc_init_net(void);
87:
88: void socket_set_blocking(int socket_fd);
89: void socket_set_nonblocking(int socket_fd);
90:
91: void debug_dump_cmd(gzmcp_cmd cmd);
92:
93: int xmit_cmd(int socket_fd, gzmcp_cmd cmd);
94:
95: void sync_with_server(void);
96:
97: void netmode_go_offline(void);
98:
99:
100: void netmode_offline_init(void);
101: network_state_mode netmode_offline_handle(void);
102:
103: void netmode_wscanning_init(void);
104: network_state_mode netmode_wscanning_handle(void);
105:
106: void netmode_wassociating_init(void);
107: network_state_mode netmode_wassociating_handle(void);
108:
109: void netmode_bcast_listen_init(void);
110: network_state_mode netmode_bcast_listen_handle(void);
111:
112: void netmode_unconnected_init(void);
113: network_state_mode netmode_unconnecected_handle(void);
114:
115: void netmode_connected_init(void);
116: network_state_mode netmode_connected_handle(void);
117:
118: void netmode_handshake_sent_init(void);
119: network_state_mode netmode_handshake_sent_handle(void);
120:
121: void netmode_online_init(void);
122: network_state_mode netmode_online_handle(void);
123:
124: network_state_mode gzmcpc_net_next_state(network_state_mode current);
125:
126:
127:
128:
129:
130: extern network_state_mode network_state;
131: extern network_state_mode last_network_state;
132: extern int nsm_init;
133:
134: extern u8 network_event_rate;
135:
136: extern int socket_shutdown_state;
137:
138: extern int zyx_ap_id;
139:
140: extern Wifi_AccessPoint zyx_ap;
141:
142: extern unsigned char wepkeys[4][32];
143:
144: extern int wepkeyid;
145:
146: extern int wepmode;
147:
148: extern int dhcp;
149:
150: extern struct in_addr gzmcpc_ipaddr;
151: extern int gzmcpc_ipaddr_last_byte;
152: extern struct in_addr gzmcpc_subnet_mask;
153: extern struct in_addr gzmcpc_gateway;
154: extern struct in_addr gzmcpc_dns1;
155: extern struct in_addr gzmcpc_dns2;
156:
157: extern char ap_ssid[SSID_MAXLEN + 1];
158:
159: extern time_val next_sync_with_server;
160:
161: extern int cstate_preset;
162: extern char cstate_preset_name[64];
163: extern int cstate_wpx;
164: extern int cstate_wpy;
165:
166: extern int server_socket_fd;
167:
168: #endif // _NDS_CLIENT_NETWORK_H
169: