- prepared for cheap request

git-svn-id: http://moon:8086/svn/mips@224 a8ebac50-d88d-4704-bea3-6648445a41b3
This commit is contained in:
2021-11-25 21:15:10 +00:00
parent d35075c34f
commit c89a796597
3 changed files with 31 additions and 21 deletions
+17 -7
View File
@@ -15,10 +15,11 @@
const char hostname[] = "ml402"; const char hostname[] = "ml402";
const char vendor[] = "Jayfield Inc."; const char vendor[] = "Jayfield Inc.";
static uint32_t xid = 0;
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// Testing // Testing
void DHCP_request_send(packet_t *pPacket, uint8_t dhcp_msg_type, uint8_t *mac_addr_src, uint8_t *inet_addr_src, uint8_t *inet_addr_dst, DHCP *pLast) void DHCP_request_send(packet_t *pPacket, uint8_t dhcp_msg_type, uint8_t *mac_addr_src, uint8_t *inet_addr_src, uint8_t *inet_addr_dst)
{ {
DHCP dhcp; DHCP dhcp;
uint32_t size; uint32_t size;
@@ -57,9 +58,10 @@ void DHCP_request_send(packet_t *pPacket, uint8_t dhcp_msg_type, uint8_t *mac_ad
{ {
case DHCP_MSG_DHCPDISCOVER: case DHCP_MSG_DHCPDISCOVER:
{ {
pDHCP->xid = (uint32_t)rand(); xid = (uint32_t)rand();
pDHCP->xid = xid;
// Request subnet mask
// Request list
size = 0; size = 0;
buffer[size++] = DHCP_OPT_SUBNETMASK; buffer[size++] = DHCP_OPT_SUBNETMASK;
buffer[size++] = DHCP_OPT_ROUTER; buffer[size++] = DHCP_OPT_ROUTER;
@@ -74,10 +76,18 @@ void DHCP_request_send(packet_t *pPacket, uint8_t dhcp_msg_type, uint8_t *mac_ad
case DHCP_MSG_DHCPREQUEST: case DHCP_MSG_DHCPREQUEST:
{ {
pDHCP->xid = pLast->xid; pDHCP->xid = xid;
// Set requested IP address // Request list
option_list_append(&options, DHCP_OPT_REQIP, pLast->yiaddr, size); size = 0;
buffer[size++] = DHCP_OPT_SUBNETMASK;
buffer[size++] = DHCP_OPT_ROUTER;
buffer[size++] = DHCP_OPT_DOMAIN_NS;
buffer[size++] = 121;
buffer[size++] = 249;
buffer[size++] = 42;
buffer[size++] = 158;
option_list_append(&options, DHCP_OPT_PARAM_REQ_LIST, buffer, size);
} }
break; break;
+1 -1
View File
@@ -80,7 +80,7 @@ typedef struct _soption_list_t
#define DHCP_MSG_DHCPRELEASE 7 #define DHCP_MSG_DHCPRELEASE 7
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
void DHCP_request_send(packet_t *pPacket, uint8_t dhcp_msg_type, uint8_t *mac_addr_src, uint8_t *inet_addr_src, uint8_t *inet_addr_dst, DHCP *pLast); void DHCP_request_send(packet_t *pPacket, uint8_t dhcp_msg_type, uint8_t *mac_addr_src, uint8_t *inet_addr_src, uint8_t *inet_addr_dst);
void option_list_init(option_list_t *pObj, void *pBuffer, size_t size); void option_list_init(option_list_t *pObj, void *pBuffer, size_t size);
void option_list_append(option_list_t *pObj, uint8_t option_type, void const *pData, size_t size); void option_list_append(option_list_t *pObj, uint8_t option_type, void const *pData, size_t size);
size_t data_entry_create(void *pDst, uint8_t type, void const *pData, size_t size); size_t data_entry_create(void *pDst, uint8_t type, void const *pData, size_t size);
+13 -13
View File
@@ -336,28 +336,28 @@ int main()
DHCP *pDHCP; DHCP *pDHCP;
if (dhcp_state == 1) if (dhcp_state == 1)
{ {
for (int kk=0; kk < 1; kk++) sleep(3000);
{ printf("---------------------------------------------------------------\n");
printf("---------------------------------------------------------------\n"); printf("- Send DHCP Discover ------------------------------------------\n");
printf("- Send DHCP Discover ------------------------------------------\n"); printf("---------------------------------------------------------------\n");
printf("---------------------------------------------------------------\n"); Eth_pkt_create(&packet, TYPE_PROTO_IP, eth_myself, eth_bcst);
sleep(3000); DHCP_request_send(&packet, DHCP_MSG_DHCPDISCOVER, eth_myself, ip_zero, ip_bcast);
Eth_pkt_create(&packet, TYPE_PROTO_IP, eth_myself, eth_bcst); PrintBuffer8((uint8_t*)packet.pkt_buf, 16, packet.size);
DHCP_request_send(&packet, DHCP_MSG_DHCPDISCOVER, eth_myself, ip_zero, ip_bcast, NULL); Eth_pkt_send(&packet);
PrintBuffer8((uint8_t*)packet.pkt_buf, 16, packet.size); dhcp_state = 2;
Eth_pkt_send(&packet);
}
dhcp_state = 0;
} }
if (dhcp_state == 2) if (dhcp_state == 2)
{ {
sleep(3000);
printf("---------------------------------------------------------------\n"); printf("---------------------------------------------------------------\n");
printf("- Send DHCP Request -------------------------------------------\n"); printf("- Send DHCP Request -------------------------------------------\n");
printf("---------------------------------------------------------------\n"); printf("---------------------------------------------------------------\n");
Eth_pkt_create(&packet, TYPE_PROTO_IP, eth_myself, eth_bcst); Eth_pkt_create(&packet, TYPE_PROTO_IP, eth_myself, eth_bcst);
DHCP_request_send(&packet, DHCP_MSG_DHCPREQUEST, eth_myself, ip_zero, ip_bcast, pDHCP); DHCP_request_send(&packet, DHCP_MSG_DHCPREQUEST, eth_myself, ip_zero, ip_bcast);
Eth_pkt_send(&packet); Eth_pkt_send(&packet);
dhcp_state = 0;
} }
if (dhcp_state == 3) if (dhcp_state == 3)