author | zautrix <zautrix> | 2004-08-07 17:24:40 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-08-07 17:24:40 (UTC) |
commit | 88b0d33b8b0b1f6ae320cfc863ca6a47fa8fec22 (patch) (unidiff) | |
tree | 6331418973714243beb674abc87692277b83869d /gammu/emb/common/protocol/obex/obex.c | |
parent | ef8a09ce74ad3f0a51484d03fdf009bd5b3677bf (diff) | |
download | kdepimpi-88b0d33b8b0b1f6ae320cfc863ca6a47fa8fec22.zip kdepimpi-88b0d33b8b0b1f6ae320cfc863ca6a47fa8fec22.tar.gz kdepimpi-88b0d33b8b0b1f6ae320cfc863ca6a47fa8fec22.tar.bz2 |
Initial revision
Diffstat (limited to 'gammu/emb/common/protocol/obex/obex.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | gammu/emb/common/protocol/obex/obex.c | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/gammu/emb/common/protocol/obex/obex.c b/gammu/emb/common/protocol/obex/obex.c new file mode 100644 index 0000000..942c084 --- a/dev/null +++ b/gammu/emb/common/protocol/obex/obex.c | |||
@@ -0,0 +1,120 @@ | |||
1 | /* (c) 2003 by Marcin Wiacek */ | ||
2 | /* www.irda.org OBEX specs 1.3 */ | ||
3 | |||
4 | #include "../../gsmstate.h" | ||
5 | |||
6 | #include <stdio.h> | ||
7 | #include <string.h> | ||
8 | |||
9 | #if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) | ||
10 | |||
11 | #include "../../gsmcomon.h" | ||
12 | #include "obex.h" | ||
13 | |||
14 | static GSM_Error OBEX_WriteMessage (GSM_StateMachine *s, unsigned char *buffer, | ||
15 | int length, unsigned char type) | ||
16 | { | ||
17 | unsigned char*out_buffer; | ||
18 | int current=0,sent; | ||
19 | |||
20 | out_buffer = (unsigned char *)malloc(length + 3); | ||
21 | |||
22 | OBEXAddBlock(out_buffer, ¤t, type, buffer, length); | ||
23 | |||
24 | GSM_DumpMessageLevel2(s, out_buffer+3, length, type); | ||
25 | GSM_DumpMessageLevel3(s, out_buffer+3, length, type); | ||
26 | |||
27 | /* Send it out... */ | ||
28 | sent = s->Device.Functions->WriteDevice(s,out_buffer,current); | ||
29 | |||
30 | free(out_buffer); | ||
31 | |||
32 | if (sent!=current) return ERR_DEVICEWRITEERROR; | ||
33 | return ERR_NONE; | ||
34 | } | ||
35 | |||
36 | static GSM_Error OBEX_StateMachine(GSM_StateMachine *s, unsigned char rx_char) | ||
37 | { | ||
38 | GSM_Phone_Functions *Phone= s->Phone.Functions; | ||
39 | GSM_Protocol_OBEXData *d= &s->Protocol.Data.OBEX; | ||
40 | |||
41 | switch (d->MsgRXState) { | ||
42 | case RX_Sync: | ||
43 | d->Msg.Type = rx_char; | ||
44 | d->MsgRXState = RX_GetLength1; | ||
45 | break; | ||
46 | case RX_GetLength1: | ||
47 | d->Msg.Length = rx_char * 256; | ||
48 | d->MsgRXState = RX_GetLength2; | ||
49 | break; | ||
50 | case RX_GetLength2: | ||
51 | d->Msg.Length = d->Msg.Length + rx_char - 3; | ||
52 | d->Msg.Count = 0; | ||
53 | if (d->Msg.Count == d->Msg.Length) { | ||
54 | s->Phone.Data.RequestMsg= &d->Msg; | ||
55 | s->Phone.Data.DispatchError= Phone->DispatchMessage(s); | ||
56 | d->MsgRXState = RX_Sync; | ||
57 | } else { | ||
58 | if (d->Msg.BufferUsed < d->Msg.Length) { | ||
59 | d->Msg.BufferUsed = d->Msg.Length; | ||
60 | d->Msg.Buffer = (unsigned char *)realloc(d->Msg.Buffer,d->Msg.BufferUsed); | ||
61 | } | ||
62 | d->MsgRXState = RX_GetMessage; | ||
63 | } | ||
64 | break; | ||
65 | case RX_GetMessage: | ||
66 | d->Msg.Buffer[d->Msg.Count] = rx_char; | ||
67 | d->Msg.Count++; | ||
68 | if (d->Msg.Count == d->Msg.Length) { | ||
69 | s->Phone.Data.RequestMsg= &d->Msg; | ||
70 | s->Phone.Data.DispatchError= Phone->DispatchMessage(s); | ||
71 | d->MsgRXState = RX_Sync; | ||
72 | } | ||
73 | break; | ||
74 | } | ||
75 | |||
76 | return ERR_NONE; | ||
77 | } | ||
78 | |||
79 | static GSM_Error OBEX_Initialise(GSM_StateMachine *s) | ||
80 | { | ||
81 | GSM_Protocol_OBEXData *d = &s->Protocol.Data.OBEX; | ||
82 | |||
83 | d->Msg.BufferUsed= 0; | ||
84 | d->Msg.Buffer = NULL; | ||
85 | d->Msg.Length = 0; | ||
86 | |||
87 | d->MsgRXState = RX_Sync; | ||
88 | |||
89 | return ERR_NONE; | ||
90 | } | ||
91 | |||
92 | static GSM_Error OBEX_Terminate(GSM_StateMachine *s) | ||
93 | { | ||
94 | free(s->Protocol.Data.OBEX.Msg.Buffer); | ||
95 | return ERR_NONE; | ||
96 | } | ||
97 | |||
98 | GSM_Protocol_Functions OBEXProtocol = { | ||
99 | OBEX_WriteMessage, | ||
100 | OBEX_StateMachine, | ||
101 | OBEX_Initialise, | ||
102 | OBEX_Terminate | ||
103 | }; | ||
104 | |||
105 | #endif | ||
106 | |||
107 | void OBEXAddBlock(char *Buffer, int *Pos, unsigned char ID, char *AddBuffer, int AddLength) | ||
108 | { | ||
109 | Buffer[(*Pos)++] = ID; | ||
110 | Buffer[(*Pos)++] = (AddLength+3)/256; | ||
111 | Buffer[(*Pos)++] = (AddLength+3)%256; | ||
112 | if (AddBuffer != NULL) { | ||
113 | memcpy(Buffer+(*Pos),AddBuffer,AddLength); | ||
114 | (*Pos) += AddLength; | ||
115 | } | ||
116 | } | ||
117 | |||
118 | /* How should editor hadle tabs in this file? Add editor commands here. | ||
119 | * vim: noexpandtab sw=8 ts=8 sts=8: | ||
120 | */ | ||