Skip to content
Snippets Groups Projects
Commit f2b03689 authored by David Maul's avatar David Maul :crab:
Browse files

change mesaurement_data_type_t discriminator to uint8_t

parent 60a86118
No related branches found
No related tags found
No related merge requests found
...@@ -38,7 +38,7 @@ enum measurement_data_type { ...@@ -38,7 +38,7 @@ enum measurement_data_type {
* typedef message_data_type_t - Alias for uint32_t representing the measurement * typedef message_data_type_t - Alias for uint32_t representing the measurement
* data type. * data type.
*/ */
typedef uint32_t measurement_data_type_t; typedef uint8_t measurement_data_type_t;
/** /**
* typedef measurement_data_t - Union to hold different types of measurement * typedef measurement_data_t - Union to hold different types of measurement
......
...@@ -72,7 +72,7 @@ static void prepare_for_sending(void) { ...@@ -72,7 +72,7 @@ static void prepare_for_sending(void) {
uint8_t *bytes = (uint8_t *)packet->data.measurements; uint8_t *bytes = (uint8_t *)packet->data.measurements;
for (size_t i = 0; i < sizeof(measurement_t) * packet->data.count; i++) { for (size_t i = 0; i < sizeof(measurement_t) * packet->data.count; i++) {
send_buffer[bytes[3 + i]] = bytes[i]; send_buffer[3 + i] = bytes[i];
} }
bytes = (uint8_t *)&packet->crc; bytes = (uint8_t *)&packet->crc;
...@@ -87,37 +87,29 @@ static void prepare_for_sending(void) { ...@@ -87,37 +87,29 @@ static void prepare_for_sending(void) {
static ssize_t device_write(struct file *filp, const char *input, size_t length, static ssize_t device_write(struct file *filp, const char *input, size_t length,
loff_t *offset) { loff_t *offset) {
if (length != sizeof(data_t)) { data_t temp_data;
printk(KERN_ALERT "lkm: Tried to write more bytes than allowed\n");
if (copy_from_user(&temp_data, input, sizeof(data_t))) {
return -EFAULT; return -EFAULT;
} }
if (((data_t *)input)->count >= MAX_MEASUREMENTS) { if (temp_data.count >= MAX_MEASUREMENTS) {
printk(KERN_ALERT "lkm: Tried to write more measurements than allowed\n"); printk(KERN_ALERT "lkm: Tried to write more measurements than allowed\n");
return -EFAULT; return -EFAULT;
} }
if (copy_from_user((void *)&(packet->data.sender_id), packet->data.sender_id = temp_data.sender_id;
(void *)&(((data_t *)input)->sender_id), packet->data.count = temp_data.count;
sizeof(uint8_t))) {
return -EFAULT;
}
if (copy_from_user((void *)&(packet->data.count), if (temp_data.measurements != NULL) {
(void *)&(((data_t *)input)->count), sizeof(uint8_t))) { if (copy_from_user(packet->data.measurements, temp_data.measurements,
sizeof(measurement_t) * temp_data.count)) {
return -EFAULT; return -EFAULT;
} }
if (copy_from_user((void *)packet->data.measurements,
(void *)((data_t *)input)->measurements,
sizeof(measurement_t) * packet->data.count)) {
return -EFAULT;
} }
prepare_for_sending(); prepare_for_sending();
printk(KERN_INFO "lkm: received write of size %zu\n", length);
return length; return length;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment