You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

wol.c 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright (C) 2008 William Stewart.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #include <stdio.h>
  19. #include <stdint.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <errno.h>
  23. #include <byteswap.h>
  24. #include <gpxe/features.h>
  25. #include <gpxe/netdevice.h>
  26. #include <gpxe/if_ether.h>
  27. #include <gpxe/iobuf.h>
  28. #include <usr/ifmgmt.h>
  29. #include <usr/wol.h>
  30. #include <timer.h>
  31. /** @file
  32. *
  33. * Wake on lan
  34. *
  35. */
  36. /**
  37. * Boot from a network device
  38. *
  39. * @v netdev Network device
  40. * @ret rc Return status code
  41. */
  42. #define WOL_MSG_LEN (6 + 16*6)
  43. void wakeup_server(char *server_adr)
  44. {
  45. int rc, i,j;
  46. unsigned char *buf;
  47. uint8_t eth_broadcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  48. unsigned int len;
  49. struct io_buffer *iobuf;
  50. struct ethhdr *ethhdr;
  51. struct net_device *netdev;
  52. for_each_netdev ( netdev ) {
  53. break;
  54. }
  55. if (netdev == NULL)
  56. {
  57. printf("Could not find netdev\n");
  58. return;
  59. }
  60. /* Open device and display device status */
  61. if ( (ifopen ( netdev ) ) != 0 )
  62. {
  63. printf("Could not open netdev\n");
  64. return;
  65. }
  66. /* Create outgoing I/O buffer */
  67. iobuf = alloc_iob ((ETH_HLEN + WOL_MSG_LEN)*2);
  68. if (!iobuf)
  69. {
  70. printf("Could not allocate iob\n");
  71. return;
  72. }
  73. ethhdr = iob_put(iobuf, sizeof(*ethhdr));
  74. /* Build Ethernet header */
  75. memcpy (ethhdr->h_dest, eth_broadcast, ETH_ALEN );
  76. memcpy (ethhdr->h_source, netdev->ll_addr, ETH_ALEN );
  77. ethhdr->h_protocol = htons (0x0842);
  78. buf = iob_put (iobuf, WOL_MSG_LEN);
  79. /* Build the message to send - 6 x 0xff then 16 x dest address */
  80. len =0;
  81. for (i = 0; i < 6; i++)
  82. buf[len++] = 0xff;
  83. for (j = 0; j < 16; j++)
  84. for (i = 0; i < 6; i++)
  85. buf[len++] = server_adr[i];
  86. rc = netdev_tx (netdev, iobuf);
  87. if (rc !=0)
  88. printf("Failed to transmit WOL packet\n");
  89. /* Give the controller a chance to send it before checking */
  90. mdelay(100);
  91. netdev_poll(netdev);
  92. }