comparison g23m/condat/ms/src/aci/ati_bas.c @ 19:340f85ab71c1

AT+CGxx: remove leo2moko hacks
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 23 Sep 2016 06:16:09 +0000
parents 509db1a7b7b8
children a1d085f6d7e9
comparison
equal deleted inserted replaced
18:4346e5e95d3c 19:340f85ab71c1
2174 +--------------------------------------------------------------------+ 2174 +--------------------------------------------------------------------+
2175 | PROJECT : GSM-F&D (8411) MODULE : ACI_CMD | 2175 | PROJECT : GSM-F&D (8411) MODULE : ACI_CMD |
2176 | STATE : code ROUTINE : aciPrcsPlusCG | 2176 | STATE : code ROUTINE : aciPrcsPlusCG |
2177 +--------------------------------------------------------------------+ 2177 +--------------------------------------------------------------------+
2178 2178
2179 Conditioned-out below is TI's original version of the function 2179 PURPOSE :
2180 responsible for generating responses to +CGMI, +CGMM, +CGMR and +CGSN 2180 */
2181 commands. As you can see, it is very simple and straightforward.
2182 But see the comments afterward for why the FreeCalypso firmware has
2183 to use a not-very-clean hacked version instead.
2184 */
2185
2186 #if 0
2187 LOCAL T_ATI_RSLT aciPrcsPlusCG (UBYTE srcId, CHAR* cl, CHAR* ef) 2181 LOCAL T_ATI_RSLT aciPrcsPlusCG (UBYTE srcId, CHAR* cl, CHAR* ef)
2188 { 2182 {
2189 pcm_FileInfo_Type fileInfo; 2183 pcm_FileInfo_Type fileInfo;
2190 USHORT i; 2184 USHORT i;
2191 2185
2195 { 2189 {
2196 cmdCmeError (CME_ERR_MemFail); 2190 cmdCmeError (CME_ERR_MemFail);
2197 return ATI_FAIL; 2191 return ATI_FAIL;
2198 } 2192 }
2199 2193
2200
2201 if (pcm_ReadFile ((UBYTE*)ef, fileInfo.FileSize, 2194 if (pcm_ReadFile ((UBYTE*)ef, fileInfo.FileSize,
2202 (UBYTE*)g_sa, &fileInfo.Version) NEQ DRV_OK) 2195 (UBYTE*)g_sa, &fileInfo.Version) NEQ DRV_OK)
2203 { 2196 {
2204 cmdCmeError (CME_ERR_MemFail); 2197 cmdCmeError (CME_ERR_MemFail);
2205 return ATI_FAIL; 2198 return ATI_FAIL;
2206 } 2199 }
2207 2200
2208 i = 0; 2201 i = 0;
2209 while ((UBYTE)g_sa[i] NEQ 0xFF) 2202 while ((UBYTE)g_sa[i] NEQ 0xFF AND i < fileInfo.FileSize)
2210 {
2211 i++; 2203 i++;
2212 }
2213 g_sa[i] = '\0'; 2204 g_sa[i] = '\0';
2214 io_sendMessage (srcId, g_sa, ATI_NORMAL_OUTPUT ); 2205
2215
2216 return ATI_CMPL;
2217 }
2218 #endif
2219
2220 /*
2221 As you can see in the conditioned-out code above, TI's original
2222 implementation of +CGMI/+CGMM/+CGMR/+CGSN simply spits out whatever
2223 gets read out of PCM/FFS. But if one runs that original TI code
2224 on the Openmoko GSM modem, there are some undesirable effects:
2225
2226 * The strings stored in FFS in /pcm/CGM[IMR] (written there at the
2227 factory along with the IMEI and the RF calibration data, I presume)
2228 are just plain text, e.g., "FIC/OpenMoko" (w/o quotes) in /pcm/CGMI
2229 and "Neo1973 GTA02" (ditto) in /pcm/CGMM. The PCM code trustingly
2230 reads them out of FFS and into the in-RAM PCM table. But if you
2231 look at the PCM compiled-in defaults in
2232 ../../../../../chipsetsw/drivers/drv_app/ffs/board/pcmdata.c,
2233 it appears that at some point they were intended to be enclosed
2234 in angle brackets. The experiments I (Space Falcon) did suggest
2235 that the ATI layer is perfectly happy to emit these PlusCG responses
2236 either in the angle-bracketed form, or in the form used by Om's
2237 firmware, e.g., +CGMM: "Neo1973 whatever embedded modem".
2238 But if PCM contains an unencapsulated string like "Neo1973 GTA02"
2239 (read from FFS) and that string gets emitted raw, the ATI layer
2240 gets confused somewhere.
2241
2242 * TI's ATI layer is not the only code that needs to be kept happy.
2243 The code that talks AT commands to our modem (fsogsmd or whatever)
2244 probably expects the +CGMI/+CGMM/+CGMR/+CGSN responses to be
2245 formatted (encapsulated) in the form in which Om's firmware emits
2246 them, hence I reason we should do our best to reproduce that format.
2247 My version below implements +CGMI and +CGMM by reading the string
2248 value out of PCM (FFS in practice) and encapsulating it in the
2249 Om-like manner before handing it to the ATI layer for output.
2250
2251 * For +CGMR I return a compiled-in string identifying this FreeCalypso
2252 firmware. I see no point in reading anything out of FFS or PCM
2253 at all in this case, as the objective of the +CGMR query is to
2254 identify the firmware version in use, rather than factory FFS
2255 programming.
2256
2257 * With TI's vanilla code, the +CGSN query is logically independent of
2258 the IMEI seen by the GSM stack: it fetches the CGSN record (not the
2259 IMEI one) from PCM, and that record would have to be populated from
2260 a /pcm/CGSN file in FFS, if there was one - but Om's GTA0x modems
2261 have no such file in their FFS from the factory. If one runs TI's
2262 vanilla code, one would get this dummy output: <serial number>,
2263 coming from the compiled-in PCM default table. Om's firmware
2264 responds with "+CGSN: 123456789012345" (IMEI digits, no quotes)
2265 instead. My implementation below replicates Om's functionality.
2266
2267 So without further commentary, here is my hacked version of
2268 the aciPrcsPlusCG() function:
2269 */
2270
2271 LOCAL T_ATI_RSLT aciPrcsPlusCG (UBYTE srcId, CHAR* cl, CHAR* ef_req)
2272 {
2273 CHAR* ef_read;
2274 pcm_FileInfo_Type fileInfo;
2275 int c, i, j, is_imei;
2276 char buf[32];
2277
2278 TRACE_FUNCTION("aciPrcsPlusCG()");
2279
2280 if (!strcmp(ef_req, EF_CGMR_ID)) {
2281 sprintf(g_sa, "+%s: \"FreeCalypso leo2moko port\"", ef_req);
2282 io_sendMessage (srcId, g_sa, ATI_NORMAL_OUTPUT );
2283 return ATI_CMPL;
2284 } else if (!strcmp(ef_req, EF_CGSN_ID)) {
2285 ef_read = EF_IMEI_ID;
2286 is_imei = 1;
2287 } else {
2288 ef_read = ef_req;
2289 is_imei = 0;
2290 }
2291
2292 if (pcm_GetFileInfo ((UBYTE* )ef_read, &fileInfo) NEQ DRV_OK)
2293 {
2294 cmdCmeError (CME_ERR_MemFail);
2295 return ATI_FAIL;
2296 }
2297
2298 if (is_imei) {
2299
2300 for (i = 0, j = 0; i < fileInfo.FileSize; i++) {
2301 buf[j++] = (fileInfo.FileLocation[i] & 0x0F) + '0';
2302 buf[j++] = (fileInfo.FileLocation[i] >> 4) + '0';
2303 }
2304 buf[j-1] = '\0';
2305
2306 } else {
2307
2308 buf[0] = '\"';
2309 for (i = 0, j = 1; i < fileInfo.FileSize; i++) {
2310 c = fileInfo.FileLocation[i];
2311 if (c == 0 || c == 0xFF)
2312 break;
2313 buf[j++] = c;
2314 }
2315 buf[j++] = '\"';
2316 buf[j] = '\0';
2317
2318 }
2319
2320 sprintf(g_sa, "+%s: %s", ef_req, buf);
2321 io_sendMessage (srcId, g_sa, ATI_NORMAL_OUTPUT ); 2206 io_sendMessage (srcId, g_sa, ATI_NORMAL_OUTPUT );
2322 2207
2323 return ATI_CMPL; 2208 return ATI_CMPL;
2324 } 2209 }
2325 2210