@@ -2007,7 +2007,14 @@ int bt_obex_add_header_name(struct net_buf *buf, uint16_t len, const uint8_t *na
2007
2007
{
2008
2008
size_t total ;
2009
2009
2010
- if (!buf || !name || !len ) {
2010
+ /*
2011
+ * OBEX Version 1.5, section 2.2.2 Name
2012
+ * The `name` could be a NULL, so the `len` of the name could 0.
2013
+ * In some cases an empty Name header is used to specify a particular behavior;
2014
+ * see the GET and SETPATH Operations. An empty Name header is defined as a Name
2015
+ * header of length 3 (one byte opcode + two byte length).
2016
+ */
2017
+ if (!buf || (len && !name )) {
2011
2018
LOG_WRN ("Invalid parameter" );
2012
2019
return - EINVAL ;
2013
2020
}
@@ -2017,14 +2024,16 @@ int bt_obex_add_header_name(struct net_buf *buf, uint16_t len, const uint8_t *na
2017
2024
return - ENOMEM ;
2018
2025
}
2019
2026
2020
- if (!bt_obex_string_is_valid (BT_OBEX_HEADER_ID_NAME , len , name )) {
2027
+ if (len && !bt_obex_string_is_valid (BT_OBEX_HEADER_ID_NAME , len , name )) {
2021
2028
LOG_WRN ("Invalid string" );
2022
2029
return - EINVAL ;
2023
2030
}
2024
2031
2025
2032
net_buf_add_u8 (buf , BT_OBEX_HEADER_ID_NAME );
2026
2033
net_buf_add_be16 (buf , (uint16_t )total );
2027
- net_buf_add_mem (buf , name , len );
2034
+ if (len ) {
2035
+ net_buf_add_mem (buf , name , len );
2036
+ }
2028
2037
return 0 ;
2029
2038
}
2030
2039
@@ -2662,6 +2671,7 @@ int bt_obex_header_parse(struct net_buf *buf,
2662
2671
2663
2672
struct bt_obex_find_header_data {
2664
2673
struct bt_obex_hdr hdr ;
2674
+ bool found ;
2665
2675
};
2666
2676
2667
2677
static bool bt_obex_find_header_cb (struct bt_obex_hdr * hdr , void * user_data )
@@ -2691,6 +2701,7 @@ int bt_obex_get_header_count(struct net_buf *buf, uint32_t *count)
2691
2701
data .hdr .id = BT_OBEX_HEADER_ID_COUNT ;
2692
2702
data .hdr .len = 0 ;
2693
2703
data .hdr .data = NULL ;
2704
+ data .found = false;
2694
2705
2695
2706
err = bt_obex_header_parse (buf , bt_obex_find_header_cb , & data );
2696
2707
if (err ) {
@@ -2718,13 +2729,14 @@ int bt_obex_get_header_name(struct net_buf *buf, uint16_t *len, const uint8_t **
2718
2729
data .hdr .id = BT_OBEX_HEADER_ID_NAME ;
2719
2730
data .hdr .len = 0 ;
2720
2731
data .hdr .data = NULL ;
2732
+ data .found = false;
2721
2733
2722
2734
err = bt_obex_header_parse (buf , bt_obex_find_header_cb , & data );
2723
2735
if (err ) {
2724
2736
return err ;
2725
2737
}
2726
2738
2727
- if (( data . hdr . len == 0 ) || !data .hdr . data ) {
2739
+ if (!data .found ) {
2728
2740
return - ENODATA ;
2729
2741
}
2730
2742
@@ -2746,6 +2758,7 @@ int bt_obex_get_header_type(struct net_buf *buf, uint16_t *len, const uint8_t **
2746
2758
data .hdr .id = BT_OBEX_HEADER_ID_TYPE ;
2747
2759
data .hdr .len = 0 ;
2748
2760
data .hdr .data = NULL ;
2761
+ data .found = false;
2749
2762
2750
2763
err = bt_obex_header_parse (buf , bt_obex_find_header_cb , & data );
2751
2764
if (err ) {
@@ -2774,6 +2787,7 @@ int bt_obex_get_header_len(struct net_buf *buf, uint32_t *len)
2774
2787
data .hdr .id = BT_OBEX_HEADER_ID_LEN ;
2775
2788
data .hdr .len = 0 ;
2776
2789
data .hdr .data = NULL ;
2790
+ data .found = false;
2777
2791
2778
2792
err = bt_obex_header_parse (buf , bt_obex_find_header_cb , & data );
2779
2793
if (err ) {
@@ -2801,6 +2815,7 @@ int bt_obex_get_header_time_iso_8601(struct net_buf *buf, uint16_t *len, const u
2801
2815
data .hdr .id = BT_OBEX_HEADER_ID_TIME_ISO_8601 ;
2802
2816
data .hdr .len = 0 ;
2803
2817
data .hdr .data = NULL ;
2818
+ data .found = false;
2804
2819
2805
2820
err = bt_obex_header_parse (buf , bt_obex_find_header_cb , & data );
2806
2821
if (err ) {
@@ -2829,6 +2844,7 @@ int bt_obex_get_header_time(struct net_buf *buf, uint32_t *t)
2829
2844
data .hdr .id = BT_OBEX_HEADER_ID_TIME ;
2830
2845
data .hdr .len = 0 ;
2831
2846
data .hdr .data = NULL ;
2847
+ data .found = false;
2832
2848
2833
2849
err = bt_obex_header_parse (buf , bt_obex_find_header_cb , & data );
2834
2850
if (err ) {
@@ -2856,6 +2872,7 @@ int bt_obex_get_header_description(struct net_buf *buf, uint16_t *len, const uin
2856
2872
data .hdr .id = BT_OBEX_HEADER_ID_DES ;
2857
2873
data .hdr .len = 0 ;
2858
2874
data .hdr .data = NULL ;
2875
+ data .found = false;
2859
2876
2860
2877
err = bt_obex_header_parse (buf , bt_obex_find_header_cb , & data );
2861
2878
if (err ) {
@@ -2884,6 +2901,7 @@ int bt_obex_get_header_target(struct net_buf *buf, uint16_t *len, const uint8_t
2884
2901
data .hdr .id = BT_OBEX_HEADER_ID_TARGET ;
2885
2902
data .hdr .len = 0 ;
2886
2903
data .hdr .data = NULL ;
2904
+ data .found = false;
2887
2905
2888
2906
err = bt_obex_header_parse (buf , bt_obex_find_header_cb , & data );
2889
2907
if (err ) {
@@ -2912,6 +2930,7 @@ int bt_obex_get_header_http(struct net_buf *buf, uint16_t *len, const uint8_t **
2912
2930
data .hdr .id = BT_OBEX_HEADER_ID_HTTP ;
2913
2931
data .hdr .len = 0 ;
2914
2932
data .hdr .data = NULL ;
2933
+ data .found = false;
2915
2934
2916
2935
err = bt_obex_header_parse (buf , bt_obex_find_header_cb , & data );
2917
2936
if (err ) {
@@ -2940,6 +2959,7 @@ int bt_obex_get_header_body(struct net_buf *buf, uint16_t *len, const uint8_t **
2940
2959
data .hdr .id = BT_OBEX_HEADER_ID_BODY ;
2941
2960
data .hdr .len = 0 ;
2942
2961
data .hdr .data = NULL ;
2962
+ data .found = false;
2943
2963
2944
2964
err = bt_obex_header_parse (buf , bt_obex_find_header_cb , & data );
2945
2965
if (err ) {
@@ -2968,6 +2988,7 @@ int bt_obex_get_header_end_body(struct net_buf *buf, uint16_t *len, const uint8_
2968
2988
data .hdr .id = BT_OBEX_HEADER_ID_END_BODY ;
2969
2989
data .hdr .len = 0 ;
2970
2990
data .hdr .data = NULL ;
2991
+ data .found = false;
2971
2992
2972
2993
err = bt_obex_header_parse (buf , bt_obex_find_header_cb , & data );
2973
2994
if (err ) {
@@ -2996,6 +3017,7 @@ int bt_obex_get_header_who(struct net_buf *buf, uint16_t *len, const uint8_t **w
2996
3017
data .hdr .id = BT_OBEX_HEADER_ID_WHO ;
2997
3018
data .hdr .len = 0 ;
2998
3019
data .hdr .data = NULL ;
3020
+ data .found = false;
2999
3021
3000
3022
err = bt_obex_header_parse (buf , bt_obex_find_header_cb , & data );
3001
3023
if (err ) {
@@ -3024,6 +3046,7 @@ int bt_obex_get_header_conn_id(struct net_buf *buf, uint32_t *conn_id)
3024
3046
data .hdr .id = BT_OBEX_HEADER_ID_CONN_ID ;
3025
3047
data .hdr .len = 0 ;
3026
3048
data .hdr .data = NULL ;
3049
+ data .found = false;
3027
3050
3028
3051
err = bt_obex_header_parse (buf , bt_obex_find_header_cb , & data );
3029
3052
if (err ) {
@@ -3079,6 +3102,7 @@ int bt_obex_get_header_app_param(struct net_buf *buf, uint16_t *len, const uint8
3079
3102
data .hdr .id = BT_OBEX_HEADER_ID_APP_PARAM ;
3080
3103
data .hdr .len = 0 ;
3081
3104
data .hdr .data = NULL ;
3105
+ data .found = false;
3082
3106
3083
3107
err = bt_obex_header_parse (buf , bt_obex_find_header_cb , & data );
3084
3108
if (err ) {
@@ -3107,6 +3131,7 @@ int bt_obex_get_header_auth_challenge(struct net_buf *buf, uint16_t *len, const
3107
3131
data .hdr .id = BT_OBEX_HEADER_ID_AUTH_CHALLENGE ;
3108
3132
data .hdr .len = 0 ;
3109
3133
data .hdr .data = NULL ;
3134
+ data .found = false;
3110
3135
3111
3136
err = bt_obex_header_parse (buf , bt_obex_find_header_cb , & data );
3112
3137
if (err ) {
@@ -3135,6 +3160,7 @@ int bt_obex_get_header_auth_rsp(struct net_buf *buf, uint16_t *len, const uint8_
3135
3160
data .hdr .id = BT_OBEX_HEADER_ID_AUTH_RSP ;
3136
3161
data .hdr .len = 0 ;
3137
3162
data .hdr .data = NULL ;
3163
+ data .found = false;
3138
3164
3139
3165
err = bt_obex_header_parse (buf , bt_obex_find_header_cb , & data );
3140
3166
if (err ) {
@@ -3163,6 +3189,7 @@ int bt_obex_get_header_creator_id(struct net_buf *buf, uint32_t *creator_id)
3163
3189
data .hdr .id = BT_OBEX_HEADER_ID_CREATE_ID ;
3164
3190
data .hdr .len = 0 ;
3165
3191
data .hdr .data = NULL ;
3192
+ data .found = false;
3166
3193
3167
3194
err = bt_obex_header_parse (buf , bt_obex_find_header_cb , & data );
3168
3195
if (err ) {
@@ -3190,6 +3217,7 @@ int bt_obex_get_header_wan_uuid(struct net_buf *buf, uint16_t *len, const uint8_
3190
3217
data .hdr .id = BT_OBEX_HEADER_ID_WAN_UUID ;
3191
3218
data .hdr .len = 0 ;
3192
3219
data .hdr .data = NULL ;
3220
+ data .found = false;
3193
3221
3194
3222
err = bt_obex_header_parse (buf , bt_obex_find_header_cb , & data );
3195
3223
if (err ) {
@@ -3218,6 +3246,7 @@ int bt_obex_get_header_obj_class(struct net_buf *buf, uint16_t *len, const uint8
3218
3246
data .hdr .id = BT_OBEX_HEADER_ID_OBJECT_CLASS ;
3219
3247
data .hdr .len = 0 ;
3220
3248
data .hdr .data = NULL ;
3249
+ data .found = false;
3221
3250
3222
3251
err = bt_obex_header_parse (buf , bt_obex_find_header_cb , & data );
3223
3252
if (err ) {
@@ -3247,6 +3276,7 @@ int bt_obex_get_header_session_param(struct net_buf *buf, uint16_t *len,
3247
3276
data .hdr .id = BT_OBEX_HEADER_ID_SESSION_PARAM ;
3248
3277
data .hdr .len = 0 ;
3249
3278
data .hdr .data = NULL ;
3279
+ data .found = false;
3250
3280
3251
3281
err = bt_obex_header_parse (buf , bt_obex_find_header_cb , & data );
3252
3282
if (err ) {
@@ -3275,6 +3305,7 @@ int bt_obex_get_header_session_seq_number(struct net_buf *buf, uint32_t *session
3275
3305
data .hdr .id = BT_OBEX_HEADER_ID_SESSION_SEQ_NUM ;
3276
3306
data .hdr .len = 0 ;
3277
3307
data .hdr .data = NULL ;
3308
+ data .found = false;
3278
3309
3279
3310
err = bt_obex_header_parse (buf , bt_obex_find_header_cb , & data );
3280
3311
if (err ) {
@@ -3302,6 +3333,7 @@ int bt_obex_get_header_action_id(struct net_buf *buf, uint32_t *action_id)
3302
3333
data .hdr .id = BT_OBEX_HEADER_ID_ACTION_ID ;
3303
3334
data .hdr .len = 0 ;
3304
3335
data .hdr .data = NULL ;
3336
+ data .found = false;
3305
3337
3306
3338
err = bt_obex_header_parse (buf , bt_obex_find_header_cb , & data );
3307
3339
if (err ) {
@@ -3329,6 +3361,7 @@ int bt_obex_get_header_dest_name(struct net_buf *buf, uint16_t *len, const uint8
3329
3361
data .hdr .id = BT_OBEX_HEADER_ID_DEST_NAME ;
3330
3362
data .hdr .len = 0 ;
3331
3363
data .hdr .data = NULL ;
3364
+ data .found = false;
3332
3365
3333
3366
err = bt_obex_header_parse (buf , bt_obex_find_header_cb , & data );
3334
3367
if (err ) {
@@ -3357,6 +3390,7 @@ int bt_obex_get_header_perm(struct net_buf *buf, uint32_t *perm)
3357
3390
data .hdr .id = BT_OBEX_HEADER_ID_PERM ;
3358
3391
data .hdr .len = 0 ;
3359
3392
data .hdr .data = NULL ;
3393
+ data .found = false;
3360
3394
3361
3395
err = bt_obex_header_parse (buf , bt_obex_find_header_cb , & data );
3362
3396
if (err ) {
@@ -3384,6 +3418,7 @@ int bt_obex_get_header_srm(struct net_buf *buf, uint8_t *srm)
3384
3418
data .hdr .id = BT_OBEX_HEADER_ID_SRM ;
3385
3419
data .hdr .len = 0 ;
3386
3420
data .hdr .data = NULL ;
3421
+ data .found = false;
3387
3422
3388
3423
err = bt_obex_header_parse (buf , bt_obex_find_header_cb , & data );
3389
3424
if (err ) {
@@ -3411,6 +3446,7 @@ int bt_obex_get_header_srm_param(struct net_buf *buf, uint8_t *srm_param)
3411
3446
data .hdr .id = BT_OBEX_HEADER_ID_SRM_PARAM ;
3412
3447
data .hdr .len = 0 ;
3413
3448
data .hdr .data = NULL ;
3449
+ data .found = false;
3414
3450
3415
3451
err = bt_obex_header_parse (buf , bt_obex_find_header_cb , & data );
3416
3452
if (err ) {
0 commit comments