1 /*
2  * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3  */
4 
5 #ifndef __MAP_API_H__
6 #define __MAP_API_H__
7 
8 #include "bluetooth.h"
9 #include "obex_api.h"
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 #define BTIF_MAP_SESSION_FOLDER_LEVEL_MAX (32)
16 
17 typedef void * btif_map_session_handle_t;
18 
19 typedef char * telephone_number_t;
20 typedef char * short_message_t;
21 
22 typedef enum {
23     BTIF_MAP_SESSION_EVENT_OPEN_IND = 0,
24     BTIF_MAP_SESSION_EVENT_OPEN, // 1
25     BTIF_MAP_SESSION_EVENT_CLOSE, // 2
26 } btif_map_session_event_t;
27 
28 typedef enum {
29     BTIF_MAP_SESSION_ERR_NO_ERROR = 0,
30     BTIF_MAP_SESSION_ERR_SDP_REQUEST_FAIL, // 1
31     BTIF_MAP_SESSION_ERR_CHANNEL_CLOSE, // 2
32 } btif_map_session_error_t;
33 
34 typedef struct {
35     union {
36         struct {
37             btif_map_session_error_t error;
38             uint8_t error_detail;
39         } close;
40         struct {
41             uint8_t *packet;
42             uint32_t packet_len;
43         } data;
44         struct {
45             bt_bdaddr_t *remote;
46         } open;
47     } p;
48 } btif_map_session_cb_param_t;
49 
50 typedef int (*btif_map_session_event_handler_t)(btif_map_session_handle_t handle,
51     btif_map_session_event_t event, btif_map_session_cb_param_t *param);
52 
53 typedef void (*btif_map_callback_t) (void * param, void * map_session);
54 
55 typedef enum {
56     BTIF_MAP_SESSION_TYPE_MAS = 0,
57     BTIF_MAP_SESSION_TYPE_MNS, // 1
58 } btif_map_session_type_t;
59 
60 typedef struct {
61     btif_map_session_type_t type;
62     btif_obex_session_role_t obex_role;
63 } btif_map_session_config_t;
64 
65 #define BTIF_MAP_REQUEST_NUM_IN_QUEUE_MAX (10)
66 #define BTIF_MAP_SMS_TELEPHONE_NUMBER_SIZE_MAX (18)
67 #define BTIF_MAP_SMS_MSG_SIZE_MAX (256)
68 
69 typedef struct {
70     list_entry_t node;
71     char number[BTIF_MAP_SMS_TELEPHONE_NUMBER_SIZE_MAX];
72     char msg[BTIF_MAP_SMS_MSG_SIZE_MAX];
73 } btif_map_sms_t;
74 
75 typedef struct {
76     union {
77         struct {
78             const char *folder[BTIF_MAP_SESSION_FOLDER_LEVEL_MAX];
79             uint8_t folder_level;
80             uint8_t up_level;
81         } SetFolder;
82     } p;
83 } btif_map_session_function_param_t;
84 
85 bt_status_t btif_map_initialize(void);
86 btif_map_session_handle_t btif_map_create_session(void);
87 btif_map_session_handle_t btif_map_get_session(bt_bdaddr_t *remote);
88 bt_status_t btif_map_session_open(btif_map_session_handle_t handle, bt_bdaddr_t *remote, btif_map_session_config_t *config,
89     btif_map_session_event_handler_t handler);
90 bt_status_t btif_map_set_folder(btif_map_session_handle_t handle, btif_map_session_function_param_t *param);
91 bt_status_t btif_map_send_sms(btif_map_session_handle_t handle, telephone_number_t receipt, short_message_t msg);
92 bt_status_t btif_map_session_close(btif_map_session_handle_t handle);
93 bool btif_map_check_is_connected(btif_map_session_handle_t handle);
94 void btif_map_callback_register(btif_map_callback_t callback);
95 #if defined(IBRT)
96 #ifdef __BTMAP_ENABLE__
97 uint32_t btif_map_get_server_chnl(void);
98 uint32_t map_save_ctx(uint32_t server_chnl, uint32_t conn_id,uint8_t *buf, uint32_t buf_len);
99 uint32_t map_restore_ctx(bt_bdaddr_t *remote,uint32_t connection_id,uint32_t server_chnl);
100 uint32_t btif_map_get_rfcomm_handle(void);
101 uint32_t btif_map_profile_save_ctx(uint8_t *buf, uint32_t buf_len);
102 uint32_t btif_map_profile_restore_ctx(uint8_t *buf, uint32_t buf_len);
103 #endif
104 #endif
105 
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #endif /* __MAP_API_H__ */