ETHInterface.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #ifndef ETHInterface_H
  16. #define ETHInterface_H
  17. #include "util/events/EventBase.h"
  18. #include "interface/Interface.h"
  19. #include "interface/InterfaceController.h"
  20. #include "util/log/Log.h"
  21. #include "memory/Allocator.h"
  22. #include "util/Linker.h"
  23. Linker_require("interface/ETHInterface_" + builder.config.systemName + ".c")
  24. struct ETHInterface;
  25. /**
  26. * @param base the LibEvent context.
  27. * @param bindDevice the name of the device to bind to.
  28. * @param allocator the memory allocator for this message.
  29. * @param exHandler the handler to deal with whatever exception arises.
  30. * @param logger
  31. * @param ic the controller which this interface should register with
  32. * and use when starting connections.
  33. * @return a new ETHInterface.
  34. */
  35. struct ETHInterface* ETHInterface_new(struct EventBase* base,
  36. const char* bindDevice,
  37. struct Allocator* allocator,
  38. struct Except* exHandler,
  39. struct Log* logger,
  40. struct InterfaceController* ic);
  41. /**
  42. * Begin an outgoing connection.
  43. *
  44. * @param macAddress the MAC address of the ethernet card to connect to.
  45. * @param cryptoKey the node's public key, this is required to send it traffic.
  46. * @param password if specified, the password for authenticating with the other node.
  47. * @param ethIf the Ether interface.
  48. * @return 0 on success
  49. * ETHInterface_beginConnection_OUT_OF_SPACE if there is no space to store the entry.
  50. * ETHInterface_beginConnection_BAD_KEY invalid (non-cjdns) cryptoKey
  51. * ETHInterface_beginConnection_BAD_IFACE failed to parse interface name.
  52. * ETHInterface_beginConnection_UNKNOWN_ERROR something failed in InterfaceController.
  53. * ETHInterface_beginConnection_BAD_MAC malformed MAC address.
  54. */
  55. #define ETHInterface_beginConnection_OUT_OF_SPACE -1
  56. #define ETHInterface_beginConnection_BAD_KEY -2
  57. #define ETHInterface_beginConnection_BAD_IFACE -3
  58. #define ETHInterface_beginConnection_UNKNOWN_ERROR -4
  59. #define ETHInterface_beginConnection_BAD_MAC -5
  60. int ETHInterface_beginConnection(const char* macAddress,
  61. uint8_t cryptoKey[32],
  62. String* password,
  63. struct ETHInterface* ethIf);
  64. /**
  65. * Get or set the beaconing state of the ethernet interface.
  66. *
  67. * @param ethIf the ethernet iface.
  68. * @param state if not NULL, the state will be set to this, if NULL then nothing will be changed.
  69. * @return the current state after (possibly) setting.
  70. */
  71. #define ETHInterface_beacon_DISABLED 0
  72. #define ETHInterface_beacon_ACCEPTING 1
  73. #define ETHInterface_beacon_ACCEPTING_AND_SENDING 2
  74. int ETHInterface_beacon(struct ETHInterface* ethIf, int* state);
  75. #endif