Commit Graph

145 Commits

Author SHA1 Message Date
Martin Mathieson 7199a04c4c BTLE: Fix a copy/paste error in control_opcode_vals 2023-01-23 10:32:52 +00:00
Rubin Gerritsen 751d836123 btle: Add control proc enum to make code self-documenting
Previously hardcoded integers were used in control procedure
dissection. This resulted in hard to read code.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2023-01-07 08:30:14 +00:00
Rubin Gerritsen b857c3189a btle: Dissector name updated to 5.3
It is dissecting 5.3, so it makes sense the name is updated

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2023-01-07 08:30:14 +00:00
Rubin Gerritsen 08d78fddb3 btle: Add some braces to if statements
As suggested in merge request 9233.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2023-01-07 08:30:14 +00:00
Rubin Gerritsen 0627ece136 btle: Fix bitmask for 5.3 feature sets
These were incorrectly set in
8f747e41c9

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2023-01-07 08:30:14 +00:00
Rubin Gerritsen 8f747e41c9 Bluetooth: Dissect features defined in 5.1 - 5.3
See Core_v5.3, Vol 6, Part B, Section 4.6.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2023-01-04 09:32:28 +00:00
Rubin Gerritsen 78c7b184c9 Bluetooth: Dissect 5.3 ACL control procedure packets
The dissection also includes adding control procedure sequence validation.
See Core_v5.3, Vol 6, Part B, Section 2.4.2.36-39 and Section 5.1.19-22.

Core_v5.3 was released in 2021.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2023-01-04 09:32:28 +00:00
Rubin Gerritsen f41ce48d39 Bluetooth: Perform control proc validation on LL_CIS_TERMINATE_IND
This will add expert info if the packet is being sent when
it is not allowed to be sent

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2023-01-04 09:32:28 +00:00
Rubin Gerritsen e273428b7c Bluetooth: Perform control proc validation on LL_PERIODIC_SYNC_IND
This will add expert info if the packet is being sent when
it is not allowed to be sent

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2023-01-04 09:32:28 +00:00
Rubin Gerritsen c0b6b858dc Bluetooth: Add more validation to power control procedures
The LL_REJECT_EXT_IND is an allowed response to the LL_POWER_CONTROL_REQ,
see Core_v5.3, Vol 6, Part B, Section 5.1.17.

Performs control procedure validation one a LL_POWER_CHANGE_IND is sent

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2023-01-04 09:32:28 +00:00
Rubin Gerritsen 1ebd11dd49 Bluetooth: Allow LL_REJECT_EXT_IND as a response to LL_CIS_REQ/RSP
In Core_v5.3, Vol 6, Part B, Section 5.1.15 describes that this
is allowed.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2023-01-04 09:32:28 +00:00
Rubin Gerritsen 62fafa5fc9 Bluetooth: Allow LL_REJECT_EXT_IND as a response to LL_CTE_REQ
In Core_v5.3, Vol 6, Part B, Section 5.1.12 describes that this
is allowed.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2023-01-04 09:32:28 +00:00
Rubin Gerritsen 1eeb342476 Bluetooth: Detect invalid incompatible control procedure conflict resolution
Core spec 5.2, Vol 6, Part B, Section 5.3 describes how the link layer should
resolve the scenario where a collision occurs where both link layers initiate
incompabile control procedures.

This commit adds expect information for the case where these conflicts are not
handled according to spec.

Example of an invalid scenario:

M->S: LL_PHY_REQ
S->M: LL_PHY_REQ
S->M: LL_PHY_RSP
M->S: LL_PHY_UPDATE_IND

The correct sequence for this scenario is:
M->S: LL_PHY_REQ
S->M: LL_PHY_REQ
S->M: LL_PHY_RSP
M->S: LL_REJECT_EXT_IND
M->S: LL_PHY_UPDATE_IND

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2023-01-04 09:32:28 +00:00
Rubin Gerritsen aefd842613 Bluetooth: Refactor adding control procedure packets to contexts
By defining control_proc_add_frame(), control_proc_add_last_frame(), and
control_proc_add_frame_with_instant() a lot of duplicate code can be removed.

This commit makes the checks for the CIS establishment procedure follow the spec.
Previously the dissector had two bugs:
 - It allowed both master and slave to initiate this procedure
 - The procedure was marked as complete once the LL_CIS_RSP was received.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2023-01-04 09:32:28 +00:00
Rubin Gerritsen 616ca5f512 Bluetooth: Refactor starting control proc context
Moves the check of starting a control procedure before the previous was complete inside
the function control_proc_start(). This check should be beformed before starting any
control procedure. Therefore it is better to simply move it inside the funciton to remove
code duplication.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2023-01-04 09:32:28 +00:00
Rubin Gerritsen 887fc09100 Bluetooth: Fix detection of colliding peer proc
A device is not allowed to start a new control procedure if it
has already responded to a peer procedure.

