mirror of
				https://github.com/iiab/iiab.git
				synced 2025-03-09 15:40:17 +00:00 
			
		
		
		
	Merge pull request #1716 from tim-moody/bluetooth
Bluetooth PAN and Terminal servers
This commit is contained in:
		
						commit
						ca034ffa01
					
				
					 17 changed files with 245 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -28,6 +28,12 @@
 | 
			
		|||
  when: squid_install | bool
 | 
			
		||||
  tags: base, squid, network, domain
 | 
			
		||||
 | 
			
		||||
- name: Install Bluetooth - only on Raspberry  Pi
 | 
			
		||||
  include_role:
 | 
			
		||||
    name: bluetooth
 | 
			
		||||
  when: is_rpi | bool and bluetooth_install | bool
 | 
			
		||||
  tags: bluetooth
 | 
			
		||||
 | 
			
		||||
# NETWORK moved to the very end, after Stage 9 (9-LOCAL-ADDONS)
 | 
			
		||||
# It can also be run manually using: cd /opt/iiab/iiab; ./iiab-network
 | 
			
		||||
#
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										11
									
								
								roles/bluetooth/README.rst
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								roles/bluetooth/README.rst
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,11 @@
 | 
			
		|||
================
 | 
			
		||||
Bluetooth README
 | 
			
		||||
================
 | 
			
		||||
 | 
			
		||||
This role provides two services, pan or Personal Area Network, and term, terminal emulation.
 | 
			
		||||
 | 
			
		||||
They may be turned on or off with iiab-bt-pan-on(off) and iiab-bt-term-on(off), respectively.
 | 
			
		||||
 | 
			
		||||
The terminal emulates a vt100 and operates at 115200 bps, but does not always connect reliably.
 | 
			
		||||
 | 
			
		||||
This role is only available for the Raspberry Pi.
 | 
			
		||||
							
								
								
									
										3
									
								
								roles/bluetooth/defaults/main.yml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								roles/bluetooth/defaults/main.yml
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,3 @@
 | 
			
		|||
bluetooth_install: False
 | 
			
		||||
bluetooth_enabled: False
 | 
			
		||||
bluetooth_term_enabled: False
 | 
			
		||||
							
								
								
									
										4
									
								
								roles/bluetooth/tasks/main.yml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								roles/bluetooth/tasks/main.yml
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,4 @@
 | 
			
		|||
# This is rpi only
 | 
			
		||||
 | 
			
		||||
- include_tasks: rpi_install.yml
 | 
			
		||||
  when: is_rpi and bluetooth_install
 | 
			
		||||
							
								
								
									
										132
									
								
								roles/bluetooth/tasks/rpi_install.yml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										132
									
								
								roles/bluetooth/tasks/rpi_install.yml
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,132 @@
 | 
			
		|||
# This is rpi only
 | 
			
		||||
 | 
			
		||||
- name: "Install rpi bluetooth packages"
 | 
			
		||||
  package:
 | 
			
		||||
    name:
 | 
			
		||||
      - bluetooth
 | 
			
		||||
      - bluez
 | 
			
		||||
      - bluez-tools
 | 
			
		||||
    state: present
 | 
			
		||||
 | 
			
		||||
- name: Create bluetooth services
 | 
			
		||||
  template:
 | 
			
		||||
    backup: no
 | 
			
		||||
    src: "{{ item.src }}"
 | 
			
		||||
    dest: "{{ item.dest }}"
 | 
			
		||||
    owner: root
 | 
			
		||||
    group: root
 | 
			
		||||
    mode: 0644
 | 
			
		||||
  with_items:
 | 
			
		||||
    - { src: 'bt-agent.service.j2', dest: '/etc/systemd/system/bt-agent.service' }
 | 
			
		||||
    - { src: 'bt-pan.service.j2', dest: '/etc/systemd/system/bt-pan.service' }
 | 
			
		||||
    - { src: 'bt-term.service.j2', dest: '/etc/systemd/system/bt-term.service' }
 | 
			
		||||
    - { src: 'network.conf.j2', dest: '/etc/bluetooth/network.conf' }
 | 
			
		||||
 | 
			
		||||
