espnow.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * ESPRESSIF MIT License
  3. *
  4. * Copyright (c) 2016 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
  5. *
  6. * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case,
  7. * it is free of charge, to any person obtaining a copy of this software and associated
  8. * documentation files (the "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
  11. * to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all copies or
  14. * substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. */
  24. #ifndef __ESPNOW_H__
  25. #define __ESPNOW_H__
  26. enum esp_now_role {
  27. ESP_NOW_ROLE_IDLE = 0,
  28. ESP_NOW_ROLE_CONTROLLER,
  29. ESP_NOW_ROLE_SLAVE,
  30. ESP_NOW_ROLE_COMBO,
  31. ESP_NOW_ROLE_MAX,
  32. };
  33. typedef void (*esp_now_recv_cb_t)(u8 *mac_addr, u8 *data, u8 len);
  34. typedef void (*esp_now_send_cb_t)(u8 *mac_addr, u8 status);
  35. int esp_now_init(void);
  36. int esp_now_deinit(void);
  37. int esp_now_register_send_cb(esp_now_send_cb_t cb);
  38. int esp_now_unregister_send_cb(void);
  39. int esp_now_register_recv_cb(esp_now_recv_cb_t cb);
  40. int esp_now_unregister_recv_cb(void);
  41. int esp_now_send(u8 *da, u8 *data, int len);
  42. int esp_now_add_peer(u8 *mac_addr, u8 role, u8 channel, u8 *key, u8 key_len);
  43. int esp_now_del_peer(u8 *mac_addr);
  44. int esp_now_set_self_role(u8 role);
  45. int esp_now_get_self_role(void);
  46. int esp_now_set_peer_role(u8 *mac_addr, u8 role);
  47. int esp_now_get_peer_role(u8 *mac_addr);
  48. int esp_now_set_peer_channel(u8 *mac_addr, u8 channel);
  49. int esp_now_get_peer_channel(u8 *mac_addr);
  50. int esp_now_set_peer_key(u8 *mac_addr, u8 *key, u8 key_len);
  51. int esp_now_get_peer_key(u8 *mac_addr, u8 *key, u8 *key_len);
  52. u8 *esp_now_fetch_peer(bool restart);
  53. int esp_now_is_peer_exist(u8 *mac_addr);
  54. int esp_now_get_cnt_info(u8 *all_cnt, u8 *encrypt_cnt);
  55. int esp_now_set_kok(u8 *key, u8 len);
  56. #endif