static int bootme_src_port = 0xdeadface;
static int bootme_dst_port = 0xdeadbeef;
static uchar bootme_ether[ETH_ALEN];
-static IPaddr_t bootme_ip;
+static struct in_addr bootme_ip;
static int bootme_timed_out;
static const char *output_packet; /* used by first send udp */
static int output_packet_len;
}
printf("%02x ", p[i]);
- if (!((i + 1) % 16)){
+ if (!((i + 1) % 16)) {
printf(" ");
for (j = i - 15; j <= i; j++){
- if((p[j] > 0x1f) && (p[j] < 0x7f)) {
+ if ((p[j] > 0x1f) && (p[j] < 0x7f)) {
printf("%c", p[j]);
} else {
printf(".");
static int env_id;
-static int is_broadcast(IPaddr_t ip)
+static int is_broadcast(struct in_addr ip)
{
- static IPaddr_t netmask;
- static IPaddr_t our_ip;
+ static struct in_addr netmask;
+ static struct in_addr our_ip;
- return (ip == ~0 || /* 255.255.255.255 */
- ((netmask & our_ip) == (netmask & ip) && /* on the same net */
- (netmask | ip) == ~0)); /* broadcast to our net */
+ return (ip.s_addr == ~0 || /* 255.255.255.255 */
+ ((netmask.s_addr & our_ip.s_addr) == (netmask.s_addr & ip.s_addr) && /* on the same net */
+ (netmask.s_addr | ip.s_addr) == ~0)); /* broadcast to our net */
}
static int check_net_config(void)
char *bip;
bootme_dst_port = EDBG_DOWNLOAD_PORT;
- if (bootme_ip == 0) {
+ if (bootme_ip.s_addr == 0) {
bip = getenv("bootmeip");
if (bip) {
- bootme_ip = getenv_IPaddr("bootmeip");
- if (!bootme_ip)
+ bootme_ip = getenv_ip("bootmeip");
+ if (!bootme_ip.s_addr)
return -EINVAL;
p = strchr(bip, ':');
if (p) {
memset(bootme_ether, 0, sizeof(bootme_ether));
net_init();
- NetServerIP = bootme_ip;
+ net_copy_ip(&net_server_ip, &bootme_ip);
}
return 0;
}
static void bootme_wait_arp_handler(uchar *pkt, unsigned dest,
- IPaddr_t sip, unsigned src,
+ struct in_addr sip, unsigned src,
unsigned len)
{
net_set_state(NETLOOP_SUCCESS); /* got arp reply - quit net loop */
return 0;
}
-static void bootme_handler(uchar *pkt, unsigned dest_port, IPaddr_t src_ip,
+static void bootme_handler(uchar *pkt, unsigned dest_port, struct in_addr src_ip,
unsigned src_port, unsigned len)
{
uchar *eth_pkt = pkt;
printf("%c\x08", cursor);
cursor = next_cursor(cursor);
- if (!is_broadcast(bootme_ip) && src_ip != bootme_ip) {
+ if (!is_broadcast(bootme_ip) && src_ip.s_addr != bootme_ip.s_addr) {
debug("src_ip %pI4 does not match destination IP %pI4\n",
&src_ip, &bootme_ip);
return; /* not from our server */
}
if (bootme_state == BOOTME_INIT || bootme_state == BOOTME_DEBUG_INIT) {
struct ethernet_hdr *eth = (struct ethernet_hdr *)(pkt -
- NetEthHdrSize() - IP_UDP_HDR_SIZE);
+ net_eth_hdr_size() - IP_UDP_HDR_SIZE);
memcpy(bootme_ether, eth->et_src, sizeof(bootme_ether));
printf("Target MAC address set to %pM\n", bootme_ether);
if (is_broadcast(bootme_ip)) {
- NetCopyIP(&bootme_ip, &src_ip);
+ net_copy_ip(&bootme_ip, &src_ip);
}
}
if (bootme_state == BOOTME_INIT) {
case BOOTME_DOWNLOAD:
if (last_state != BOOTME_INIT)
- NetBootFileXferSize += len - 4;
+ net_boot_file_size += len - 4;
/* fallthru */
case BOOTME_DEBUG:
if (last_state == BOOTME_INIT ||
last_state == BOOTME_DEBUG_INIT)
bootme_timeout = 3 * 1000;
- NetSetTimeout(bootme_timeout, bootme_timeout_handler);
+ net_set_timeout_handler(bootme_timeout, bootme_timeout_handler);
break;
case BOOTME_DONE:
check_net_config();
if (output_packet_len == 0 ||
- memcmp(bootme_ether, NetEtherNullAddr, ETH_ALEN) != 0) {
+ is_valid_ethaddr(bootme_ether)) {
/* wait for incoming packet */
net_set_udp_handler(bootme_handler);
bootme_timed_out = 0;
- NetSetTimeout(bootme_timeout, bootme_timeout_handler);
+ net_set_timeout_handler(bootme_timeout, bootme_timeout_handler);
} else {
/* send ARP request */
uchar *pkt;
net_set_arp_handler(bootme_wait_arp_handler);
- assert(NetTxPacket != NULL);
- pkt = (uchar *)NetTxPacket + NetEthHdrSize() + IP_UDP_HDR_SIZE;
+ assert(net_tx_packet != NULL);
+ pkt = (uchar *)net_tx_packet + net_eth_hdr_size() + IP_UDP_HDR_SIZE;
memcpy(pkt, output_packet, output_packet_len);
debug("%s@%d: Sending ARP request:\n", __func__, __LINE__);
ce_dump_block(pkt, output_packet_len);
- NetSendUDPPacket(bootme_ether, bootme_ip, bootme_dst_port,
+ net_send_udp_packet(bootme_ether, bootme_ip, bootme_dst_port,
bootme_src_port, output_packet_len);
output_packet_len = 0;
}
check_net_config();
debug("%s: buf: %p len: %u from %pI4:%d to %pI4:%d\n",
- __func__, buf, len, &NetOurIP, bootme_src_port, &bootme_ip,
+ __func__, buf, len, &net_ip, bootme_src_port, &bootme_ip,
bootme_dst_port);
- if (memcmp(bootme_ether, NetEtherNullAddr, ETH_ALEN) == 0) {
+ if (is_zero_ethaddr(bootme_ether)) {
output_packet = buf;
output_packet_len = len;
/* wait for arp reply and send packet */
- ret = NetLoop(BOOTME);
+ ret = net_loop(BOOTME);
if (ret < 0) {
/* drop packet */
output_packet_len = 0;
return 0;
}
- assert(NetTxPacket != NULL);
- pkt = (uchar *)NetTxPacket + NetEthHdrSize() + IP_UDP_HDR_SIZE;
+ if (eth->state != ETH_STATE_ACTIVE) {
+ if (eth_is_on_demand_init()) {
+ ret = eth_init();
+ if (ret < 0)
+ return ret;
+ eth_set_last_protocol(BOOTME);
+ } else {
+ eth_init_state_only();
+ }
+ }
+
+ assert(net_tx_packet != NULL);
+ pkt = (uchar *)net_tx_packet + net_eth_hdr_size() + IP_UDP_HDR_SIZE;
memcpy(pkt, buf, len);
- ret = NetSendUDPPacket(bootme_ether, bootme_ip, bootme_dst_port,
+ ret = net_send_udp_packet(bootme_ether, bootme_ip, bootme_dst_port,
bootme_src_port, len);
if (ret)
printf("Failed to send packet: %d\n", ret);
return ret;
}
-static void bootme_init(IPaddr_t server_ip)
+static void bootme_init(struct in_addr server_ip)
{
debug("%s@%d: bootme_state: %d -> %d\n", __func__, __LINE__,
bootme_state, BOOTME_INIT);
bootme_state = BOOTME_INIT;
- bootme_ip = server_ip;
+ net_copy_ip(&bootme_ip, &server_ip);
/* force reconfiguration in check_net_config() */
env_id = 0;
}
bootme_packet_handler = handler;
- ret = NetLoop(BOOTME);
+ ret = net_loop(BOOTME);
if (ret < 0)
return BOOTME_ERROR;
if (bootme_timed_out && bootme_state != BOOTME_INIT)
bootme_state = BOOTME_DEBUG_INIT;
bootme_timeout = 3 * 1000;
- NetSetTimeout(bootme_timeout, bootme_timeout_handler);
+ net_set_timeout_handler(bootme_timeout, bootme_timeout_handler);
- ret = NetLoop(BOOTME);
+ ret = net_loop(BOOTME);
if (ret < 0)
return BOOTME_ERROR;
if (bootme_timed_out)
return bootme_state;
}
-int BootMeRequest(IPaddr_t server_ip, const void *buf, size_t len, int timeout)
+int BootMeRequest(struct in_addr server_ip, const void *buf, size_t len, int timeout)
{
bootme_init(server_ip);
bootme_timeout = timeout * 1000;
bootme_timed_out = 0;
- NetSetTimeout(bootme_timeout, bootme_timeout_handler);
+ net_set_timeout_handler(bootme_timeout, bootme_timeout_handler);
return bootme_send_frame(buf, len);
}