BOOL net_sms_handle_gprsq(char *caller, char *command, char *arguments)
{
    char *s;

    if (sys_features[FEATURE_CARBITS]&FEATURE_CB_SOUT_SMS) return FALSE;

    net_send_sms_start(caller);

    s = stp_rom(net_scratchpad, "GPRS:");
    s = stp_s(s, "\r\n APN:", par_get(PARAM_GPRSAPN));
    s = stp_s(s, "\r\n User:"******"\r\n Password:"******"\r\n GSM:", car_gsmcops);

    if (!inputs_gsmgprs())
        s = stp_rom(s, "\r\n GPRS: DISABLED");
    else if (net_msg_serverok)
        s = stp_rom(s, "\r\n GPRS: OK\r\n Server: Connected OK");
    else if (net_state == NET_STATE_READY)
        s = stp_rom(s, "\r\n GSM: OK\r\n Server: Not connected");
    else
    {
        s = stp_x(s, "\r\n GSM/GPRS: Not connected (0x", net_state);
        s = stp_rom(s, ")");
    }

    net_puts_ram(net_scratchpad);

    return TRUE;
}
Example #2
0
BOOL net_sms_handle_diag(char *caller, char *command, char *arguments)
{
  char *s;

  if (sys_features[FEATURE_CARBITS] & FEATURE_CB_SOUT_SMS) return FALSE;

  net_send_sms_start(caller);

  s = stp_rom(net_scratchpad, "DIAG:");
  s = stp_i(s, "\n RED Led:", led_code[OVMS_LED_RED]);
  s = stp_i(s, "\n GRN Led:", led_code[OVMS_LED_GRN]);
  s = stp_x(s, "\n NET State:0x", net_state);

  if (car_12vline > 0)
  {
    s = stp_l2f(s, "\n 12V Line:", car_12vline, 1);
    s = stp_l2f(s, " ref=", car_12vline_ref, 1);
  }

#ifndef OVMS_NO_CRASHDEBUG
  /* DEBUG / QA stats: output crash counter and decode last reason:
   */
  s = stp_i(s, "\n Crashes:", debug_crashcnt);
  if (debug_crashreason)
  {
    s = stp_rom(s, "\n ..last:");
    if (debug_crashreason & 0x01)
      s = stp_rom(s, " BOR"); // Brown Out Reset
    if (debug_crashreason & 0x02)
      s = stp_rom(s, " POR"); // Power On Reset
    if (debug_crashreason & 0x04)
      s = stp_rom(s, " PD"); // Power-Down Detection
    if (debug_crashreason & 0x08)
      s = stp_rom(s, " TO"); // Watchdog Timeout
    if (debug_crashreason & 0x10)
      s = stp_rom(s, " RI"); // Reset Instruction
    if (debug_crashreason & 0x20)
      s = stp_rom(s, " STKFUL"); // Stack overflow
    if (debug_crashreason & 0x40)
      s = stp_rom(s, " STKUNF"); // Stack underflow
    s = stp_i(s, " - ", debug_checkpoint);
  }
#endif // OVMS_NO_CRASHDEBUG

  net_puts_ram(net_scratchpad);

  return TRUE;
}
void net_msg_server_welcome(char *msg)
  {
  // The server has sent a welcome (token <space> base64digest)
  char *d,*p,*s;
  int k;
  unsigned char hwv = 1;

  #ifdef OVMS_HW_V2
  hwv = 2;
  #endif

  if( !msg ) return;
  for (d=msg;(*d != 0)&&(*d != ' ');d++) ;
  if (*d != ' ') return;
  *d++ = 0;

  // At this point, <msg> is token, and <x> is base64digest
  // (both null-terminated)

  // Check for token-replay attack
  if (strcmp(token,msg)==0)
    return; // Server is using our token!

  // Validate server token
  p = par_get(PARAM_SERVERPASS);
  hmac_md5(msg, strlen(msg), p, strlen(p), digest);
  base64encode(digest, MD5_SIZE, net_scratchpad);
  if (strcmp(d,net_scratchpad)!=0)
    return; // Invalid server digest

  // Ok, at this point, our token is ok
  strcpy(net_scratchpad,msg);
  strcat(net_scratchpad,token);
  hmac_md5(net_scratchpad,strlen(net_scratchpad),p,strlen(p),digest);

  // Setup, and prime the rx and tx cryptos
  RC4_setup(&rx_crypto1, &rx_crypto2, digest, MD5_SIZE);
  for (k=0;k<1024;k++)
    {
    net_scratchpad[0] = 0;
    RC4_crypt(&rx_crypto1, &rx_crypto2, net_scratchpad, 1);
    }
  RC4_setup(&tx_crypto1, &tx_crypto2, digest, MD5_SIZE);
  for (k=0;k<1024;k++)
    {
    net_scratchpad[0] = 0;
    RC4_crypt(&tx_crypto1, &tx_crypto2, net_scratchpad, 1);
    }

  net_msg_serverok = 1;

  p = par_get(PARAM_PARANOID);
  if (*p == 'P')
    {
    // Paranoid mode initialisation
    if (ptokenmade==0)
      {
      // We need to make the ptoken
      for (k=0;k<TOKEN_SIZE;k++)
        {
        ptoken[k] = cb64[rand()%64];
        }
      ptoken[TOKEN_SIZE] = 0;
      }

    // To be truly paranoid, we must send the paranoid token to the server ;-)
    ptokenmade=0; // Leave it off for the MP-0 ET message
    strcpypgm2ram(net_scratchpad,(char const rom far*)"MP-0 ET");
    strcat(net_scratchpad,ptoken);
    net_msg_start();
    net_msg_encode_puts();
    net_msg_send();
    ptokenmade=1; // And enable paranoid mode from now on...

    // And calculate the pdigest for future use
    p = par_get(PARAM_MODULEPASS);
    hmac_md5(ptoken, strlen(ptoken), p, strlen(p), pdigest);
    }
  else
    {
    ptokenmade = 0; // This disables paranoid mode
  }


  /* DEBUG / QA stats: Send crash counter and last reason:
   *
   * MP-0 H*-OVM-DebugCrash,0,2592000
   *  ,<firmware_version>/<vehicle_type><vehicle_version>/V<hardware_version>
   *  ,<crashcnt>,<crashreason>,<checkpoint>
   */

  if (debug_crashreason & 0x80)
    {
    debug_crashreason &= ~0x80; // clear checkpoint hold bit

    s = stp_i(net_scratchpad, "MP-0 H*-OVM-DebugCrash,0,2592000,", ovms_firmware[0]);
    s = stp_i(s, ".", ovms_firmware[1]);
    s = stp_i(s, ".", ovms_firmware[2]);
    s = stp_s(s, "/", par_get(PARAM_VEHICLETYPE));
    if (vehicle_version)
       s = stp_rom(s, vehicle_version);
    s = stp_i(s, "/V", hwv);
    s = stp_i(s, ",", debug_crashcnt);
    s = stp_x(s, ",", debug_crashreason);
    s = stp_i(s, ",", debug_checkpoint);

    delay100(20);
    net_msg_start();
    net_msg_encode_puts();
    net_msg_send();
    }
#ifdef OVMS_LOGGINGMODULE
  logging_serverconnect();
#endif // #ifdef OVMS_LOGGINGMODULE
}