- name: Create bluetooth utility scripts
 | 
			
		||||
  template:
 | 
			
		||||
    backup: no
 | 
			
		||||
    src: "{{ item.src }}"
 | 
			
		||||
    dest: "{{ item.dest }}"
 | 
			
		||||
    owner: root
 | 
			
		||||
    group: root
 | 
			
		||||
    mode: 0755
 | 
			
		||||
  with_items:
 | 
			
		||||
    - { src: 'iiab-bt-pan-on.j2', dest: '/usr/bin/iiab-bt-pan-on' }
 | 
			
		||||
    - { src: 'iiab-bt-pan-off.j2', dest: '/usr/bin/iiab-bt-pan-off' }
 | 
			
		||||
    - { src: 'iiab-bt-pan-discoverable-on.j2', dest: 'iiab-bt-pan-discoverable-on' }
 | 
			
		||||
    - { src: 'iiab-bt-term-on.j2', dest: '/usr/bin/iiab-bt-term-on' }
 | 
			
		||||
    - { src: 'iiab-bt-term-off.j2', dest: '/usr/bin/iiab-bt-term-off' }
 | 
			
		||||
 | 
			
		||||
# Bluetooth service needs /usr/lib/bluetooth/bluetoothd -C --noplugin=sap
 | 
			
		||||
# Copy and patch it
 | 
			
		||||
 | 
			
		||||
- name: Copy the bluetooth service
 | 
			
		||||
  template:
 | 
			
		||||
    dest: /etc/systemd/system/bluetooth.service
 | 
			
		||||
    src: /lib/systemd/system/bluetooth.service
 | 
			
		||||
 | 
			
		||||
- name: Add  -C --noplugin=sap to execStart of bluetooth service
 | 
			
		||||
  lineinfile:
 | 
			
		||||
    path: /etc/systemd/system/bluetooth.service
 | 
			
		||||
    regexp: '^ExecStart=/usr/lib/bluetooth/bluetoothd'
 | 
			
		||||
    line: 'ExecStart=/usr/lib/bluetooth/bluetoothd -C --noplugin=sap'
 | 
			
		||||
 | 
			
		||||
- name: Set discoverable not to timeout
 | 
			
		||||
  lineinfile:
 | 
			
		||||
    path: /etc/bluetooth/main.conf
 | 
			
		||||
    regexp: '^#DiscoverableTimeout'
 | 
			
		||||
    line: 'DiscoverableTimeout = 0'
 | 
			
		||||
 | 
			
		||||
- name: Enable & Restart 'bt-agent' service
 | 
			
		||||
  systemd:
 | 
			
		||||
    daemon_reload: yes
 | 
			
		||||
    name: bluetooth
 | 
			
		||||
    enabled: yes
 | 
			
		||||
    state: restarted
 | 
			
		||||
 | 
			
		||||
# enable or disable bt-agent
 | 
			
		||||
- name: Enable & Restart 'bt-agent' service
 | 
			
		||||
  systemd:
 | 
			
		||||
    daemon_reload: yes
 | 
			
		||||
    name: bt-agent
 | 
			
		||||
    enabled: yes
 | 
			
		||||
    state: restarted
 | 
			
		||||
  when: bluetooth_enabled or bluetooth_term_enabled
 | 
			
		||||
 | 
			
		||||
- name: Disable 'bt-agent' service
 | 
			
		||||
  systemd:
 | 
			
		||||
    daemon_reload: yes
 | 
			
		||||
    name: bt-agent
 | 
			
		||||
    enabled: no
 | 
			
		||||
    state: stopped
 | 
			
		||||
  when: not bluetooth_enabled and not bluetooth_term_enabled
 | 
			
		||||
 | 
			
		||||
# enable or disable bt-pan
 | 
			
		||||
- name: Enable & Restart 'bt-pan' service
 | 
			
		||||
  systemd:
 | 
			
		||||
    daemon_reload: yes
 | 
			
		||||
    name: bt-pan
 | 
			
		||||
    enabled: yes
 | 
			
		||||
    state: restarted
 | 
			
		||||
  when: bluetooth_enabled | bool
 | 
			
		||||
 | 
			
		||||
- name: Disable 'bt-pan' service
 | 
			
		||||
  systemd:
 | 
			
		||||
    daemon_reload: yes
 | 
			
		||||
    name: bt-pan
 | 
			
		||||
    enabled: no
 | 
			
		||||
    state: stopped
 | 
			
		||||
  when: not bluetooth_enabled | bool
 | 
			
		||||
 | 
			
		||||
# enable or disable bt-term
 | 
			
		||||
- name: Enable & Restart 'bt-term' service
 | 
			
		||||
  systemd:
 | 
			
		||||
    daemon_reload: yes
 | 
			
		||||
    name: bt-term
 | 
			
		||||
    enabled: yes
 | 
			
		||||
    state: restarted
 | 
			
		||||
  when: bluetooth_term_enabled | bool
 | 
			
		||||
 | 
			
		||||
