1 /*
2    This example code is in the Public Domain (or CC0 licensed, at your option.)
3 
4    Unless required by applicable law or agreed to in writing, this
5    software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
6    CONDITIONS OF ANY KIND, either express or implied.
7 */
8 
9 #include <stdio.h>
10 # include <stdlib.h>
11 #include <string.h>
12 #include "esp_spp_api.h"
13 #include "esp_gap_bt_api.h"
14 #include "app_spp_msg_set.h"
15 
16 extern esp_bd_addr_t peer_bd_addr;
17 
spp_msg_show_usage(void)18 void spp_msg_show_usage(void)
19 {
20     printf("########################################################################\n");
21     printf("Supported commands are as follows, arguments are embraced with < and >\n");
22     printf("spp h;                -- show command manual\n\n");
23     printf("Use this cmmand table if the IO Capability of local device set as IO_CAP_IO.\n");
24     printf("spp ok;               -- manual Numeric Confirmation.\n\n");
25     printf("Use this cmmand table if the IO Capability of local device set as IO_CAP_IN.\n");
26     printf("spp key <auth key>;   -- manual Passkey. (e.g. spp key 136245;)\n\n");
27     printf("########################################################################\n");
28 }
29 
30 #define SPP_CMD_HANDLER(cmd)    static void spp_##cmd##_handler(int argn, char **argv)
31 
32 
SPP_CMD_HANDLER(help)33 SPP_CMD_HANDLER(help)
34 {
35     spp_msg_show_usage();
36 }
37 
SPP_CMD_HANDLER(ok)38 SPP_CMD_HANDLER(ok)
39 {
40     esp_bt_gap_ssp_confirm_reply(peer_bd_addr, true);
41 }
42 
SPP_CMD_HANDLER(key)43 SPP_CMD_HANDLER(key)
44 {
45     if (argn != 2) {
46         printf("Insufficient number of arguments");
47     } else {
48         printf("Input Paring Key: %s\n", argv[1]);
49         int passkey = atoi(argv[1]);
50         esp_bt_gap_ssp_passkey_reply(peer_bd_addr, true, passkey);
51     }
52 }
53 
54 static spp_msg_hdl_t spp_cmd_tbl[] = {
55     {0,    "h",   spp_help_handler},
56     {5,    "ok",  spp_ok_handler},
57     {10,   "key", spp_key_handler},
58 };
59 
spp_get_cmd_tbl(void)60 spp_msg_hdl_t *spp_get_cmd_tbl(void)
61 {
62     return spp_cmd_tbl;
63 }
64 
spp_get_cmd_tbl_size(void)65 size_t spp_get_cmd_tbl_size(void)
66 {
67     return sizeof(spp_cmd_tbl) / sizeof(spp_msg_hdl_t);
68 }
69