From 49871b37ab0c7ff1bca2709b6d22fa927a98f43e Mon Sep 17 00:00:00 2001 From: Tim Moody Date: Sun, 2 Jun 2019 10:55:15 -0400 Subject: [PATCH] Bluetooth PAN and Terminal servers --- roles/bluetooth/README.rst | 9 ++ roles/bluetooth/defaults/main.yml | 3 + roles/bluetooth/tasks/main.yml | 4 + roles/bluetooth/tasks/rpi_install.yml | 93 +++++++++++++++++++ roles/bluetooth/templates/bt-agent.service.j2 | 10 ++ roles/bluetooth/templates/bt-pan.service.j2 | 11 +++ roles/bluetooth/templates/bt-term.service.j2 | 13 +++ roles/bluetooth/templates/iiab-bt-pan-off.j2 | 7 ++ roles/bluetooth/templates/iiab-bt-pan-on.j2 | 7 ++ roles/bluetooth/templates/iiab-bt-term-off.j2 | 4 + roles/bluetooth/templates/iiab-bt-term-on.j2 | 4 + 11 files changed, 165 insertions(+) create mode 100644 roles/bluetooth/README.rst create mode 100644 roles/bluetooth/defaults/main.yml create mode 100644 roles/bluetooth/tasks/main.yml create mode 100644 roles/bluetooth/tasks/rpi_install.yml create mode 100644 roles/bluetooth/templates/bt-agent.service.j2 create mode 100644 roles/bluetooth/templates/bt-pan.service.j2 create mode 100644 roles/bluetooth/templates/bt-term.service.j2 create mode 100644 roles/bluetooth/templates/iiab-bt-pan-off.j2 create mode 100644 roles/bluetooth/templates/iiab-bt-pan-on.j2 create mode 100644 roles/bluetooth/templates/iiab-bt-term-off.j2 create mode 100644 roles/bluetooth/templates/iiab-bt-term-on.j2 diff --git a/roles/bluetooth/README.rst b/roles/bluetooth/README.rst new file mode 100644 index 000000000..5b4f460a5 --- /dev/null +++ b/roles/bluetooth/README.rst @@ -0,0 +1,9 @@ +================ +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 role is only available for the Raspberry Pi. diff --git a/roles/bluetooth/defaults/main.yml b/roles/bluetooth/defaults/main.yml new file mode 100644 index 000000000..28fa4359c --- /dev/null +++ b/roles/bluetooth/defaults/main.yml @@ -0,0 +1,3 @@ +bluetooth_install: False +bluetooth_enabled: False +bluetooth_term_enabled: False diff --git a/roles/bluetooth/tasks/main.yml b/roles/bluetooth/tasks/main.yml new file mode 100644 index 000000000..48de6a784 --- /dev/null +++ b/roles/bluetooth/tasks/main.yml @@ -0,0 +1,4 @@ +# This is rpi only + +- include_tasks: rpi_bluetooth_install.yml + when: is_rpi | bool diff --git a/roles/bluetooth/tasks/rpi_install.yml b/roles/bluetooth/tasks/rpi_install.yml new file mode 100644 index 000000000..8ebe3881b --- /dev/null +++ b/roles/bluetooth/tasks/rpi_install.yml @@ -0,0 +1,93 @@ +# 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: '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-term-on.j2', dest: '/usr/bin/iiab-bt-term-on' } + - { src: 'iiab-bt-term-off.j2', dest: '/usr/bin/iiab-bt-term-off' } + +# 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 }}" diff --git a/roles/bluetooth/templates/bt-agent.service.j2 b/roles/bluetooth/templates/bt-agent.service.j2 new file mode 100644 index 000000000..ba3537e0b --- /dev/null +++ b/roles/bluetooth/templates/bt-agent.service.j2 @@ -0,0 +1,10 @@ +[Unit] +Description=Bluetooth Auth Agent + +[Service] +ExecStart=/usr/bin/bt-agent -c NoInputNoOutput +Type=simple + +[Install] +WantedBy=multi-user.target + diff --git a/roles/bluetooth/templates/bt-pan.service.j2 b/roles/bluetooth/templates/bt-pan.service.j2 new file mode 100644 index 000000000..56a1a6bdf --- /dev/null +++ b/roles/bluetooth/templates/bt-pan.service.j2 @@ -0,0 +1,11 @@ +[Unit] +Description=Bluetooth NEP PAN +After=br0.network + +[Service] +ExecStart=/usr/bin/bt-network -s nap br0 +Type=simple + +[Install] +WantedBy=multi-user.target + diff --git a/roles/bluetooth/templates/bt-term.service.j2 b/roles/bluetooth/templates/bt-term.service.j2 new file mode 100644 index 000000000..66f9377dc --- /dev/null +++ b/roles/bluetooth/templates/bt-term.service.j2 @@ -0,0 +1,13 @@ +[Unit] +Description=RFCOMM service +After=bluetooth.service +Requires=bluetooth.service + +[Service] +Type=oneshot +ExecStart=/usr/bin/sdptool add SP +ExecStartPost=/bin/hciconfig hci0 piscan +ExecStart=/usr/bin/rfcomm watch hci0 1 getty rfcomm0 115200 vt100 + +[Install] +WantedBy=multi-user.target diff --git a/roles/bluetooth/templates/iiab-bt-pan-off.j2 b/roles/bluetooth/templates/iiab-bt-pan-off.j2 new file mode 100644 index 000000000..155becbd5 --- /dev/null +++ b/roles/bluetooth/templates/iiab-bt-pan-off.j2 @@ -0,0 +1,7 @@ +#!/bin/bash + +systemctl disable bt-agent +systemctl stop bt-agent + +systemctl disable bt-pan +systemctl stop bt-pan diff --git a/roles/bluetooth/templates/iiab-bt-pan-on.j2 b/roles/bluetooth/templates/iiab-bt-pan-on.j2 new file mode 100644 index 000000000..71d644d98 --- /dev/null +++ b/roles/bluetooth/templates/iiab-bt-pan-on.j2 @@ -0,0 +1,7 @@ +#!/bin/bash + +systemctl enable bt-agent +systemctl start bt-agent + +systemctl enable bt-pan +systemctl start bt-pan diff --git a/roles/bluetooth/templates/iiab-bt-term-off.j2 b/roles/bluetooth/templates/iiab-bt-term-off.j2 new file mode 100644 index 000000000..f1664450d --- /dev/null +++ b/roles/bluetooth/templates/iiab-bt-term-off.j2 @@ -0,0 +1,4 @@ +#!/bin/bash + +systemctl disable bt-term +systemctl stop bt-term diff --git a/roles/bluetooth/templates/iiab-bt-term-on.j2 b/roles/bluetooth/templates/iiab-bt-term-on.j2 new file mode 100644 index 000000000..dc13df2ad --- /dev/null +++ b/roles/bluetooth/templates/iiab-bt-term-on.j2 @@ -0,0 +1,4 @@ +#!/bin/bash + +systemctl enable bt-term +systemctl start bt-term