1 /* SPDX-License-Identifier: GPL-2.0+ */ 2 /* 3 * userspace interface for pi433 radio module 4 * 5 * Pi433 is a 433MHz radio module for the Raspberry Pi. 6 * It is based on the HopeRf Module RFM69CW. Therefore, inside of this 7 * driver you'll find an abstraction of the rf69 chip. 8 * 9 * If needed this driver could also be extended to support other 10 * devices based on HopeRf rf69 as well as HopeRf modules with a similar 11 * interface such as RFM69HCW, RFM12, RFM95 and so on. 12 * 13 * Copyright (C) 2016 Wolf-Entwicklungen 14 * Marcus Wolf <linux@wolf-entwicklungen.de> 15 */ 16 17 #ifndef PI433_H 18 #define PI433_H 19 20 #include <linux/types.h> 21 #include "rf69_enum.h" 22 23 /*---------------------------------------------------------------------------*/ 24 25 enum option_on_off { 26 OPTION_OFF, 27 OPTION_ON 28 }; 29 30 /* IOCTL structs and commands */ 31 32 /** 33 * struct pi433_tx_cfg 34 * describes the configuration of the radio module for sending data 35 * @frequency: 36 * @bit_rate: 37 * @modulation: 38 * @data_mode: 39 * @preamble_length: 40 * @sync_pattern: 41 * @tx_start_condition: 42 * @payload_length: 43 * @repetitions: 44 * 45 * ATTENTION: 46 * If the contents of 'pi433_tx_cfg' ever change 47 * incompatibly, then the ioctl number (see define below) must change. 48 * 49 * NOTE: struct layout is the same in 64bit and 32bit userspace. 50 */ 51 #define PI433_TX_CFG_IOCTL_NR 0 52 struct pi433_tx_cfg { 53 __u32 frequency; 54 __u16 bit_rate; 55 __u32 dev_frequency; 56 enum modulation modulation; 57 enum mod_shaping mod_shaping; 58 59 enum pa_ramp pa_ramp; 60 61 enum tx_start_condition tx_start_condition; 62 63 __u16 repetitions; 64 65 /* packet format */ 66 enum option_on_off enable_preamble; 67 enum option_on_off enable_sync; 68 enum option_on_off enable_length_byte; 69 enum option_on_off enable_address_byte; 70 enum option_on_off enable_crc; 71 72 __u16 preamble_length; 73 __u8 sync_length; 74 __u8 fixed_message_length; 75 76 __u8 sync_pattern[8]; 77 __u8 address_byte; 78 }; 79 80 /** 81 * struct pi433_rx_cfg 82 * describes the configuration of the radio module for receiving data 83 * @frequency: 84 * @bit_rate: 85 * @modulation: 86 * @data_mode: 87 * @preamble_length: 88 * @sync_pattern: 89 * @tx_start_condition: 90 * @payload_length: 91 * @repetitions: 92 * 93 * ATTENTION: 94 * If the contents of 'pi433_rx_cfg' ever change 95 * incompatibly, then the ioctl number (see define below) must change 96 * 97 * NOTE: struct layout is the same in 64bit and 32bit userspace. 98 */ 99 #define PI433_RX_CFG_IOCTL_NR 1 100 struct pi433_rx_cfg { 101 __u32 frequency; 102 __u16 bit_rate; 103 __u32 dev_frequency; 104 105 enum modulation modulation; 106 107 __u8 rssi_threshold; 108 enum threshold_decrement threshold_decrement; 109 enum antenna_impedance antenna_impedance; 110 enum lna_gain lna_gain; 111 enum mantisse bw_mantisse; /* normal: 0x50 */ 112 __u8 bw_exponent; /* during AFC: 0x8b */ 113 enum dagc dagc; 114 115 /* packet format */ 116 enum option_on_off enable_sync; 117 118 /* should be used in combination with sync, only */ 119 enum option_on_off enable_length_byte; 120 121 /* operational with sync, only */ 122 enum address_filtering enable_address_filtering; 123 124 /* only operational, if sync on and fixed length or length byte is used */ 125 enum option_on_off enable_crc; 126 127 __u8 sync_length; 128 __u8 fixed_message_length; 129 __u32 bytes_to_drop; 130 131 __u8 sync_pattern[8]; 132 __u8 node_address; 133 __u8 broadcast_address; 134 }; 135 136 #define PI433_IOC_MAGIC 'r' 137 138 #define PI433_IOC_RD_TX_CFG \ 139 _IOR(PI433_IOC_MAGIC, PI433_TX_CFG_IOCTL_NR, char[sizeof(struct pi433_tx_cfg)]) 140 #define PI433_IOC_WR_TX_CFG \ 141 _IOW(PI433_IOC_MAGIC, PI433_TX_CFG_IOCTL_NR, char[sizeof(struct pi433_tx_cfg)]) 142 143 #define PI433_IOC_RD_RX_CFG \ 144 _IOR(PI433_IOC_MAGIC, PI433_RX_CFG_IOCTL_NR, char[sizeof(struct pi433_rx_cfg)]) 145 #define PI433_IOC_WR_RX_CFG \ 146 _IOW(PI433_IOC_MAGIC, PI433_RX_CFG_IOCTL_NR, char[sizeof(struct pi433_rx_cfg)]) 147 148 #endif /* PI433_H */ 149