The detection of a response being present did not take into account
that some procedures do not have a response.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2022-10-31 13:10:53 +00:00
Joakim Andersson 169867aafb Bluetooth: Handle PHY Update procedure with no change
Handle PHY Update procedure where both PHY fields are set to no change.
This procedure is terminated immediately without instant.
The instant field is reserved for future use.

This fixes the Control Procedure validation not marking this procedure
as terminated, and marking all following control procedures as invalid
since the instant has not yet been reached.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2022-09-15 11:41:22 +00:00
Joakim Andersson 230a2ae16a Bluetooth: Fix reserved field in CTE request control packet
Fix reserved field in CTE request, copy paste mistake from MinCTELenReq
field.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2022-09-15 11:41:22 +00:00
Rubin Gerritsen 56817af9b5 Bluetooth: Decode LL_VERSION_IND packets with version 5.3
Bluetooth 5.3 was released 2021-07-13.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2022-08-17 16:29:25 +02:00
Jaap Keuter bdb460ef69 Bluetooth: have BT specific global names contain bluetooth 2022-03-14 20:02:10 +00:00
João Valverde 22ee2764a7 Replace g_snprintf() with snprintf() (dissectors)
Use macros from inttypes.h with format strings.
2021-12-19 20:25:11 +00:00
Stig Bjørlykke 3badea1e80 btle: Improve Advertising Data reassembly
Copy Advertiser Address from AUX_ADV_IND if not present in AUX_CHAIN_IND
to make reassembly work. Check for valid reassembled data before
doing dissect_ad_eir().
2021-11-20 15:38:24 +00:00
Gerald Combs d19bdb70ed BT LE LL: Add a NULL Check.
Fixes #17681.
2021-10-26 23:58:52 +00:00
Joakim Andersson 5c46e0eac3 btle: Add support for CTE Info field in Data Physical Channel PDUs
Add support for the optional CTE Info field in the Data Physical Channel
PDU header.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-09-02 17:48:43 +00:00
Joakim Andersson eda513d972 btle: Update text for channel to include index
Update channel to include index to clear up possible confusion if this
is RF channel, or channel index.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-08-29 13:37:23 +00:00
Joakim Andersson b75107c77f Bluetooth: Fix clock accuracy field offset in sync info
Fix clock accuracy field offset in the sync info information in the
extended advertising header.
The field was placed at offset 4 instead of the current offset + 4.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-08-10 20:33:25 +00:00
Evan Huus 8ee8808876 First pass pinfo->pool conversion, part 2
Automated find/replace of wmem_packet_scope() with pinfo->pool in all
files where it didn't cause a build failure.
2021-07-21 09:54:57 -04:00
Joakim Andersson 72d331cfdc btle: Fix parsing of empty extendend advertising header
Fix parsing of extended advertising when the extended advertising header
is empty. The flag field is excluded when none of the fields are present
and the extended header length field is 0.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-06-25 11:34:17 +00:00
Joakim Andersson 23d3e0bdde btle: Fix parsing of CTE Info field in extended advertising header
Fix parsing of the CTE Info field in the extended advertising header.
The bit-mask of the different fields was wrongly placed.
The text of the different fields all said "CTE Info".
The CTE Time field was added twice.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-06-25 11:34:17 +00:00
Thomas Sailer b5f2ed34b1 btle: decode new control PDUs and advertising info in 5.2
Decode control PDUs and advertising informationintroduced in
Bluetooth Core v5.2
2021-03-13 16:56:11 +00:00
Martin Mathieson 11e919898c Set a few more dissector vars/funs to static.
These are the last of the easy ones to fix/set.
2021-02-15 09:20:58 +00:00
Alexis La Goutte f2888ecf38 btle: Fix Dead Store found by Clang Analyzer
packet-btle.c:1417:13: warning: Value stored to 'item' is never read [deadcode.DeadStores]
2021-02-11 21:56:37 +00:00
Guy Harris c26addae44 One more check for connection_info being non-null is needed.
This fixes issue #17182.
2021-01-27 00:15:24 -08:00
Rubin Gerritsen 277890d7e1 Bluetooth: Fix NULL pointer dereference crash
Occured when a control procedure packet was logged without connection
context.

The bug was introduced in 0dab2494ca

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2021-01-26 10:53:35 +00:00
Rubin Gerritsen 32cadbacb1 Bluetooth: Detect invalid control procedure collision resolution
See Bluetooth Core Spec, Vol 6, Part B, Section 5.3

