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