3434
3535static bool prov_fast_adv ;
3636
37- static void proxy_complete_pdu (struct bt_mesh_proxy_role * role );
3837static int gatt_send (struct bt_conn * conn ,
3938 const void * data , uint16_t len ,
4039 bt_gatt_complete_func_t end , void * user_data );
4140
42- static struct bt_mesh_proxy_role cli = {
43- .cb = {
44- .send = gatt_send ,
45- .recv = proxy_complete_pdu ,
46- },
47- };
48-
41+ static struct bt_mesh_proxy_role * cli ;
4942static bool service_registered ;
5043
51- static void proxy_complete_pdu (struct bt_mesh_proxy_role * role )
44+ static void proxy_msg_recv (struct bt_mesh_proxy_role * role )
5245{
5346 switch (role -> msg_type ) {
5447 case BT_MESH_PROXY_PROV :
@@ -68,7 +61,7 @@ static ssize_t gatt_recv(struct bt_conn *conn,
6861{
6962 const uint8_t * data = buf ;
7063
71- if (cli . conn != conn ) {
64+ if (cli -> conn != conn ) {
7265 BT_ERR ("No PB-GATT Client found" );
7366 return - ENOTCONN ;
7467 }
@@ -83,7 +76,7 @@ static ssize_t gatt_recv(struct bt_conn *conn,
8376 return - EINVAL ;
8477 }
8578
86- return bt_mesh_proxy_msg_recv (& cli , buf , len );
79+ return bt_mesh_proxy_msg_recv (cli , buf , len );
8780}
8881
8982static void gatt_connected (struct bt_conn * conn , uint8_t err )
@@ -96,11 +89,9 @@ static void gatt_connected(struct bt_conn *conn, uint8_t err)
9689 return ;
9790 }
9891
99- cli . conn = bt_conn_ref (conn );
92+ cli = bt_mesh_proxy_role_setup (conn , gatt_send , proxy_msg_recv );
10093
10194 BT_DBG ("conn %p err 0x%02x" , (void * )conn , err );
102-
103- bt_mesh_proxy_msg_init (& cli );
10495}
10596
10697static void gatt_disconnected (struct bt_conn * conn , uint8_t reason )
@@ -113,27 +104,19 @@ static void gatt_disconnected(struct bt_conn *conn, uint8_t reason)
113104 return ;
114105 }
115106
116- if (cli .conn != conn ) {
117- BT_WARN ("No PB-GATT Client found" );
118- return ;
119- }
120-
121- BT_DBG ("conn %p reason 0x%02x" , (void * )conn , reason );
107+ cli = NULL ;
122108
123109 bt_mesh_pb_gatt_close (conn );
124110
125- if (bt_mesh_is_provisioned ()) {
126- (void )bt_mesh_pb_gatt_disable ();
127-
128- if (IS_ENABLED (CONFIG_BT_MESH_GATT_PROXY )) {
129- (void )bt_mesh_proxy_gatt_enable ();
130- }
111+ if (!bt_mesh_is_provisioned ()) {
112+ return ;
131113 }
132114
133- bt_conn_unref (cli .conn );
134- cli .conn = NULL ;
115+ (void )bt_mesh_pb_gatt_disable ();
135116
136- bt_mesh_adv_update ();
117+ if (IS_ENABLED (CONFIG_BT_MESH_GATT_PROXY )) {
118+ (void )bt_mesh_proxy_gatt_enable ();
119+ }
137120}
138121
139122static void prov_ccc_changed (const struct bt_gatt_attr * attr , uint16_t value )
@@ -144,7 +127,7 @@ static void prov_ccc_changed(const struct bt_gatt_attr *attr, uint16_t value)
144127static ssize_t prov_ccc_write (struct bt_conn * conn ,
145128 const struct bt_gatt_attr * attr , uint16_t value )
146129{
147- if (cli . conn != conn ) {
130+ if (cli -> conn != conn ) {
148131 BT_ERR ("No PB-GATT Client found" );
149132 return - ENOTCONN ;
150133 }
@@ -231,12 +214,12 @@ static const struct bt_data prov_ad[] = {
231214int bt_mesh_pb_gatt_send (struct bt_conn * conn , struct net_buf_simple * buf ,
232215 bt_gatt_complete_func_t end , void * user_data )
233216{
234- if (cli . conn != conn ) {
217+ if (! cli || cli -> conn != conn ) {
235218 BT_ERR ("No PB-GATT Client found" );
236219 return - ENOTCONN ;
237220 }
238221
239- return bt_mesh_proxy_msg_send (& cli , BT_MESH_PROXY_PROV , buf , end , user_data );
222+ return bt_mesh_proxy_msg_send (cli , BT_MESH_PROXY_PROV , buf , end , user_data );
240223}
241224
242225static size_t gatt_prov_adv_create (struct bt_data prov_sd [1 ])
0 commit comments