If the event counter is available, the procedure is marked as complete
when the instant is reached.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2021-01-26 07:05:08 +00:00
Rubin Gerritsen 0dab2494ca Bluetooth: Match control procedure requests with responses
This makes it easier to read logs where both the master
and slave initiate control procedures at the same time.
Retransmitted packets are not part of the request/response
tracing.

In order to perform the analysis, direction information must
be available.

The matching is implemented by storing control procedure contexts
for each direction for each connection object as each direction
may initiate its own procedure.

Limitations:
- When there is a control procedure violation where a device
  initiates a new procedure before the previous is complete,
  only the first procedure is traced.
  It would be possible to create more advanced tracing by
  storing a list of contexts per frame.
  However, as this is anyways a specification violation, this
  adds unnecessary complexity.
- Control procedures involving an instant are marked as completed
  when the last frame is sent even though the control procedure
  is completed when the instant is reached.
  This is the best possible approach when the event counter is
  not available.
  Due to this limitation, we are not able to detect the control
  procedure violation where a device initiates a new procedure
  before the instant is reached.

The following control procedure violations are detected:
- Starting a control procedure before the previous is complete.
  Control procedure violations where a new procedure is started
  before the instant is reached is currently not detected.
  That requires knowing the event counter.
- Control procedure packets that are not valid responses to an
  existing ongoing control procedure.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2021-01-24 14:12:20 +01:00
Joakim Andersson 8da6d6d1cc bluetooth: Add event counter and event counter valid to context
Add event counter and event counter valid variables to the btle context.
This information has to come from the capture context, and the information
is useful to provide context information around LL control procedures with
instant.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-01-21 07:22:47 +00:00
Rubin Gerritsen 0e84610676 Bluetooth: Refactor dissection of control proc packets
Now they appear in the correct order.
Some common code snippets are extracted out to separate functions.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2021-01-11 13:56:03 +00:00
Rubin Gerritsen 7304487462 btle: LL_REJECT_IND_EXT -> LL_REJECT_EXT_IND
Use the name defined by the Bluetooth Specification.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-12-11 08:05:03 +00:00
Joakim Andersson a42bbbeff6 Bluetooth: Fix l2cap reassembly resuming old reassembly
Fix l2cap reassembly resuming reassembly on old fragment that has
failed when a new packet arrives that matches the remaining
segmentation length of the failed reassembly.
Update the l2cap_index and set segmentation started to false so
that this does not happen anymore.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-12-04 14:41:56 +00:00
Joakim Andersson e06afb4252 bluetooth: Change wording of sequence number context information
Change the wording of the sequence number context information from
"Wrong" to the more accurate description that this is a retransmit.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-11-28 11:15:59 +00:00
Joakim Andersson 7f5ddfc7f3 bluetooth: Add context information for next expected sequence number
Add context information for next expected sequence number so that
analysing for acknowledgedment or request for retransmit can be done
without comparing packets manually.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-11-28 11:15:59 +00:00
lutianxiong 65ac14b51a btle: Initialise acl_data to avoid wild pointer dereference
Close oss-fuzz issue 25007.
2020-11-19 12:44:40 +00:00
Martin Mathieson 7c178d752f Bluetooth protocols: fix some protocol item lengths 2020-10-28 22:35:28 +00:00
Martin Mathieson 4a4e50992a More spelling fixes, start of second pass of dissectors.
Now easier to find errors due to script improvements and more complete
dictionary file.
2020-08-30 22:34:34 +01:00
Martin Mathieson 1dd8bb2811 Find and fix dissectors that should be using a default tfs.
Found using tools/check_tfs.py, included in this commit.
Here are the reports that were fixed here:

Examining:
All dissector modules

