File size: 7,490 Bytes
279efce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# Reset Bluetooth

You are helping the user completely reset the Bluetooth subsystem to fix persistent issues.

## Task

**WARNING:** This will remove all paired Bluetooth devices and require re-pairing.

1. **Ask user to confirm:**
   - This will unpair all Bluetooth devices
   - Devices will need to be paired again
   - Bluetooth service will be restarted

2. **Stop Bluetooth service:**
   ```bash
   # Stop Bluetooth
   sudo systemctl stop bluetooth

   # Verify stopped
   systemctl is-active bluetooth
   ```

3. **Kill any remaining Bluetooth processes:**
   ```bash
   # Kill bluetoothd
   sudo killall bluetoothd 2>/dev/null

   # Kill bluetooth-related processes
   ps aux | grep bluetooth | grep -v grep
   sudo killall -9 bluez-alsa bluez-obexd 2>/dev/null
   ```

4. **Remove Bluetooth pairing cache:**
   ```bash
   # Remove paired devices database
   sudo rm -rf /var/lib/bluetooth/*

   # Show what was removed
   echo "Removed all paired device data from /var/lib/bluetooth/"
   ```

5. **Clear user Bluetooth cache:**
   ```bash
   # Remove user Bluetooth cache
   rm -rf ~/.cache/bluetooth 2>/dev/null
   rm -rf ~/.local/share/bluetooth 2>/dev/null

   echo "Cleared user Bluetooth cache"
   ```

6. **Reset Bluetooth modules:**
   ```bash
   # Remove Bluetooth kernel modules
   sudo modprobe -r bnep
   sudo modprobe -r bluetooth
   sudo modprobe -r btusb
   sudo modprobe -r btintel  # Intel Bluetooth
   sudo modprobe -r btrtl    # Realtek Bluetooth

   echo "Bluetooth modules unloaded"
   sleep 2
   ```

7. **Reload Bluetooth modules:**
   ```bash
   # Reload modules
   sudo modprobe bluetooth
   sudo modprobe btusb
   sudo modprobe bnep

   # Load vendor-specific modules if needed
   sudo modprobe btintel 2>/dev/null
   sudo modprobe btrtl 2>/dev/null

   echo "Bluetooth modules reloaded"
   ```

8. **Reset HCI interface:**
   ```bash
   # Bring down Bluetooth controller
   sudo hciconfig hci0 down 2>/dev/null

   sleep 1

   # Bring it back up
   sudo hciconfig hci0 up 2>/dev/null

   # Reset the controller
   sudo hciconfig hci0 reset 2>/dev/null

   echo "HCI interface reset"
   ```

9. **Unblock Bluetooth:**
   ```bash
   # Unblock Bluetooth (soft and hard)
   sudo rfkill unblock bluetooth

   # Verify not blocked
   rfkill list bluetooth
   ```

10. **Start Bluetooth service:**
    ```bash
    # Start and enable Bluetooth
    sudo systemctl start bluetooth
    sudo systemctl enable bluetooth

    # Wait for service to fully start
    sleep 3

    # Check status
    systemctl status bluetooth --no-pager
    ```

11. **Power on Bluetooth controller:**
    ```bash
    # Turn on Bluetooth
    bluetoothctl power on

    # Set as discoverable (optional)
    bluetoothctl discoverable on

    # Set pairable
    bluetoothctl pairable on

    # Show controller info
    bluetoothctl show
    ```

12. **Verify Bluetooth is working:**
    ```bash
    # Check service
    echo "Service status: $(systemctl is-active bluetooth)"

    # Check controller
    echo "Controller powered: $(bluetoothctl show | grep Powered)"

    # Check for adapters
    hciconfig -a

    # Start scanning to test
    echo "Starting scan for 10 seconds..."
    timeout 10 bluetoothctl scan on

    bluetoothctl devices
    ```

13. **Create reset report:**
    ```bash
    cat > /tmp/bluetooth-reset-report.txt << EOF
    Bluetooth Reset Report
    ======================
    Date: $(date)

    === Service Status ===
    $(systemctl status bluetooth --no-pager)

    === Controller Info ===
    $(bluetoothctl show)

    === Hardware Info ===
    $(hciconfig -a)

    === RF Kill Status ===
    $(rfkill list bluetooth)

    === Loaded Modules ===
    $(lsmod | grep -E "bluetooth|bnep|btusb")

    === Kernel Messages (last 20) ===
    $(dmesg | grep -i bluetooth | tail -20)

    Next Steps:
    1. Your Bluetooth has been reset
    2. All previous pairings have been removed
    3. Put your device in pairing mode
    4. Use: bluetoothctl scan on
    5. Use: bluetoothctl pair <DEVICE_MAC>
    6. Use: bluetoothctl connect <DEVICE_MAC>
    EOF

    cat /tmp/bluetooth-reset-report.txt
    ```

