Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/rex/post/hwbridge/extensions/zigbee/zigbee.rb
Views: 11705
#1# -*- coding: binary -*-2require 'rex/post/hwbridge/client'34module Rex5module Post6module HWBridge7module Extensions8module Zigbee910###11# Zigbee extension - set of commands to be executed on zigbee compatible hw bridges12###1314class Zigbee < Extension1516def initialize(client)17super(client, 'zigbee')1819# Alias the following things on the client object so that they20# can be directly referenced21client.register_extension_aliases(22[23{24'name' => 'zigbee',25'ext' => self26}27])28end2930# Sets the default target device31# @param device [String] Target Zigbee device ID32def set_target_device(device)33self.target_device = device34end3536# Retrieves the default zigbee device ID37# @return [String] Zigbee device ID38def get_target_device39self.target_device40end4142# Gets supported Zigbee Devices43# @return [Array] Devices44def supported_devices45client.send_request("/zigbee/supported_devices")46end4748# Sets the channel49# @param dev [String] Device to affect50# @param channel [Integer] Channel number51def set_channel(dev, channel)52client.send_request("/zigbee/#{dev}/set_channel?chan=#{channel}")53end5455# Injects a raw packet56# @param dev [String] Zigbee Device ID57# @param data [String] Raw hex data that will be Base64 encoded58def inject(dev, data)59data = Base64.urlsafe_encode64(data)60client.send_request("/zigbee/#{dev}/inject?data=#{data}")61end6263# Receives data from transceiver64# @param dev [String] Zigbee Device ID65# @return [Hash] { data: HexString, valid_crc: X, rssi: X }66def recv(dev)67data = client.send_request("/zigbee/#{dev}/recv")68if data.size > 069data["data"] = Base64.urlsafe_decode64(data["data"]) if data.has_key? "data"70end71data72end7374# Disables sniffer and puts the device in a state that can be changed (like adujsting channel)75# @param dev [String] Zigbee Device ID76def sniffer_off(dev)77client.send_request("/zigbee/#{dev}/sniffer_off")78end7980# Enables sniffer receive mode. Not necessary to call before calling recv81# @param dev [String] Zigbee Device ID82def sniffer_on(dev)83client.send_request("/zigbee/#{dev}/sniffer_on")84end8586attr_accessor :target_device8788end8990end91end92end93end94end959697