@@ -3010,22 +3010,16 @@ static void btusb_coredump_qca(struct hci_dev *hdev)
3010
3010
bt_dev_err (hdev , "%s: triggle crash failed (%d)" , __func__ , err );
3011
3011
}
3012
3012
3013
- /*
3014
- * ==0: not a dump pkt.
3015
- * < 0: fails to handle a dump pkt
3016
- * > 0: otherwise.
3017
- */
3013
+ /* Return: 0 on success, negative errno on failure. */
3018
3014
static int handle_dump_pkt_qca (struct hci_dev * hdev , struct sk_buff * skb )
3019
3015
{
3020
- int ret = 1 ;
3016
+ int ret = 0 ;
3021
3017
u8 pkt_type ;
3022
3018
u8 * sk_ptr ;
3023
3019
unsigned int sk_len ;
3024
3020
u16 seqno ;
3025
3021
u32 dump_size ;
3026
3022
3027
- struct hci_event_hdr * event_hdr ;
3028
- struct hci_acl_hdr * acl_hdr ;
3029
3023
struct qca_dump_hdr * dump_hdr ;
3030
3024
struct btusb_data * btdata = hci_get_drvdata (hdev );
3031
3025
struct usb_device * udev = btdata -> udev ;
@@ -3035,30 +3029,14 @@ static int handle_dump_pkt_qca(struct hci_dev *hdev, struct sk_buff *skb)
3035
3029
sk_len = skb -> len ;
3036
3030
3037
3031
if (pkt_type == HCI_ACLDATA_PKT ) {
3038
- acl_hdr = hci_acl_hdr (skb );
3039
- if (le16_to_cpu (acl_hdr -> handle ) != QCA_MEMDUMP_ACL_HANDLE )
3040
- return 0 ;
3041
3032
sk_ptr += HCI_ACL_HDR_SIZE ;
3042
3033
sk_len -= HCI_ACL_HDR_SIZE ;
3043
- event_hdr = (struct hci_event_hdr * )sk_ptr ;
3044
- } else {
3045
- event_hdr = hci_event_hdr (skb );
3046
3034
}
3047
3035
3048
- if ((event_hdr -> evt != HCI_VENDOR_PKT )
3049
- || (event_hdr -> plen != (sk_len - HCI_EVENT_HDR_SIZE )))
3050
- return 0 ;
3051
-
3052
3036
sk_ptr += HCI_EVENT_HDR_SIZE ;
3053
3037
sk_len -= HCI_EVENT_HDR_SIZE ;
3054
3038
3055
3039
dump_hdr = (struct qca_dump_hdr * )sk_ptr ;
3056
- if ((sk_len < offsetof(struct qca_dump_hdr , data ))
3057
- || (dump_hdr -> vse_class != QCA_MEMDUMP_VSE_CLASS )
3058
- || (dump_hdr -> msg_type != QCA_MEMDUMP_MSG_TYPE ))
3059
- return 0 ;
3060
-
3061
- /*it is dump pkt now*/
3062
3040
seqno = le16_to_cpu (dump_hdr -> seqno );
3063
3041
if (seqno == 0 ) {
3064
3042
set_bit (BTUSB_HW_SSR_ACTIVE , & btdata -> flags );
@@ -3132,17 +3110,84 @@ static int handle_dump_pkt_qca(struct hci_dev *hdev, struct sk_buff *skb)
3132
3110
return ret ;
3133
3111
}
3134
3112
3113
+ /* Return: true if the ACL packet is a dump packet, false otherwise. */
3114
+ static bool acl_pkt_is_dump_qca (struct hci_dev * hdev , struct sk_buff * skb )
3115
+ {
3116
+ u8 * sk_ptr ;
3117
+ unsigned int sk_len ;
3118
+
3119
+ struct hci_event_hdr * event_hdr ;
3120
+ struct hci_acl_hdr * acl_hdr ;
3121
+ struct qca_dump_hdr * dump_hdr ;
3122
+
3123
+ sk_ptr = skb -> data ;
3124
+ sk_len = skb -> len ;
3125
+
3126
+ acl_hdr = hci_acl_hdr (skb );
3127
+ if (le16_to_cpu (acl_hdr -> handle ) != QCA_MEMDUMP_ACL_HANDLE )
3128
+ return false;
3129
+
3130
+ sk_ptr += HCI_ACL_HDR_SIZE ;
3131
+ sk_len -= HCI_ACL_HDR_SIZE ;
3132
+ event_hdr = (struct hci_event_hdr * )sk_ptr ;
3133
+
3134
+ if ((event_hdr -> evt != HCI_VENDOR_PKT ) ||
3135
+ (event_hdr -> plen != (sk_len - HCI_EVENT_HDR_SIZE )))
3136
+ return false;
3137
+
3138
+ sk_ptr += HCI_EVENT_HDR_SIZE ;
3139
+ sk_len -= HCI_EVENT_HDR_SIZE ;
3140
+
3141
+ dump_hdr = (struct qca_dump_hdr * )sk_ptr ;
3142
+ if ((sk_len < offsetof(struct qca_dump_hdr , data )) ||
3143
+ (dump_hdr -> vse_class != QCA_MEMDUMP_VSE_CLASS ) ||
3144
+ (dump_hdr -> msg_type != QCA_MEMDUMP_MSG_TYPE ))
3145
+ return false;
3146
+
3147
+ return true;
3148
+ }
3149
+
3150
+ /* Return: true if the event packet is a dump packet, false otherwise. */
3151
+ static bool evt_pkt_is_dump_qca (struct hci_dev * hdev , struct sk_buff * skb )
3152
+ {
3153
+ u8 * sk_ptr ;
3154
+ unsigned int sk_len ;
3155
+
3156
+ struct hci_event_hdr * event_hdr ;
3157
+ struct qca_dump_hdr * dump_hdr ;
3158
+
3159
+ sk_ptr = skb -> data ;
3160
+ sk_len = skb -> len ;
3161
+
3162
+ event_hdr = hci_event_hdr (skb );
3163
+
3164
+ if ((event_hdr -> evt != HCI_VENDOR_PKT )
3165
+ || (event_hdr -> plen != (sk_len - HCI_EVENT_HDR_SIZE )))
3166
+ return false;
3167
+
3168
+ sk_ptr += HCI_EVENT_HDR_SIZE ;
3169
+ sk_len -= HCI_EVENT_HDR_SIZE ;
3170
+
3171
+ dump_hdr = (struct qca_dump_hdr * )sk_ptr ;
3172
+ if ((sk_len < offsetof(struct qca_dump_hdr , data )) ||
3173
+ (dump_hdr -> vse_class != QCA_MEMDUMP_VSE_CLASS ) ||
3174
+ (dump_hdr -> msg_type != QCA_MEMDUMP_MSG_TYPE ))
3175
+ return false;
3176
+
3177
+ return true;
3178
+ }
3179
+
3135
3180
static int btusb_recv_acl_qca (struct hci_dev * hdev , struct sk_buff * skb )
3136
3181
{
3137
- if (handle_dump_pkt_qca (hdev , skb ))
3138
- return 0 ;
3182
+ if (acl_pkt_is_dump_qca (hdev , skb ))
3183
+ return handle_dump_pkt_qca ( hdev , skb ) ;
3139
3184
return hci_recv_frame (hdev , skb );
3140
3185
}
3141
3186
3142
3187
static int btusb_recv_evt_qca (struct hci_dev * hdev , struct sk_buff * skb )
3143
3188
{
3144
- if (handle_dump_pkt_qca (hdev , skb ))
3145
- return 0 ;
3189
+ if (evt_pkt_is_dump_qca (hdev , skb ))
3190
+ return handle_dump_pkt_qca ( hdev , skb ) ;
3146
3191
return hci_recv_frame (hdev , skb );
3147
3192
}
3148
3193
0 commit comments