@@ -2285,78 +2285,106 @@ int bt_obex_add_header_conn_id(struct net_buf *buf, uint32_t conn_id)
2285
2285
return 0 ;
2286
2286
}
2287
2287
2288
- int bt_obex_add_header_app_param (struct net_buf * buf , uint16_t len , const uint8_t * app_param )
2288
+ int bt_obex_add_header_app_param (struct net_buf * buf , size_t count , const struct bt_obex_tlv data [] )
2289
2289
{
2290
2290
size_t total ;
2291
+ uint16_t len = 0 ;
2291
2292
2292
- if (!buf || !app_param || !len ) {
2293
+ if (!buf || !data || !count ) {
2293
2294
LOG_WRN ("Invalid parameter" );
2294
2295
return - EINVAL ;
2295
2296
}
2296
2297
2298
+ for (size_t i = 0 ; i < count ; i ++ ) {
2299
+ if (data [i ].data_len && !data [i ].data ) {
2300
+ LOG_WRN ("Invalid parameter" );
2301
+ return - EINVAL ;
2302
+ }
2303
+ len += data [i ].data_len + sizeof (data [i ].type ) + sizeof (data [i ].data_len );
2304
+ }
2305
+
2297
2306
total = sizeof (uint8_t ) + sizeof (len ) + len ;
2298
2307
if (net_buf_tailroom (buf ) < total ) {
2299
2308
return - ENOMEM ;
2300
2309
}
2301
2310
2302
- if (!bt_obex_string_is_valid (BT_OBEX_HEADER_ID_APP_PARAM , len , app_param )) {
2303
- LOG_WRN ("Invalid string" );
2304
- return - EINVAL ;
2305
- }
2306
-
2307
2311
net_buf_add_u8 (buf , BT_OBEX_HEADER_ID_APP_PARAM );
2308
2312
net_buf_add_be16 (buf , (uint16_t )total );
2309
- net_buf_add_mem (buf , app_param , len );
2313
+ for (size_t i = 0 ; i < count ; i ++ ) {
2314
+ len += data [i ].data_len + sizeof (data [i ].type ) + sizeof (data [i ].data_len );
2315
+ net_buf_add_u8 (buf , data [i ].type );
2316
+ net_buf_add_u8 (buf , data [i ].data_len );
2317
+ net_buf_add_mem (buf , data [i ].data , (size_t )data [i ].data_len );
2318
+ }
2310
2319
return 0 ;
2311
2320
}
2312
2321
2313
- int bt_obex_add_header_auth_challenge (struct net_buf * buf , uint16_t len , const uint8_t * auth )
2322
+ int bt_obex_add_header_auth_challenge (struct net_buf * buf , size_t count ,
2323
+ const struct bt_obex_tlv data [])
2314
2324
{
2315
2325
size_t total ;
2326
+ uint16_t len = 0 ;
2316
2327
2317
- if (!buf || !auth || !len ) {
2328
+ if (!buf || !data || !count ) {
2318
2329
LOG_WRN ("Invalid parameter" );
2319
2330
return - EINVAL ;
2320
2331
}
2321
2332
2333
+ for (size_t i = 0 ; i < count ; i ++ ) {
2334
+ if (data [i ].data_len && !data [i ].data ) {
2335
+ LOG_WRN ("Invalid parameter" );
2336
+ return - EINVAL ;
2337
+ }
2338
+ len += data [i ].data_len + sizeof (data [i ].type ) + sizeof (data [i ].data_len );
2339
+ }
2340
+
2322
2341
total = sizeof (uint8_t ) + sizeof (len ) + len ;
2323
2342
if (net_buf_tailroom (buf ) < total ) {
2324
2343
return - ENOMEM ;
2325
2344
}
2326
2345
2327
- if (!bt_obex_string_is_valid (BT_OBEX_HEADER_ID_AUTH_CHALLENGE , len , auth )) {
2328
- LOG_WRN ("Invalid string" );
2329
- return - EINVAL ;
2330
- }
2331
-
2332
2346
net_buf_add_u8 (buf , BT_OBEX_HEADER_ID_AUTH_CHALLENGE );
2333
2347
net_buf_add_be16 (buf , (uint16_t )total );
2334
- net_buf_add_mem (buf , auth , len );
2348
+ for (size_t i = 0 ; i < count ; i ++ ) {
2349
+ len += data [i ].data_len + sizeof (data [i ].type ) + sizeof (data [i ].data_len );
2350
+ net_buf_add_u8 (buf , data [i ].type );
2351
+ net_buf_add_u8 (buf , data [i ].data_len );
2352
+ net_buf_add_mem (buf , data [i ].data , (size_t )data [i ].data_len );
2353
+ }
2335
2354
return 0 ;
2336
2355
}
2337
2356
2338
- int bt_obex_add_header_auth_rsp (struct net_buf * buf , uint16_t len , const uint8_t * auth )
2357
+ int bt_obex_add_header_auth_rsp (struct net_buf * buf , size_t count , const struct bt_obex_tlv data [] )
2339
2358
{
2340
2359
size_t total ;
2360
+ uint16_t len = 0 ;
2341
2361
2342
- if (!buf || !auth || !len ) {
2362
+ if (!buf || !data || !count ) {
2343
2363
LOG_WRN ("Invalid parameter" );
2344
2364
return - EINVAL ;
2345
2365
}
2346
2366
2367
+ for (size_t i = 0 ; i < count ; i ++ ) {
2368
+ if (data [i ].data_len && !data [i ].data ) {
2369
+ LOG_WRN ("Invalid parameter" );
2370
+ return - EINVAL ;
2371
+ }
2372
+ len += data [i ].data_len + sizeof (data [i ].type ) + sizeof (data [i ].data_len );
2373
+ }
2374
+
2347
2375
total = sizeof (uint8_t ) + sizeof (len ) + len ;
2348
2376
if (net_buf_tailroom (buf ) < total ) {
2349
2377
return - ENOMEM ;
2350
2378
}
2351
2379
2352
- if (!bt_obex_string_is_valid (BT_OBEX_HEADER_ID_AUTH_RSP , len , auth )) {
2353
- LOG_WRN ("Invalid string" );
2354
- return - EINVAL ;
2355
- }
2356
-
2357
2380
net_buf_add_u8 (buf , BT_OBEX_HEADER_ID_AUTH_RSP );
2358
2381
net_buf_add_be16 (buf , (uint16_t )total );
2359
- net_buf_add_mem (buf , auth , len );
2382
+ for (size_t i = 0 ; i < count ; i ++ ) {
2383
+ len += data [i ].data_len + sizeof (data [i ].type ) + sizeof (data [i ].data_len );
2384
+ net_buf_add_u8 (buf , data [i ].type );
2385
+ net_buf_add_u8 (buf , data [i ].data_len );
2386
+ net_buf_add_mem (buf , data [i ].data , (size_t )data [i ].data_len );
2387
+ }
2360
2388
return 0 ;
2361
2389
}
2362
2390
@@ -3010,6 +3038,34 @@ int bt_obex_get_header_conn_id(struct net_buf *buf, uint32_t *conn_id)
3010
3038
return 0 ;
3011
3039
}
3012
3040
3041
+ int bt_obex_tlv_parse (uint16_t len , const uint8_t * data ,
3042
+ bool (* func )(struct bt_obex_tlv * tlv , void * user_data ), void * user_data )
3043
+ {
3044
+ uint16_t index = 0 ;
3045
+ struct bt_obex_tlv tlv ;
3046
+
3047
+ if (!len || !data || !func ) {
3048
+ LOG_WRN ("Invalid parameter" );
3049
+ return - EINVAL ;
3050
+ }
3051
+
3052
+ while ((index + 2 ) <= len ) {
3053
+ tlv .type = data [index ];
3054
+ tlv .data_len = data [index + 1 ];
3055
+ index += 2 ;
3056
+ if ((index + tlv .data_len ) > len ) {
3057
+ break ;
3058
+ }
3059
+
3060
+ tlv .data = & data [index ];
3061
+ index += tlv .data_len ;
3062
+ if (!func (& tlv , user_data )) {
3063
+ return 0 ;
3064
+ }
3065
+ }
3066
+ return 0 ;
3067
+ }
3068
+
3013
3069
int bt_obex_get_header_app_param (struct net_buf * buf , uint16_t * len , const uint8_t * * app_param )
3014
3070
{
3015
3071
struct bt_obex_find_header_data data ;
0 commit comments