libsyncml  0.5.4
obex_client_samsung.c
1 /*
2  * libsyncml - A syncml protocol implementation
3  * Copyright (C) 2008 Michael Bell <michael.bell@opensync.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  */
20 
21 #include <libsyncml/syncml.h>
22 #include <libsyncml/syncml_internals.h>
23 #include <libsyncml/sml_error_internals.h>
24 #include <libsyncml/sml_transport_internals.h>
25 #include "obex_client_internals.h"
26 
27 SmlBool smlTransportObexVendorSamsungInit(SmlTransportObexClientEnv *env)
28 {
29  smlTrace(TRACE_EXIT, "%s(%p, %s)", __func__, VA_STRING(env->model));
30 
31  /* Samsung uses several different ways of implementing SyncML.
32  * Actually this is only one dialect.
33  * If you need more then add model based detection via env->model.
34  */
35 
36  /* Notice - the information here are taken from
37  *
38  * www.traud.de/gsm/samsung.htm
39  *
40  * Many thanks for this nice work goes to Alexander Traud.
41  */
42  if (
43  // PC Sync 2
44  !g_strcasecmp("SGH-Z500", env->model) ||
45  !g_strcasecmp("SGH-ZM60", env->model) ||
46 
47  // PC Studio 3
48  !g_strcasecmp("SGH-D347", env->model) ||
49  !g_strcasecmp("SGH-D357", env->model) ||
50  !g_strcasecmp("SGH-D520", env->model) ||
51  !g_strcasecmp("SGH-D830", env->model) ||
52  !g_strcasecmp("SGH-D840", env->model) ||
53  !g_strcasecmp("SGH-E770", env->model) ||
54  !g_strcasecmp("SGH-E860", env->model) ||
55  !g_strcasecmp("SGH-E900", env->model) ||
56  !g_strcasecmp("SGH-F480", env->model) ||
57  !g_strcasecmp("SGH-S500i", env->model) ||
58  !g_strcasecmp("SGH-T609", env->model) ||
59  !g_strcasecmp("SGH-X800", env->model) ||
60  !g_strcasecmp("SGH-X810", env->model) ||
61  !g_strcasecmp("SGH-X820", env->model) ||
62  !g_strcasecmp("SGH-Z150", env->model) ||
63  !g_strcasecmp("SGH-Z310", env->model) ||
64  !g_strcasecmp("SGH-Z320i", env->model) ||
65  !g_strcasecmp("SGH-Z400", env->model) ||
66  !g_strcasecmp("SGH-Z510", env->model) ||
67  !g_strcasecmp("SGH-Z540", env->model) ||
68  !g_strcasecmp("SGH-Z560", env->model) ||
69  !g_strcasecmp("SGH-ZV30", env->model)
70  )
71  {
72  smlTrace(TRACE_INTERNAL, "%s: WebSync WiDESYNC III (Gumi, Suwon 3G)", __func__);
73  smlTrace(TRACE_INTERNAL, "%s: %i datastores" , __func__, g_list_length(env->datastores));
74 
75  /* Example: AT+SyncML=4061062063064
76  * 1. byte: number of datastores
77  * 2.+3. byte: 200+number => 206 == TWO-WAY-SYNC-BY-SERVER
78  * 4. byte: database
79  * 1 contacts/addressbook
80  * 2 events/calendar
81  * 3 notes/memos
82  * 4 todos/tasks
83  * repeat with 2.+3.
84  */
85  env->at_command = g_strdup_printf("AT+SyncML=%i", g_list_length(env->datastores));
86  unsigned int i;
87  for(i = 0; i < g_list_length(env->datastores); i++)
88  {
89  char *tmp = g_strjoin("", env->at_command, "06", NULL);
90  SmlTransportObexDatastoreType *type;
91  type = g_list_nth_data(env->datastores, i);
92  switch(*type)
93  {
94  case SML_TRANSPORT_OBEX_DATASTORE_CONTACT:
95  env->at_command = g_strjoin ("", tmp, "1", NULL);
96  break;
97  case SML_TRANSPORT_OBEX_DATASTORE_EVENT:
98  env->at_command = g_strjoin ("", tmp, "2", NULL);
99  break;
100  case SML_TRANSPORT_OBEX_DATASTORE_NOTE:
101  env->at_command = g_strjoin ("", tmp, "3", NULL);
102  break;
103  case SML_TRANSPORT_OBEX_DATASTORE_TODO:
104  env->at_command = g_strjoin ("", tmp, "4", NULL);
105  break;
106  default:
107  smlSafeCFree(&tmp);
108  g_warning("Unkown datastore type %d for Samsung mobiles.",
109  *type);
110  return FALSE;
111  }
112  smlSafeCFree(&tmp);
113  }
114  } else {
115  g_warning("Unknown Samsung mobile device %s - using default AT command.",
116  env->model);
117  return TRUE;
118  }
119  /* add the CR */
120  char *tmp = g_strjoin("", env->at_command, "\r", NULL);
121  smlSafeCFree(&(env->at_command));
122  env->at_command = tmp;
123  tmp = NULL;
124 
125  smlTrace(TRACE_EXIT, "%s - %s", __func__, VA_STRING(env->at_command));
126  return TRUE;
127 }