24
24
25
25
#include "host/conn_internal.h"
26
26
#include "l2cap_br_internal.h"
27
+ #include "rfcomm_internal.h"
27
28
#include "obex_internal.h"
28
29
29
30
#define LOG_LEVEL CONFIG_BT_GOEP_LOG_LEVEL
@@ -168,6 +169,8 @@ static int goep_rfcomm_accept(struct bt_conn *conn, struct bt_rfcomm_server *ser
168
169
{
169
170
struct bt_goep_transport_rfcomm_server * rfcomm_server ;
170
171
struct bt_goep * goep ;
172
+ uint32_t mtu ;
173
+ uint32_t hdr_size ;
171
174
int err ;
172
175
173
176
rfcomm_server = CONTAINER_OF (server , struct bt_goep_transport_rfcomm_server , rfcomm );
@@ -183,13 +186,32 @@ static int goep_rfcomm_accept(struct bt_conn *conn, struct bt_rfcomm_server *ser
183
186
return err ;
184
187
}
185
188
186
- if (!goep || !goep -> transport_ops || (goep -> obex .rx .mtu < GOEP_MIN_MTU ) ||
187
- !goep -> obex .server_ops || !goep -> obex .server_ops -> connect ||
188
- !goep -> obex .server_ops -> disconnect ) {
189
+ if (!goep || !goep -> transport_ops || !goep -> obex .server_ops ||
190
+ !goep -> obex .server_ops -> connect || !goep -> obex .server_ops -> disconnect ) {
189
191
LOG_DBG ("Invalid parameter" );
190
192
return - EINVAL ;
191
193
}
192
194
195
+ hdr_size = sizeof (struct bt_l2cap_hdr );
196
+ hdr_size += BT_RFCOMM_HDR_SIZE + BT_RFCOMM_FCS_SIZE ;
197
+
198
+ mtu = CONFIG_BT_GOEP_RFCOMM_MTU - hdr_size ;
199
+ /* Use default MTU if it is not given */
200
+ if (!goep -> obex .rx .mtu ) {
201
+ goep -> obex .rx .mtu = mtu ;
202
+ }
203
+
204
+ if (goep -> obex .rx .mtu < GOEP_MIN_MTU ) {
205
+ LOG_WRN ("GOEP RFCOMM MTU less than minimum size (%d < %d)" , goep -> obex .rx .mtu ,
206
+ GOEP_MIN_MTU );
207
+ goep -> obex .rx .mtu = GOEP_MIN_MTU ;
208
+ }
209
+
210
+ if (goep -> obex .rx .mtu > mtu ) {
211
+ LOG_WRN ("GOEP RFCOMM MTU exceeds maximum size (%d > %d)" , goep -> obex .rx .mtu , mtu );
212
+ goep -> obex .rx .mtu = mtu ;
213
+ }
214
+
193
215
err = bt_obex_reg_transport (& goep -> obex , & goep_rfcomm_transport_ops );
194
216
if (err ) {
195
217
LOG_WRN ("Fail to reg transport ops" );
@@ -238,14 +260,35 @@ int bt_goep_transport_rfcomm_server_register(struct bt_goep_transport_rfcomm_ser
238
260
int bt_goep_transport_rfcomm_connect (struct bt_conn * conn , struct bt_goep * goep , uint8_t channel )
239
261
{
240
262
int err ;
263
+ uint32_t mtu ;
264
+ uint32_t hdr_size ;
241
265
242
- if (!conn || !goep || !goep -> transport_ops || (goep -> obex .rx .mtu < GOEP_MIN_MTU ) ||
243
- !goep -> obex .client_ops || !goep -> obex .client_ops -> connect ||
244
- !goep -> obex .client_ops -> disconnect ) {
266
+ if (!conn || !goep || !goep -> transport_ops || !goep -> obex .client_ops ||
267
+ !goep -> obex .client_ops -> connect || !goep -> obex .client_ops -> disconnect ) {
245
268
LOG_DBG ("Invalid parameter" );
246
269
return - EINVAL ;
247
270
}
248
271
272
+ hdr_size = sizeof (struct bt_l2cap_hdr );
273
+ hdr_size += BT_RFCOMM_HDR_SIZE + BT_RFCOMM_FCS_SIZE ;
274
+
275
+ mtu = CONFIG_BT_GOEP_RFCOMM_MTU - hdr_size ;
276
+ /* Use default MTU if it is not given */
277
+ if (!goep -> obex .rx .mtu ) {
278
+ goep -> obex .rx .mtu = mtu ;
279
+ }
280
+
281
+ if (goep -> obex .rx .mtu < GOEP_MIN_MTU ) {
282
+ LOG_WRN ("GOEP RFCOMM MTU less than minimum size (%d < %d)" , goep -> obex .rx .mtu ,
283
+ GOEP_MIN_MTU );
284
+ goep -> obex .rx .mtu = GOEP_MIN_MTU ;
285
+ }
286
+
287
+ if (goep -> obex .rx .mtu > mtu ) {
288
+ LOG_WRN ("GOEP RFCOMM MTU exceeds maximum size (%d > %d)" , goep -> obex .rx .mtu , mtu );
289
+ goep -> obex .rx .mtu = mtu ;
290
+ }
291
+
249
292
err = bt_obex_reg_transport (& goep -> obex , & goep_rfcomm_transport_ops );
250
293
if (err ) {
251
294
LOG_WRN ("Fail to reg transport ops" );
@@ -425,6 +468,8 @@ static int goep_l2cap_accept(struct bt_conn *conn, struct bt_l2cap_server *serve
425
468
{
426
469
struct bt_goep_transport_l2cap_server * l2cap_server ;
427
470
struct bt_goep * goep ;
471
+ uint32_t mtu ;
472
+ uint32_t hdr_size ;
428
473
int err ;
429
474
430
475
l2cap_server = CONTAINER_OF (server , struct bt_goep_transport_l2cap_server , l2cap );
@@ -440,13 +485,31 @@ static int goep_l2cap_accept(struct bt_conn *conn, struct bt_l2cap_server *serve
440
485
return err ;
441
486
}
442
487
443
- if (!goep || !goep -> transport_ops || (goep -> obex .rx .mtu < GOEP_MIN_MTU ) ||
444
- !goep -> obex .server_ops || !goep -> obex .server_ops -> connect ||
445
- !goep -> obex .server_ops -> disconnect ) {
488
+ if (!goep || !goep -> transport_ops || !goep -> obex .server_ops ||
489
+ !goep -> obex .server_ops -> connect || !goep -> obex .server_ops -> disconnect ) {
446
490
LOG_DBG ("Invalid parameter" );
447
491
return - EINVAL ;
448
492
}
449
493
494
+ hdr_size = sizeof (struct bt_l2cap_hdr );
495
+
496
+ mtu = CONFIG_BT_GOEP_L2CAP_MTU - hdr_size ;
497
+ /* Use default MTU if it is not given */
498
+ if (!goep -> obex .rx .mtu ) {
499
+ goep -> obex .rx .mtu = mtu ;
500
+ }
501
+
502
+ if (goep -> obex .rx .mtu < GOEP_MIN_MTU ) {
503
+ LOG_WRN ("GOEP RFCOMM MTU less than minimum size (%d < %d)" , goep -> obex .rx .mtu ,
504
+ GOEP_MIN_MTU );
505
+ goep -> obex .rx .mtu = GOEP_MIN_MTU ;
506
+ }
507
+
508
+ if (goep -> obex .rx .mtu > mtu ) {
509
+ LOG_WRN ("GOEP RFCOMM MTU exceeds maximum size (%d > %d)" , goep -> obex .rx .mtu , mtu );
510
+ goep -> obex .rx .mtu = mtu ;
511
+ }
512
+
450
513
err = bt_obex_reg_transport (& goep -> obex , & goep_l2cap_transport_ops );
451
514
if (err ) {
452
515
LOG_WRN ("Fail to reg transport ops" );
@@ -500,10 +563,11 @@ int bt_goep_transport_l2cap_connect(struct bt_conn *conn, struct bt_goep *goep,
500
563
{
501
564
int err ;
502
565
uint32_t state ;
566
+ uint32_t mtu ;
567
+ uint32_t hdr_size ;
503
568
504
- if (!conn || !goep || !goep -> transport_ops || (goep -> obex .rx .mtu < GOEP_MIN_MTU ) ||
505
- !goep -> obex .client_ops || !goep -> obex .client_ops -> connect ||
506
- !goep -> obex .client_ops -> disconnect ) {
569
+ if (!conn || !goep || !goep -> transport_ops || !goep -> obex .client_ops ||
570
+ !goep -> obex .client_ops -> connect || !goep -> obex .client_ops -> disconnect ) {
507
571
LOG_DBG ("Invalid parameter" );
508
572
return - EINVAL ;
509
573
}
@@ -514,6 +578,25 @@ int bt_goep_transport_l2cap_connect(struct bt_conn *conn, struct bt_goep *goep,
514
578
return - EBUSY ;
515
579
}
516
580
581
+ hdr_size = sizeof (struct bt_l2cap_hdr );
582
+
583
+ mtu = CONFIG_BT_GOEP_L2CAP_MTU - hdr_size ;
584
+ /* Use default MTU if it is not given */
585
+ if (!goep -> obex .rx .mtu ) {
586
+ goep -> obex .rx .mtu = mtu ;
587
+ }
588
+
589
+ if (goep -> obex .rx .mtu < GOEP_MIN_MTU ) {
590
+ LOG_WRN ("GOEP RFCOMM MTU less than minimum size (%d < %d)" , goep -> obex .rx .mtu ,
591
+ GOEP_MIN_MTU );
592
+ goep -> obex .rx .mtu = GOEP_MIN_MTU ;
593
+ }
594
+
595
+ if (goep -> obex .rx .mtu > mtu ) {
596
+ LOG_WRN ("GOEP RFCOMM MTU exceeds maximum size (%d > %d)" , goep -> obex .rx .mtu , mtu );
597
+ goep -> obex .rx .mtu = mtu ;
598
+ }
599
+
517
600
err = bt_obex_reg_transport (& goep -> obex , & goep_l2cap_transport_ops );
518
601
if (err ) {
519
602
LOG_WRN ("Fail to reg transport ops" );
0 commit comments