1 | // DSWifi Project - sgIP Internet Protocol Stack Implementation |
---|
2 | // Copyright (C) 2005-2006 Stephen Stair - sgstair@akkit.org - http://www.akkit.org |
---|
3 | /****************************************************************************** |
---|
4 | DSWifi Lib and test materials are licenced under the MIT open source licence: |
---|
5 | Copyright (c) 2005-2006 Stephen Stair |
---|
6 | |
---|
7 | Permission is hereby granted, free of charge, to any person obtaining a copy of |
---|
8 | this software and associated documentation files (the "Software"), to deal in |
---|
9 | the Software without restriction, including without limitation the rights to |
---|
10 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
---|
11 | of the Software, and to permit persons to whom the Software is furnished to do |
---|
12 | so, subject to the following conditions: |
---|
13 | |
---|
14 | The above copyright notice and this permission notice shall be included in all |
---|
15 | copies or substantial portions of the Software. |
---|
16 | |
---|
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
---|
23 | SOFTWARE. |
---|
24 | ******************************************************************************/ |
---|
25 | #ifndef SGIP_DHCP_H |
---|
26 | #define SGIP_DHCP_H |
---|
27 | |
---|
28 | #include "sgIP_Config.h" |
---|
29 | #include "sgIP_Hub.h" |
---|
30 | |
---|
31 | // "DHCP Server" port is 67, "DHCP Client" port is 68 |
---|
32 | // DHCP messages broadcast by a client prior to that client obtaining its IP address must have the source address field in the IP header set to 0. |
---|
33 | |
---|
34 | |
---|
35 | |
---|
36 | typedef struct SGIP_DHCP_PACKET { // yes, freaking big endian prevails here too. |
---|
37 | unsigned char op; // opcode/message type (1=BOOTREQUEST, 2=BOOTREPLY) |
---|
38 | unsigned char htype; // hardware address type |
---|
39 | unsigned char hlen; // Hardware address length (should be 6, for ethernet/wifi) |
---|
40 | unsigned char hops; // set to 0 |
---|
41 | unsigned long xid; // 4-byte client specified transaction ID |
---|
42 | unsigned short secs; // seconds elapsed since client started trying to boot |
---|
43 | unsigned short flags; // flags |
---|
44 | unsigned long ciaddr; // client IP address, filled in by client if verifying previous params |
---|
45 | unsigned long yiaddr; // "your" (client) IP address |
---|
46 | unsigned long siaddr; // IP addr of next server to use in bootstrap. |
---|
47 | unsigned long giaddr; // Relay agent IP address |
---|
48 | unsigned char chaddr[16]; // client hardware address |
---|
49 | char sname[64]; // optional server hostname (null terminated string) |
---|
50 | char file[128]; // boot file name, null terminated string |
---|
51 | char options[312]; // optional parameters |
---|
52 | } sgIP_DHCP_Packet; |
---|
53 | |
---|
54 | enum SGIP_DHCP_STATUS { |
---|
55 | SGIP_DHCP_STATUS_IDLE, |
---|
56 | SGIP_DHCP_STATUS_WORKING, |
---|
57 | SGIP_DHCP_STATUS_FAILED, |
---|
58 | SGIP_DHCP_STATUS_SUCCESS |
---|
59 | }; |
---|
60 | |
---|
61 | #define DHCP_TYPE_DISCOVER 1 |
---|
62 | #define DHCP_TYPE_OFFER 2 |
---|
63 | #define DHCP_TYPE_REQUEST 3 |
---|
64 | #define DHCP_TYPE_ACK 5 |
---|
65 | #define DHCP_TYPE_RELEASE 7 |
---|
66 | |
---|
67 | |
---|
68 | #ifdef __cplusplus |
---|
69 | extern "C" { |
---|
70 | #endif |
---|
71 | |
---|
72 | void sgIP_DHCP_Init(void); |
---|
73 | |
---|
74 | void sgIP_DHCP_SetHostName(char * s); // just for the fun of it. |
---|
75 | int sgIP_DHCP_IsDhcpIp(unsigned long ip); // check if the IP address was assigned via dhcp. |
---|
76 | void sgIP_DHCP_Start(sgIP_Hub_HWInterface * interface, int getDNS); // begin dhcp transaction to get IP and maybe DNS data. |
---|
77 | void sgIP_DHCP_Release(void); // call to dump our DHCP address and leave. |
---|
78 | int sgIP_DHCP_Update(void); // MUST be called periodicly after _Start; returns status - call until it returns something other than SGIP_DHCP_STATUS_WORKING |
---|
79 | void sgIP_DHCP_Terminate(void); // kill the process where it stands; deallocate all DHCP resources. |
---|
80 | |
---|
81 | #ifdef __cplusplus |
---|
82 | }; |
---|
83 | #endif |
---|
84 | |
---|
85 | |
---|
86 | #endif |
---|