epan/dissectors/packet-assa_r3.c tfs_mortisepins_flags - could have used tfs_high_low from tfs.c instead:  {High,Low}
epan/dissectors/packet-btle.c tfs_present_bit - could have used tfs_present_not_present from tfs.c instead:  {Present,Not Present}
epan/dissectors/packet-dhcp.c tfs_fqdn_s - could have used tfs_server_client from tfs.c instead:  {Server,Client}
epan/dissectors/packet-docsis-macmgmt.c mdd_tfs_on_off - could have used tfs_on_off from tfs.c instead:  {On,Off}
epan/dissectors/packet-docsis-macmgmt.c mdd_tfs_en_dis - could have used tfs_enabled_disabled from tfs.c instead:  {Enabled,Disabled}
epan/dissectors/packet-docsis-macmgmt.c req_not_req_tfs - could have used tfs_requested_not_requested from tfs.c instead:  {Requested,Not Requested}
epan/dissectors/packet-docsis-tlv.c on_off_tfs - could have used tfs_on_off from tfs.c instead:  {On,Off}
epan/dissectors/packet-docsis-tlv.c activation_tfs - could have used tfs_active_inactive from tfs.c instead:  {Active,Inactive}
epan/dissectors/packet-docsis.c ena_dis_tfs - could have used tfs_enabled_disabled from tfs.c instead:  {Enabled,Disabled}
epan/dissectors/packet-ecmp.c tfs_not_expected_expected - could have used tfs_odd_even from tfs.c instead:  {Odd,Even}
epan/dissectors/packet-erf.c erf_link_status_tfs - could have used tfs_up_down from tfs.c instead:  {Up,Down}
epan/dissectors/packet-h263.c on_off_flg - could have used tfs_on_off from tfs.c instead:  {On,Off}
epan/dissectors/packet-h263.c cpm_flg - could have used tfs_on_off from tfs.c instead:  {On,Off}
epan/dissectors/packet-interlink.c flags_set_notset - could have used tfs_set_notset from tfs.c instead:  {Set,Not set}
epan/dissectors/packet-ip.c tos_set_low - could have used tfs_low_normal from tfs.c instead:  {Low,Normal}
epan/dissectors/packet-ip.c tos_set_high - could have used tfs_high_normal from tfs.c instead:  {High,Normal}
epan/dissectors/packet-isakmp.c flag_r - could have used tfs_response_request from tfs.c instead:  {Response,Request}
epan/dissectors/packet-isis-lsp.c tfs_metric_supported_not_supported - could have used tfs_no_yes from tfs.c instead:  {No,Yes}
epan/dissectors/packet-kerberos.c supported_tfs - could have used tfs_supported_not_supported from tfs.c instead:  {Supported,Not supported}
epan/dissectors/packet-kerberos.c set_tfs - could have used tfs_set_notset from tfs.c instead:  {Set,Not set}
epan/dissectors/packet-mac-lte.c mac_lte_scell_status_vals - could have used tfs_activated_deactivated from tfs.c instead:  {Activated,Deactivated}
epan/dissectors/packet-p_mul.c no_yes - could have used tfs_no_yes from tfs.c instead:  {No,Yes}
epan/dissectors/packet-pgm.c opts_present - could have used tfs_present_not_present from tfs.c instead:  {Present,Not Present}
epan/dissectors/packet-rsl.c rsl_ms_fpc_epc_mode_vals - could have used tfs_inuse_not_inuse from tfs.c instead:  {In use,Not in use}
epan/dissectors/packet-sita.c tfs_sita_on_off - could have used tfs_on_off from tfs.c instead:  {On,Off}
epan/dissectors/packet-vines.c tfs_vine_rtp_no_yes - could have used tfs_no_yes from tfs.c instead:  {No,Yes}
epan/dissectors/packet-vnc.c button_mask_tfs - could have used tfs_pressed_not_pressed from tfs.c instead:  {Pressed,Not pressed}
27 issues found
Change-Id: I7e53b491f20289955c9e9caa8357197d9010a5aa
Reviewed-on: https://code.wireshark.org/review/38087
Petri-Dish: Martin Mathieson <martin.r.mathieson@googlemail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-08-07 21:27:26 +00:00
Piotr Winiarczyk a2d994d334 Btle: AE Host Advertising Data reassembly
Bluetooth Low Energy Advertising Extensions Host Advertising Data reassembly.

Bug: 16666
Change-Id: I78fea77a75f07ff7ef8a661e81ac3c729980de0e
Reviewed-on: https://code.wireshark.org/review/38016
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-08-03 06:54:42 +00:00
Anders Broman 1484c1e7f6 Fix Wpointer-sign warnings.
Change-Id: Ia51998293b967f363856d2b9ac92f498a9f54d76
Reviewed-on: https://code.wireshark.org/review/37769
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-07-07 18:42:07 +00:00
Guy Harris e1d9a226a2 Fix the type of arrays of pointers to hf_ values for bitfield routines.
The static arrays are supposed to be arrays of const pointers to int,
not arrays of non-const pointers to const int.

Fixing that means some bugs (scribbling on what's *supposed* to be a
const array) will be caught (see packet-ieee80211-radiotap.c for
examples, the first of which inspired this change and the second of
which was discovered while testing compiles with this change), and
removes the need for some annoying casts.

Also make some of those arrays static while we're at it.

Update documentation and dissector-generator tools.

Change-Id: I789da5fc60aadc15797cefecfd9a9fbe9a130ccc
Reviewed-on: https://code.wireshark.org/review/37517
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-06-19 11:32:26 +00:00
Uli Heilmeier 7c6e1a02ce BTLE: check for btle_context
Check for btle_context before accessing it.

Bug: 16612
Change-Id: I8ad0237a6f742f4091e886b0151917542d2eea82
Reviewed-on: https://code.wireshark.org/review/37387
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-06-06 14:38:34 +00:00