## USB Bluetooth Adapter Reset

If using USB Bluetooth adapter:
```bash
# Find USB Bluetooth device
usb_bt=$(lsusb | grep -i bluetooth | head -1)
echo "Found: $usb_bt"

# Get bus and device numbers
bus=$(echo $usb_bt | awk '{print $2}')
dev=$(echo $usb_bt | awk '{print $4}' | tr -d ':')

# Reset USB device
echo "Resetting USB device: Bus $bus Device $dev"
sudo usb_modeswitch -v 0x$(lsusb | grep -i bluetooth | awk '{print $6}' | cut -d: -f1) \
                     -p 0x$(lsusb | grep -i bluetooth | awk '{print $6}' | cut -d: -f2) \
                     --reset-usb 2>/dev/null

# Alternative: unbind and rebind
device_path="/sys/bus/usb/devices/$bus-*"
echo "Unbinding and rebinding USB device"
echo "$bus-*" | sudo tee /sys/bus/usb/drivers/usb/unbind 2>/dev/null
sleep 2
echo "$bus-*" | sudo tee /sys/bus/usb/drivers/usb/bind 2>/dev/null
```

## Firmware Reload

If firmware issues persist:
```bash
# Check firmware files
ls -l /lib/firmware/ | grep -i bluetooth

# Reload firmware (device-specific)
# For Intel Bluetooth:
sudo rmmod btintel
sudo modprobe btintel

# For Realtek:
sudo rmmod btrtl
sudo modprobe btrtl

# Check if firmware loaded
dmesg | grep -i "bluetooth.*firmware" | tail -5
```

## Complete System Reset

Nuclear option if nothing else works:
```bash
# Stop everything
sudo systemctl stop bluetooth
sudo killall -9 bluetoothd

# Remove all data
sudo rm -rf /var/lib/bluetooth/*
rm -rf ~/.cache/bluetooth
rm -rf ~/.local/share/bluetooth

# Remove and reload all modules
sudo modprobe -r bnep bluetooth btusb btintel btrtl
sleep 3
sudo modprobe bluetooth btusb bnep

# Remove config (will regenerate)
sudo mv /etc/bluetooth/main.conf /etc/bluetooth/main.conf.backup

# Reboot system
echo "A system reboot is recommended for complete reset"
# sudo reboot
```

## Post-Reset Pairing

Guide user through pairing:
```bash
cat << 'EOF'
To pair a device after reset:

1. Put device in pairing mode
2. Start Bluetooth scan:
   bluetoothctl scan on

3. Find your device MAC address in the list

4. Pair the device:
   bluetoothctl pair XX:XX:XX:XX:XX:XX

5. Trust the device:
   bluetoothctl trust XX:XX:XX:XX:XX:XX

6. Connect:
   bluetoothctl connect XX:XX:XX:XX:XX:XX

7. Stop scanning:
   bluetoothctl scan off

For audio devices, you may need to restart PipeWire:
   systemctl --user restart pipewire wireplumber
EOF
```

## Troubleshooting

**Reset didn't work:**
```bash
# Try full reboot
sudo reboot

# Or try removing Bluetooth packages and reinstalling
# sudo apt remove bluez bluetooth
# sudo apt install bluez bluetooth
```

**Service won't start:**
```bash
# Check for errors
journalctl -u bluetooth --since "5 minutes ago" --no-pager

# Check if masked
sudo systemctl unmask bluetooth

# Force restart
sudo systemctl restart bluetooth
```

**No adapters found:**
```bash
# Check hardware detection
lsusb | grep -i bluetooth
lspci | grep -i bluetooth

# Check kernel modules
lsmod | grep bluetooth
```

## Notes

- Backup `/var/lib/bluetooth/` before reset if you want to preserve pairings
- Some devices may require specific PIN codes during pairing
- Audio devices may need additional PipeWire/PulseAudio configuration
- Bluetooth 5.0+ devices are backward compatible
- LE (Low Energy) devices may require special pairing procedures
- System reboot recommended after complete reset
- Check `/var/log/syslog` for detailed Bluetooth errors