- name: Disable 'bt-term' service
 | 
			
		||||
  systemd:
 | 
			
		||||
    daemon_reload: yes
 | 
			
		||||
    name: bt-term
 | 
			
		||||
    enabled: no
 | 
			
		||||
    state: stopped
 | 
			
		||||
  when: not bluetooth_term_enabled | bool
 | 
			
		||||
 | 
			
		||||
- name: Add 'bluetooth' variable values to {{ iiab_ini_file }}
 | 
			
		||||
  ini_file:
 | 
			
		||||
    path: "{{ iiab_ini_file }}"
 | 
			
		||||
    section: bluetooth
 | 
			
		||||
    option: "{{ item.option }}"
 | 
			
		||||
    value: "{{ item.value }}"
 | 
			
		||||
  with_items:
 | 
			
		||||
    - option: name
 | 
			
		||||
      value: Bluetooth
 | 
			
		||||
    - option: description
 | 
			
		||||
      value: '"Bluetooth services for pan and terminal."'
 | 
			
		||||
    - option: bluetooth_enabled
 | 
			
		||||
      value: "{{ bluetooth_enabled }}"
 | 
			
		||||
    - option: bluetooth_term_enabled
 | 
			
		||||
      value: "{{ bluetooth_term_enabled }}"
 | 
			
		||||
							
								
								
									
										10
									
								
								roles/bluetooth/templates/bt-agent.service.j2
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								roles/bluetooth/templates/bt-agent.service.j2
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,10 @@
 | 
			
		|||
[Unit]
 | 
			
		||||
Description=Bluetooth Auth Agent
 | 
			
		||||
 | 
			
		||||
[Service]
 | 
			
		||||
ExecStart=/usr/bin/bt-agent -c NoInputNoOutput
 | 
			
		||||
Type=simple
 | 
			
		||||
 | 
			
		||||
[Install]
 | 
			
		||||
WantedBy=multi-user.target
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										15
									
								
								roles/bluetooth/templates/bt-pan.service.j2
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								roles/bluetooth/templates/bt-pan.service.j2
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,15 @@
 | 
			
		|||
[Unit]
 | 
			
		||||
Description=Bluetooth NEP PAN
 | 
			
		||||
#After=br0.network
 | 
			
		||||
Before=network.target
 | 
			
		||||
After=network-pre.target
 | 
			
		||||
Requires=network-pre.target
 | 
			
		||||
 | 
			
		||||
[Service]
 | 
			
		||||
ExecStart=/usr/bin/bt-network -s nap br0
 | 
			
		||||
ExecStartPost=/usr/bin/iiab-bt-pan-discoverable-on
 | 
			
		||||
Type=simple
 | 
			
		||||
 | 
			
		||||
[Install]
 | 
			
		||||
WantedBy=multi-user.target
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										12
									
								
								roles/bluetooth/templates/bt-term.service.j2
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								roles/bluetooth/templates/bt-term.service.j2
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,12 @@
 | 
			
		|||
[Unit]
 | 
			
		||||
Description=RFCOMM service
 | 
			
		||||
After=bluetooth.service
 | 
			
		||||
Requires=bluetooth.service
 | 
			
		||||
 | 
			
		||||
[Service]
 | 
			
		||||
ExecStartPre=/usr/bin/sdptool add SP
 | 
			
		||||
ExecStartPre=/bin/hciconfig hci0 piscan
 | 
			
		||||
ExecStart=/usr/bin/rfcomm watch hci0 1 getty rfcomm0 115200 vt100
 | 
			
		||||
 | 
			
		||||
[Install]
 | 
			
		||||
WantedBy=multi-user.target
 | 
			
		||||
							
								
								
									
										5
									
								
								roles/bluetooth/templates/iiab-bt-pan-discoverable-on.j2
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								roles/bluetooth/templates/iiab-bt-pan-discoverable-on.j2
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,5 @@
 | 
			
		|||
#!/bin/bash
 | 
			
		||||
 | 
			
		||||
bluetoothctl <<EOF
 | 
			
		||||
discoverable on
 | 
			
		||||
EOF
 | 
			
		||||
							
								
								
									
										12
									
								
								roles/bluetooth/templates/iiab-bt-pan-off.j2
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								roles/bluetooth/templates/iiab-bt-pan-off.j2
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,12 @@
 | 
			
		|||
