123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
-
- #include <stdio.h>
- #include <stdint.h>
- #include <stdlib.h>
- #include <string.h>
- #include <errno.h>
- #include <byteswap.h>
- #include <gpxe/features.h>
- #include <gpxe/netdevice.h>
- #include <gpxe/if_ether.h>
- #include <gpxe/iobuf.h>
- #include <usr/ifmgmt.h>
- #include <usr/wol.h>
- #include <timer.h>
-
-
-
-
- #define WOL_MSG_LEN (6 + 16*6)
-
- void wakeup_server(char *server_adr)
- {
- int rc, i,j;
- unsigned char *buf;
- uint8_t eth_broadcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
- unsigned int len;
- struct io_buffer *iobuf;
- struct ethhdr *ethhdr;
- struct net_device *netdev;
-
- for_each_netdev ( netdev ) {
- break;
- }
-
- if (netdev == NULL)
- {
- printf("Could not find netdev\n");
- return;
- }
-
-
- if ( (ifopen ( netdev ) ) != 0 )
- {
- printf("Could not open netdev\n");
- return;
- }
-
-
- iobuf = alloc_iob ((ETH_HLEN + WOL_MSG_LEN)*2);
- if (!iobuf)
- {
- printf("Could not allocate iob\n");
- return;
- }
-
- ethhdr = iob_put(iobuf, sizeof(*ethhdr));
-
-
- memcpy (ethhdr->h_dest, eth_broadcast, ETH_ALEN );
- memcpy (ethhdr->h_source, netdev->ll_addr, ETH_ALEN );
- ethhdr->h_protocol = htons (0x0842);
-
- buf = iob_put (iobuf, WOL_MSG_LEN);
-
-
- len =0;
- for (i = 0; i < 6; i++)
- buf[len++] = 0xff;
- for (j = 0; j < 16; j++)
- for (i = 0; i < 6; i++)
- buf[len++] = server_adr[i];
-
- rc = netdev_tx (netdev, iobuf);
-
- if (rc !=0)
- printf("Failed to transmit WOL packet\n");
-
-
- mdelay(100);
-
- netdev_poll(netdev);
- }
|