2957abb46d1bcaa3a3431ce23e1cce54a6bf1d3b
[project/umbim.git] / mbim-msg.h
1 /*
2 * umbim
3 * Copyright (C) 2014 John Crispin <blogic@openwrt.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15 #ifndef _MBIM_MSG_H__
16 #define _MBIM_MSG_H__
17
18 #include <string.h>
19
20 struct mbim_message_header {
21 uint32_t type;
22 uint32_t length;
23 uint32_t transaction_id;
24 } __attribute__((packed));
25
26 struct mbim_open_message {
27 struct mbim_message_header header;
28 uint32_t max_control_transfer;
29 } __attribute__((packed));
30
31 struct mbim_open_done_message {
32 struct mbim_message_header header;
33 uint32_t status_code;
34 } __attribute__((packed));
35
36 struct mbim_close_done_message {
37 uint32_t status_code;
38 } __attribute__((packed));
39
40 struct mbim_error_message {
41 uint32_t error_status_code;
42 } __attribute__((packed));
43
44 struct mbim_fragment_header {
45 uint32_t total;
46 uint32_t current;
47 } __attribute__((packed));
48
49 struct fragment_message {
50 struct mbim_fragment_header fragment_header;
51 uint8_t buffer[];
52 } __attribute__((packed));
53
54 struct command_message {
55 struct mbim_message_header header;
56 struct mbim_fragment_header fragment_header;
57 uint8_t service_id[16];
58 uint32_t command_id;
59 uint32_t command_type;
60 uint32_t buffer_length;
61 uint8_t buffer[];
62 } __attribute__((packed));
63
64 struct command_done_message {
65 struct mbim_fragment_header fragment_header;
66 uint8_t service_id[16];
67 uint32_t command_id;
68 uint32_t status_code;
69 uint32_t buffer_length;
70 uint8_t buffer[];
71 } __attribute__((packed));
72
73 struct indicate_status_message {
74 struct mbim_fragment_header fragment_header;
75 uint8_t service_id[16];
76 uint32_t command_id;
77 uint32_t buffer_length;
78 uint8_t buffer[];
79 } __attribute__((packed));
80
81 typedef int (*_mbim_cmd_request)(void);
82 typedef int (*_mbim_cmd_response)(void *buffer, int len);
83
84 extern uint8_t basic_connect[16];
85 extern int transaction_id;
86
87 const char* mbim_enum_string(struct mbim_enum *e, uint32_t key);
88 char* mbim_get_string(struct mbim_string *str, char *in);
89 void mbim_setup_header(struct mbim_message_header *hdr, MbimMessageType type, int length);
90 uint8_t* mbim_setup_command_msg(uint8_t *uuid, uint32_t type, uint32_t command_id, int len);
91 int mbim_send_open_msg(void);
92 int mbim_send_close_msg(void);
93 int mbim_send_command_msg(void);
94 int mbim_add_payload(uint8_t len);
95 int mbim_encode_string(struct mbim_string *str, char *in);
96 void mbim_get_ipv4(void *buffer, char *out, uint32_t offset);
97 void mbim_get_ipv6(void *buffer, char *out, uint32_t offset);
98 uint32_t mbim_get_int(void *buffer, uint32_t offset);
99
100 #endif