AmendHub

Download

jcs

/

wifi_da

/

wi-fi.h

 

(View History)

jcs   *: Don't rely on our static wifi_da persisting Latest amendment: 40 on 2025-01-07

1 /*
2 * Copyright (c) 2023 joshua stein <jcs@jcs.org>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #ifndef __WIFI_H__
18 #define __WIFI_H__
19
20 #include <stdlib.h>
21 #include "util.h"
22
23 #define DA_HEIGHT 25
24 #define DA_WIDTH 180
25
26 #define MAIN_MENU_ID 1
27 #define MAIN_MENU_ABOUT_ID 1
28 #define MAIN_MENU_QUIT_ID 3
29
30 #define PROMPT_DIALOG_ID 1
31 #define PROMPT_DIALOG_INPUT_FIELD_ID 3
32 #define PROMPT_DIALOG_PASSWORD_STORAGE_ID 4
33 #define PROMPT_DIALOG_INPUT_LABEL_ID 5
34 #define PROMPT_DIALOG_TITLE_LABEL_ID 6
35
36 #define ABOUT_DIALOG_ID 2
37
38 #define STR_BASE_ID 0
39 #define STR_FINDING_WIFI_ID 1
40 #define STR_NO_DEVICE_FOUND_ID 2
41 #define STR_NO_NETWORK_ID 3
42 #define STR_OTHER_NETWORK_ID 4
43 #define STR_DEBUG_LOGS_ID 5
44 #define STR_CONTINUE_ID 6
45 #define STR_CANCEL_ID 7
46 #define STR_SSID_DIALOG_TITLE_ID 8
47 #define STR_ENTER_SSID_ID 9
48 #define STR_SSID_ID 10
49 #define STR_PASSWORD_DIALOG_TITLE_ID 11
50 #define STR_REQUIRES_PASSWORD_ID 12
51 #define STR_PASSWORD_ID 13
52 #define STR_ABOUT_WIFI_ID 14
53
54 #define BLUESCSI_NETWORK_WIFI_CMD 0x1c
55 #define BLUESCSI_NETWORK_WIFI_CMD_SCAN 0x01
56 #define BLUESCSI_NETWORK_WIFI_CMD_COMPLETE 0x02
57 #define BLUESCSI_NETWORK_WIFI_CMD_SCAN_RESULTS 0x03
58 #define BLUESCSI_NETWORK_WIFI_CMD_INFO 0x04
59 #define BLUESCSI_NETWORK_WIFI_CMD_JOIN 0x05
60
61 #define hiword(x) (((short *)&(x))[0])
62 #define loword(x) (((short *)&(x))[1])
63
64 typedef short SICN[16];
65 typedef SICN **SICNHandle;
66
67 enum state {
68 STATE_CLOSED = 0,
69 STATE_INIT,
70 STATE_FINDING,
71 STATE_SCANNING,
72 STATE_IDLE
73 };
74
75 enum signal_icon_id {
76 SIGNAL_NO_DEVICE = 0,
77 SIGNAL_FINDING_DEVICE = 1,
78 SIGNAL_NONE = 2,
79 SIGNAL_1 = 3,
80 SIGNAL_2 = 4,
81 SIGNAL_3 = 5,
82 SIGNAL_4 = 6
83 };
84
85 struct wifi_da {
86 short state;
87 short str_res_id;
88 WindowPtr win;
89 Rect bounds;
90 ControlHandle ssid_list;
91 MenuHandle ssid_menu;
92 Rect ssid_menu_rect;
93 SICNHandle signal_icons;
94 Rect icon_rect;
95 BitMap win_shadow;
96 WindowPtr logger;
97 };
98
99 extern struct wifi_da wifi_da;
100
101 struct wifi_network_entry {
102 char ssid[64];
103 unsigned char bssid[6];
104 char rssi;
105 unsigned char channel;
106 unsigned char flags;
107 #define WIFI_NETWORK_FLAG_AUTH (1 << 0)
108 /* our own flag */
109 #define WIFI_NETWORK_FLAG_HIDDEN (1 << 8)
110 char _padding;
111 };
112
113 struct wifi_join_request {
114 char ssid[64];
115 char key[64];
116 unsigned char channel;
117 unsigned char _padding;
118 };
119
120 extern DCtlPtr dce;
121
122 extern short wifi_scsi_id;
123 enum {
124 WIFI_SCSI_ID_FINDING = -1,
125 WIFI_SCSI_ID_NONE = -2
126 };
127 extern unsigned long wifi_scan_started;
128 extern struct wifi_network_entry wifi_cur_info;
129 #define MAX_WIFI_NETWORKS 10
130 extern struct wifi_network_entry wifi_scan_networks[MAX_WIFI_NETWORKS];
131 extern short nwifi_scan_networks;
132 extern Cursor watch;
133
134 void wifi_about(void);
135
136 short find_str_res_id(void);
137 void logger_printf(const char *format, ...);
138
139 void create_window(short ctlrefnum);
140 void update_window(bool force);
141 void update_wifi_cur_info(void);
142 void update_wifi_ssid_list(bool update_networks);
143 void destroy_windows(void);
144 void activate_window(bool activate);
145 void window_mousedown(Point p);
146
147 short scsi_find_wifi(void);
148 bool scsi_wifi_scan(short lun);
149 bool scsi_wifi_scan_finished(short lun);
150 bool scsi_wifi_info(short lun, struct wifi_network_entry *resp);
151 short scsi_wifi_scan_results(short scsi_id,
152 struct wifi_network_entry *resp, short count);
153 bool scsi_wifi_join(short scsi_id, struct wifi_join_request *wjr);
154
155 #endif