#!/bin/bash
 | 
			
		||||
 | 
			
		||||
systemctl disable bt-agent
 | 
			
		||||
# for some reason this service is really slow to stop and can't do anything without bt-pan
 | 
			
		||||
#systemctl stop bt-agent
 | 
			
		||||
 | 
			
		||||
systemctl disable bt-pan
 | 
			
		||||
systemctl stop bt-pan
 | 
			
		||||
 | 
			
		||||
bluetoothctl <<EOF
 | 
			
		||||
discoverable off
 | 
			
		||||
EOF
 | 
			
		||||
							
								
								
									
										11
									
								
								roles/bluetooth/templates/iiab-bt-pan-on.j2
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								roles/bluetooth/templates/iiab-bt-pan-on.j2
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,11 @@
 | 
			
		|||
#!/bin/bash
 | 
			
		||||
 | 
			
		||||
systemctl enable bt-agent
 | 
			
		||||
systemctl start bt-agent
 | 
			
		||||
 | 
			
		||||
systemctl enable bt-pan
 | 
			
		||||
systemctl start bt-pan
 | 
			
		||||
 | 
			
		||||
bluetoothctl <<EOF
 | 
			
		||||
discoverable on
 | 
			
		||||
EOF
 | 
			
		||||
							
								
								
									
										4
									
								
								roles/bluetooth/templates/iiab-bt-term-off.j2
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								roles/bluetooth/templates/iiab-bt-term-off.j2
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,4 @@
 | 
			
		|||
#!/bin/bash
 | 
			
		||||
 | 
			
		||||
systemctl disable bt-term
 | 
			
		||||
systemctl stop bt-term
 | 
			
		||||
							
								
								
									
										4
									
								
								roles/bluetooth/templates/iiab-bt-term-on.j2
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								roles/bluetooth/templates/iiab-bt-term-on.j2
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,4 @@
 | 
			
		|||
#!/bin/bash
 | 
			
		||||
 | 
			
		||||
systemctl enable bt-term
 | 
			
		||||
systemctl start bt-term
 | 
			
		||||
							
								
								
									
										9
									
								
								roles/bluetooth/templates/network.conf.j2
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								roles/bluetooth/templates/network.conf.j2
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,9 @@
 | 
			
		|||
# Configuration file for the network service
 | 
			
		||||
 | 
			
		||||
[General]
 | 
			
		||||
 | 
			
		||||
# Disable link encryption: default=false
 | 
			
		||||
#DisableSecurity=true
 | 
			
		||||
 | 
			
		||||
[NAP Role]
 | 
			
		||||
Interface=br0
 | 
			
		||||
| 
						 | 
				
			
			@ -6,7 +6,7 @@ systemctl stop hostapd
 | 
			
		|||
#systemctl stop dnsmasq
 | 
			
		||||
systemctl daemon-reload
 | 
			
		||||
systemctl restart dhcpcd
 | 
			
		||||
systemctl restart networking
 | 
			
		||||
#systemctl restart networking 6/15/2019 TFM removed
 | 
			
		||||
 | 
			
		||||
# Temporary promiscuous-mode workaround for RPi's WiFi "10SEC disease"
 | 
			
		||||
# Set wlan0 to promiscuous when AP's OFF (for possible WiFi gateway)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,7 +7,7 @@ systemctl enable hostapd
 | 
			
		|||
#systemctl enable dnsmasq
 | 
			
		||||
systemctl daemon-reload
 | 
			
		||||
systemctl restart dhcpcd
 | 
			
		||||
systemctl restart networking
 | 
			
		||||
#systemctl restart networking 6/15/2019 TFM removed
 | 
			
		||||
systemctl start hostapd
 | 
			
		||||
systemctl start dnsmasq
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -88,6 +88,11 @@ reboot_to_AP: False
 | 
			
		|||
# For those installing IIAB over WiFi: "reboot_to_AP: True" overrides the above
 | 
			
		||||
# detection of WiFi-as-gateway, forcing "hostapd_enabled: True" regardless.
 | 
			
		||||
 | 
			
		||||
# Bluetooth PAN access to server
 | 
			
		||||
bluetooth_install: True
 | 
			
		||||
bluetooth_enabled: False
 | 
			
		||||
bluetooth_term_enabled: False
 | 
			
		||||
 | 
			
		||||
# Gateway mode
 | 
			
		||||
iiab_lan_enabled: True
 | 
			
		||||
iiab_wan_enabled: True
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue