bladox.com Forum Index bladox.com
Turbo SIM Toolkit Adapter Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

turbo problem-provide_nmr()

 
Post new topic   Reply to topic    bladox.com Forum Index -> Development
View previous topic :: View next topic  
Author Message
mike
Guest





PostPosted: Fri Feb 09, 2007 4:12 pm    Post subject: turbo problem-provide_nmr() Reply with quote

I have built an application that displays on terminal monitor some information like imei, cell id, NMRs etc.

the fact is that when the functions provide_imei() or provide_nmr() are called then:
-the first time i call them the result is displayed on the monitor
-the second time i call them the message "wait..." is displayed on the phone and finally the application exits
-only if i restart the terminal i can take a result on my display and only for the first time i call the function

so, i would like to ask:
-is it about a turbo problem?
-is it possible to take subsequent measurements?

thnx in advance,
mike
Back to top
pz
Guest





PostPosted: Mon Feb 12, 2007 9:57 am    Post subject: Re: turbo problem-provide_nmr() Reply with quote

mike wrote:
I have built an application that displays on terminal monitor some information like imei, cell id, NMRs etc.

the fact is that when the functions provide_imei() or provide_nmr() are called then:
-the first time i call them the result is displayed on the monitor
-the second time i call them the message "wait..." is displayed on the phone and finally the application exits


Something is wrong in your code, this is a symptom of application error.
Post your code.

Quote:

-only if i restart the terminal i can take a result on my display and only for the first time i call the function

so, i would like to ask:
-is it about a turbo problem?


No.

Quote:

-is it possible to take subsequent measurements?


Yes, no problem.

Quote:

thnx in advance,
mike
Back to top
mike
Guest





PostPosted: Mon Feb 12, 2007 4:13 pm    Post subject: Reply with quote

my code is the following:

Code:
#include <config.h>
#include <turbo/turbo.h>

#include <stdlib.h>
#include <string.h>

u8 PROGMEM t_menu[] = "MOTIVE";

/* *INDENT-OFF* */

lc_char PROGMEM lc_Text[] = {
  LC_EN ("Monitor")
  LC_END
};

lc_char PROGMEM lc_Text_1[] = {
  LC_EN ("MCC+MNC")
  LC_END
};

lc_char PROGMEM lc_Text_2[] = {
  LC_EN ("LAC")
  LC_END
};

lc_char PROGMEM lc_Text_3[] = {
  LC_EN ("Cell ID")
  LC_END
};

lc_char PROGMEM lc_Text_4[] = {
  LC_EN ("IMEI")
  LC_END
};

lc_char PROGMEM lc_Text_5[] = {
  LC_EN ("NMR")
  LC_END
};

lc_char PROGMEM lc_Text_6[] = {
  LC_EN ("BCCH")
  LC_END
};

lc_char PROGMEM lc_Text_7[] = {
  LC_EN ("DATE")
  LC_END
};

lc_char PROGMEM lc_Text_8[] = {
  LC_EN ("LANGUAGE")
  LC_END
};

lc_char PROGMEM lc_Text_9[] = {
  LC_EN ("TIMING ADVANCE")
  LC_END
};

/* *INDENT-ON* */

u8 PROGMEM nothing[] = "Cannot retrieve it!";


u8 show1 (SCtx * ctx, u8 action)
{

  if (action == APP_ENTER)
  {
  u8 *res;
  u8 *buf=malloc (20);
  u8 *r=buf;
  u8 j=0;
  u8 i, l;
  SNode *n = ctx->n;
  u8 *s = rw (&n->text);

  s = locale (s);
  if (!s)
    return APP_BACK;
  res = provide_local_info ();
  j = get_tag (res, T_LOCATION_INFO);
  if (j != 0)
  {
//MCC+MNC
    r = sprints (r, s);
    r = sprintc (r, ':');
    r = sprintc (r, '\n');
    for (i = 0; i < 3; i++)
      r = sprintch (r, res[j + 2 + i]);
    r = sprintc (r, '\0');
   }
   else
     r = sprints (r, nothing);
   r = sprintc (r, '\0');
   i = display_text (buf, NULL);
   free(buf);
   if (i != APP_END)
     return APP_BACK;
   return i;
  }
  return APP_OK;
}

u8 show2 (SCtx * ctx, u8 action)
{

  if (action == APP_ENTER)
  {
  u8 *res;
  u8 *buf=malloc (20);
  u8 *r=buf;
  u8 j=0;
  u8 i, l;
  SNode *n = ctx->n;
  u8 *s = rw (&n->text);

  s = locale (s);
  if (!s)
    return APP_BACK;
  res = provide_local_info ();
  j = get_tag (res, T_LOCATION_INFO);
  if (j != 0)
  {
//LAC
    r = sprints (r, s);
    r = sprintc (r, ':');
    r = sprintc (r, '\n');
    for (i = 3; i < 5; i++)
      r = sprintch (r, res[j + 2 + i]);
    r = sprintc (r, '\0');
   }
   else
     r = sprints (r, nothing);
   r = sprintc (r, '\0');
   i = display_text (buf, NULL);
   free(buf);
   if (i != APP_END)
     return APP_BACK;
   return i;
  }
  return APP_OK;
}

u8 show3 (SCtx * ctx, u8 action)
{

  if (action == APP_ENTER)
  {
  u8 *res;
  u8 *buf=malloc (20);
  u8 *r=buf;
  u8 j=0;
  u8 i, l;
  SNode *n = ctx->n;
  u8 *s = rw (&n->text);

  s = locale (s);
  if (!s)
    return APP_BACK;
  res = provide_local_info ();
  j = get_tag (res, T_LOCATION_INFO);
  if (j != 0)
  {
//Cell ID
    r = sprints (r, s);
    r = sprintc (r, ':');
    r = sprintc (r, '\n');
    for (i = 5; i < 7; i++)
      r = sprintch (r, res[j + 2 + i]);
    r = sprintc (r, '\0');
   }
   else
     r = sprints (r, nothing);
   r = sprintc (r, '\0');
   i = display_text (buf, NULL);
   free(buf);
   if (i != APP_END)
     return APP_BACK;
   return i;
  }
  return APP_OK;
}

u8 show4 (SCtx * ctx, u8 action)
{

  if (action == APP_ENTER)
  {
  u8 *res;
  u8 *buf=malloc (20);
  u8 *r=buf;
  u8 j=0;
  u8 i, l;
  SNode *n = ctx->n;
  u8 *s = rw (&n->text);

  s = locale (s);
  if (!s)
    return APP_BACK;
  res = provide_imei ();
  j = get_tag (res, T_IMEI);
  if (j != 0)
  {
//IMEI
    r = sprints (r, s);
    r = sprintc (r, ':');
    r = sprintc (r, '\n');
    l = res[j + 1];
    for (i = 0; i < l; i++)
      r = sprintch (r, res[j + 2 + i]);
    r = sprintc (r, '\0');
   }
   else
     r = sprints (r, nothing);
   r = sprintc (r, '\0');
   i = display_text (buf, NULL);
   free(buf);
   if (i != APP_END)
     return APP_BACK;
   return i;
  }
  return APP_OK;
}

u8 show5 (SCtx * ctx, u8 action)
{

  if (action == APP_ENTER)
  {
  u8 *res;
  u8 *buf=malloc (20);
  u8 *r=buf;
  u8 j=0;
  u8 i, l;
  SNode *n = ctx->n;
  u8 *s = rw (&n->text);

  s = locale (s);
  if (!s)
    return APP_BACK;
  res = provide_nmr ();
  j = get_tag (res, T_NMR);
  if (j != 0)
  {
//NMRs
    r = sprints (r, s);
    r = sprintc (r, ':');
    r = sprintc (r, '\n');
    l = res[j + 1];
    for (i = 0; i < l; i++)
      r = sprintch (r, res[j + 2 + i]);
    r = sprintc (r, '\0');
   }
   else
     r = sprints (r, nothing);
   r = sprintc (r, '\0');
   i = display_text (buf, NULL);
   free(buf);
   if (i != APP_END)
     return APP_BACK;
   return i;
  }
  return APP_OK;
}

u8 show6 (SCtx * ctx, u8 action)
{

  if (action == APP_ENTER)
  {
  u8 *res;
  u8 *buf=malloc (20);
  u8 *r=buf;
  u8 j=0;
  u8 i, l;
  SNode *n = ctx->n;
  u8 *s = rw (&n->text);

  s = locale (s);
  if (!s)
    return APP_BACK;
  res = provide_nmr ();
  j = get_tag (res, T_BCCH_CHANNEL_LIST);
  if (j != 0)
  {
//BCCH Channel list
    r = sprints (r, s);
    r = sprintc (r, ':');
    r = sprintc (r, '\n');
    l = res[j + 1];
    for (i = 0; i < l; i++)
      r = sprintch (r, res[j + 2 + i]);
    r = sprintc (r, '\0');
   }
   else
     r = sprints (r, nothing);
   r = sprintc (r, '\0');
   i = display_text (buf, NULL);
   free(buf);
   if (i != APP_END)
     return APP_BACK;
   return i;
  }
  return APP_OK;
}

u8 show7 (SCtx * ctx, u8 action)
{

  if (action == APP_ENTER)
  {
  u8 *res;
  u8 *buf=malloc (20);
  u8 *r=buf;
  u8 j=0;
  u8 i, l;
  SNode *n = ctx->n;
  u8 *s = rw (&n->text);

  s = locale (s);
  if (!s)
    return APP_BACK;
  res = provide_date ();
  j = get_tag (res, T_DATE);
  if (j != 0)
  {
//DATE
    r = sprints (r, s);
    r = sprintc (r, ':');
    r = sprintc (r, '\n');
    l = res[j + 1];
    for (i = 0; i < l; i++)
      r = sprintch (r, res[j + 2 + i]);
    r = sprintc (r, '\0');
   }
   else
     r = sprints (r, nothing);
   r = sprintc (r, '\0');
   i = display_text (buf, NULL);
   free(buf);
   if (i != APP_END)
     return APP_BACK;
   return i;
  }
  return APP_OK;
}

u8 show8 (SCtx * ctx, u8 action)
{

  if (action == APP_ENTER)
  {
  u8 *res;
  u8 *buf=malloc (20);
  u8 *r=buf;
  u8 j=0;
  u8 i, l;
  SNode *n = ctx->n;
  u8 *s = rw (&n->text);

  s = locale (s);
  if (!s)
    return APP_BACK;
  res = provide_language ();
  j = get_tag (res, T_LANGUAGE);
  if (j != 0)
  {
//LANGUAGE
    r = sprints (r, s);
    r = sprintc (r, ':');
    r = sprintc (r, '\n');
    l = res[j + 1];
    for (i = 0; i < l; i++)
      r = sprintch (r, res[j + 2 + i]);
    r = sprintc (r, '\0');
   }
   else
     r = sprints (r, nothing);
   r = sprintc (r, '\0');
   i = display_text (buf, NULL);
   free(buf);
   if (i != APP_END)
     return APP_BACK;
   return i;
  }
  return APP_OK;
}

u8 show9 (SCtx * ctx, u8 action)
{

  if (action == APP_ENTER)
  {
  u8 *res;
  u8 *buf=malloc (20);
  u8 *r=buf;
  u8 j=0;
  u8 i, l;
  SNode *n = ctx->n;
  u8 *s = rw (&n->text);

  s = locale (s);
  if (!s)
    return APP_BACK;
  res = provide_ta ();
  j = get_tag (res, T_TIMING_ADVANCE);
  if (j != 0)
  {
//TIMING ADVANCE
    r = sprints (r, s);
    r = sprintc (r, ':');
    r = sprintc (r, '\n');
    l = res[j + 1];
    for (i = 0; i < l; i++)
      r = sprintch (r, res[j + 2 + i]);
    r = sprintc (r, '\0');
   }
   else
     r = sprints (r, nothing);
   r = sprintc (r, '\0');
   i = display_text (buf, NULL);
   free(buf);
   if (i != APP_END)
     return APP_BACK;
   return i;
  }
  return APP_OK;
}

SNodeP ex_n = { lc_Text, NULL };
SNodeP ex_n_1 = { lc_Text_1, show1 };
SNodeP ex_n_2 = { lc_Text_2, show2 };
SNodeP ex_n_3 = { lc_Text_3, show3 };
SNodeP ex_n_4 = { lc_Text_4, show4 };
SNodeP ex_n_5 = { lc_Text_5, show5 };
SNodeP ex_n_6 = { lc_Text_6, show6 };
SNodeP ex_n_7 = { lc_Text_7, show7 };
SNodeP ex_n_8 = { lc_Text_8, show8 };
SNodeP ex_n_9 = { lc_Text_9, show9 };


/* *INDENT-OFF* */

SEdgeP ex_edges_p[] = {
  {&ex_n, &ex_n_1},
  {&ex_n, &ex_n_2},
  {&ex_n, &ex_n_3},
  {&ex_n, &ex_n_4},
  {&ex_n, &ex_n_5},
  {&ex_n, &ex_n_6},
  {&ex_n, &ex_n_7},
  {&ex_n, &ex_n_8},
  {&ex_n, &ex_n_9},
  NULL
};

/* *INDENT-ON* */

void action_menu (Menu_selection_data * x)
{
  u8 item = x->item;
  SCtx *c;

  c = spider_init ();
  c->eP = &ex_edges_p;
  c->n = &ex_n;
  spider (c);
}

void turbo_handler (u8 action, void *data)
{
  switch (action)
  {
    case ACTION_APP_INIT:
      set_proc_8 (PROC_8_LANGUAGE, LC_ENGLISH);
      break;
    case ACTION_INSERT_MENU:
      insert_menu (t_menu);
      break;
    case ACTION_MENU_SELECTION:
      stk_thread (action_menu, data);
      break;
    default:
      break;
  }
}
Back to top
pz
Guest





PostPosted: Mon Feb 12, 2007 5:21 pm    Post subject: Reply with quote

What about size of buf - 20? You copy some text and the output of privide_(), can't it be bufer overflow? (I bet on this).
I would recommend to have one global buffer malloced in APP_INIT and used by all calls, it is better for memory fragmentation.

Also if(!s) return; leaves the buf malloced, no big deal in this code, not good in general.
Back to top
mike
Guest





PostPosted: Tue Feb 13, 2007 8:45 pm    Post subject: Reply with quote

you were very right!
the problem was buffer overflow!
thanks very much
Back to top
Display posts from previous:   
Post new topic   Reply to topic    bladox.com Forum Index -> Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group