GNU Linux-libre 4.19.245-gnu1
[releases.git] / drivers / staging / pi433 / pi433_if.h
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 be extended, to also support other
12  * devices, basing on HopeRfs rf69.
13  *
14  * The driver can also be extended, to support other modules of
15  * HopeRf with a similar interace - e. g. RFM69HCW, RFM12, RFM95, ...
16  * Copyright (C) 2016 Wolf-Entwicklungen
17  *      Marcus Wolf <linux@wolf-entwicklungen.de>
18  *
19  * This program is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 2 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27  * GNU General Public License for more details.
28  */
29
30 #ifndef PI433_H
31 #define PI433_H
32
33 #include <linux/types.h>
34 #include "rf69_enum.h"
35
36 /*---------------------------------------------------------------------------*/
37
38 enum option_on_off {
39         OPTION_OFF,
40         OPTION_ON
41 };
42
43 /* IOCTL structs and commands */
44
45 /**
46  * struct pi433_tx_config
47  * describes the configuration of the radio module for sending
48  * @frequency:
49  * @bit_rate:
50  * @modulation:
51  * @data_mode:
52  * @preamble_length:
53  * @sync_pattern:
54  * @tx_start_condition:
55  * @payload_length:
56  * @repetitions:
57  *
58  * ATTENTION:
59  * If the contents of 'pi433_tx_config' ever change
60  * incompatibly, then the ioctl number (see define below) must change.
61  *
62  * NOTE: struct layout is the same in 64bit and 32bit userspace.
63  */
64 #define PI433_TX_CFG_IOCTL_NR   0
65 struct pi433_tx_cfg {
66         __u32                   frequency;
67         __u16                   bit_rate;
68         __u32                   dev_frequency;
69         enum modulation         modulation;
70         enum mod_shaping        mod_shaping;
71
72         enum pa_ramp            pa_ramp;
73
74         enum tx_start_condition tx_start_condition;
75
76         __u16                   repetitions;
77
78         /* packet format */
79         enum option_on_off      enable_preamble;
80         enum option_on_off      enable_sync;
81         enum option_on_off      enable_length_byte;
82         enum option_on_off      enable_address_byte;
83         enum option_on_off      enable_crc;
84
85         __u16                   preamble_length;
86         __u8                    sync_length;
87         __u8                    fixed_message_length;
88
89         __u8                    sync_pattern[8];
90         __u8                    address_byte;
91 };
92
93 /**
94  * struct pi433_rx_config
95  * describes the configuration of the radio module for sending
96  * @frequency:
97  * @bit_rate:
98  * @modulation:
99  * @data_mode:
100  * @preamble_length:
101  * @sync_pattern:
102  * @tx_start_condition:
103  * @payload_length:
104  * @repetitions:
105  *
106  * ATTENTION:
107  * If the contents of 'pi433_rx_config' ever change
108  * incompatibly, then the ioctl number (see define below) must change
109  *
110  * NOTE: struct layout is the same in 64bit and 32bit userspace.
111  */
112 #define PI433_RX_CFG_IOCTL_NR   1
113 struct pi433_rx_cfg {
114         __u32                   frequency;
115         __u16                   bit_rate;
116         __u32                   dev_frequency;
117
118         enum modulation         modulation;
119
120         __u8                    rssi_threshold;
121         enum threshold_decrement threshold_decrement;
122         enum antenna_impedance  antenna_impedance;
123         enum lna_gain           lna_gain;
124         enum mantisse           bw_mantisse;    /* normal: 0x50 */
125         __u8                    bw_exponent;    /* during AFC: 0x8b */
126         enum dagc               dagc;
127
128         /* packet format */
129         enum option_on_off      enable_sync;
130         enum option_on_off      enable_length_byte;       /* should be used in combination with sync, only */
131         enum address_filtering  enable_address_filtering; /* operational with sync, only */
132         enum option_on_off      enable_crc;               /* only operational, if sync on and fixed length or length byte is used */
133
134         __u8                    sync_length;
135         __u8                    fixed_message_length;
136         __u32                   bytes_to_drop;
137
138         __u8                    sync_pattern[8];
139         __u8                    node_address;
140         __u8                    broadcast_address;
141 };
142
143 #define PI433_IOC_MAGIC                 'r'
144
145 #define PI433_IOC_RD_TX_CFG     _IOR(PI433_IOC_MAGIC, PI433_TX_CFG_IOCTL_NR, char[sizeof(struct pi433_tx_cfg)])
146 #define PI433_IOC_WR_TX_CFG     _IOW(PI433_IOC_MAGIC, PI433_TX_CFG_IOCTL_NR, char[sizeof(struct pi433_tx_cfg)])
147
148 #define PI433_IOC_RD_RX_CFG     _IOR(PI433_IOC_MAGIC, PI433_RX_CFG_IOCTL_NR, char[sizeof(struct pi433_rx_cfg)])
149 #define PI433_IOC_WR_RX_CFG     _IOW(PI433_IOC_MAGIC, PI433_RX_CFG_IOCTL_NR, char[sizeof(struct pi433_rx_cfg)])
150
151 #endif /* PI433_H */