⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 message.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 5 页
字号:
      || (msg->header.command == (_DISCONNECT_I|RESPONSE)))     && ((ncci == 0)      || (msg->header.command == (_DISCONNECT_B3_I|RESPONSE))      || ((ncci < MAX_NCCI+1) && (a->ncci_plci[ncci] == plci->Id))))    {      i = plci->msg_in_read_pos;      j = plci->msg_in_write_pos;      if (j >= i)      {        if (j + msg->header.length + MSG_IN_OVERHEAD <= MSG_IN_QUEUE_SIZE)          i += MSG_IN_QUEUE_SIZE - j;        else          j = 0;      }      else      {        n = (((CAPI_MSG   *)(plci->msg_in_queue))->header.length + MSG_IN_OVERHEAD + 3) & 0xfffc;        if (i > MSG_IN_QUEUE_SIZE - n)          i = MSG_IN_QUEUE_SIZE - n + 1;        i -= j;      }      if (i <= ((msg->header.length + MSG_IN_OVERHEAD + 3) & 0xfffc))      {        dbug(0,dprintf("Q-FULL1(msg) - len=%d write=%d read=%d wrap=%d free=%d",          msg->header.length, plci->msg_in_write_pos,          plci->msg_in_read_pos, plci->msg_in_wrap_pos, i));        return _QUEUE_FULL;      }      c = FALSE;      if ((((byte   *) msg) < ((byte   *)(plci->msg_in_queue)))       || (((byte   *) msg) >= ((byte   *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))      {        if (plci->msg_in_write_pos != plci->msg_in_read_pos)          c = TRUE;      }      if (msg->header.command == _DATA_B3_R)      {        if (msg->header.length < 20)        {          dbug(1,dprintf("DATA_B3 REQ wrong length %d", msg->header.length));          return _BAD_MSG;        }        ncci_ptr = &(a->ncci[ncci]);        n = ncci_ptr->data_pending;        l = ncci_ptr->data_ack_pending;        k = plci->msg_in_read_pos;        while (k != plci->msg_in_write_pos)        {          if (k == plci->msg_in_wrap_pos)            k = 0;          if ((((CAPI_MSG   *)(&((byte   *)(plci->msg_in_queue))[k]))->header.command == _DATA_B3_R)           && (((CAPI_MSG   *)(&((byte   *)(plci->msg_in_queue))[k]))->header.ncci == ncci))          {            n++;            if (((CAPI_MSG   *)(&((byte   *)(plci->msg_in_queue))[k]))->info.data_b3_req.Flags & 0x0004)              l++;          }          k += (((CAPI_MSG   *)(&((byte   *)(plci->msg_in_queue))[k]))->header.length +            MSG_IN_OVERHEAD + 3) & 0xfffc;        }        if ((n >= MAX_DATA_B3) || (l >= MAX_DATA_ACK))        {          dbug(0,dprintf("Q-FULL2(data) - pending=%d/%d ack_pending=%d/%d",                          ncci_ptr->data_pending, n, ncci_ptr->data_ack_pending, l));          return _QUEUE_FULL;        }        if (plci->req_in || plci->internal_command)        {          if ((((byte   *) msg) >= ((byte   *)(plci->msg_in_queue)))           && (((byte   *) msg) < ((byte   *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))          {            dbug(0,dprintf("Q-FULL3(requeue)"));            return _QUEUE_FULL;          }          c = TRUE;        }      }      else      {        if (plci->req_in || plci->internal_command)          c = TRUE;        else        {          plci->command = msg->header.command;          plci->number = msg->header.number;        }      }      if (c)      {        dbug(1,dprintf("enqueue msg(0x%04x,0x%x,0x%x) - len=%d write=%d read=%d wrap=%d free=%d",          msg->header.command, plci->req_in, plci->internal_command,          msg->header.length, plci->msg_in_write_pos,          plci->msg_in_read_pos, plci->msg_in_wrap_pos, i));        if (j == 0)          plci->msg_in_wrap_pos = plci->msg_in_write_pos;        m = (CAPI_MSG   *)(&((byte   *)(plci->msg_in_queue))[j]);        for (i = 0; i < msg->header.length; i++)          ((byte   *)(plci->msg_in_queue))[j++] = ((byte   *) msg)[i];        if (m->header.command == _DATA_B3_R)        {          m->info.data_b3_req.Data = (dword)(TransmitBufferSet (appl, m->info.data_b3_req.Data));        }        j = (j + 3) & 0xfffc;        *((APPL   *   *)(&((byte   *)(plci->msg_in_queue))[j])) = appl;        plci->msg_in_write_pos = j + MSG_IN_OVERHEAD;        return 0;      }    }    else    {      plci = NULL;    }  }  dbug(1,dprintf("com=%x",msg->header.command));  for(j=0;j<MAX_MSG_PARMS+1;j++) msg_parms[j].length = 0;  for(i=0, ret = _BAD_MSG;      i<(sizeof(ftable)/sizeof(struct _ftable));      i++) {    if(ftable[i].command==msg->header.command) {      /* break loop if the message is correct, otherwise continue scan  */      /* (for example: CONNECT_B3_T90_ACT_RES has two specifications)   */      if(!api_parse(msg->info.b,(word)(msg->header.length-12),ftable[i].format,msg_parms)) {        ret = 0;        break;      }      for(j=0;j<MAX_MSG_PARMS+1;j++) msg_parms[j].length = 0;    }  }  if(ret) {    dbug(1,dprintf("BAD_MSG"));    if(plci) plci->command = 0;    return ret;  }  c = ftable[i].function(GET_DWORD(&msg->header.controller),                         msg->header.number,                         a,                         plci,                         appl,                         msg_parms);  channel_xmit_extended_xon (plci);  if(c==1) send_req(plci);  if(c==2 && plci) plci->req_in = plci->req_in_start = plci->req_out = 0;  if(plci && !plci->req_in) plci->command = 0;  return 0;}/*------------------------------------------------------------------*//* api_parse function, check the format of api messages             *//*------------------------------------------------------------------*/word api_parse(byte   * msg, word length, byte * format, API_PARSE * parms){  word i;  word p;  for(i=0,p=0; format[i]; i++) {    if(parms)    {      parms[i].info = &msg[p];    }    switch(format[i]) {    case 'b':      p +=1;      break;    case 'w':      p +=2;      break;    case 'd':      p +=4;      break;    case 's':      if(msg[p]==0xff) {        parms[i].info +=2;        parms[i].length = msg[p+1] + (msg[p+2]<<8);        p +=(parms[i].length +3);      }      else {        parms[i].length = msg[p];        p +=(parms[i].length +1);      }      break;    }    if(p>length) return TRUE;  }  if(parms) parms[i].info = NULL;  return FALSE;}void api_save_msg(API_PARSE   *in, byte *format, API_SAVE   *out){  word i, j, n = 0;  byte   *p;  p = out->info;  for (i = 0; format[i] != '\0'; i++)  {    out->parms[i].info = p;    out->parms[i].length = in[i].length;    switch (format[i])    {    case 'b':      n = 1;      break;    case 'w':      n = 2;      break;    case 'd':      n = 4;      break;    case 's':      n = in[i].length + 1;      break;    }    for (j = 0; j < n; j++)      *(p++) = in[i].info[j];  }  out->parms[i].info = NULL;  out->parms[i].length = 0;}void api_load_msg(API_SAVE   *in, API_PARSE   *out){  word i;  i = 0;  do  {    out[i].info = in->parms[i].info;    out[i].length = in->parms[i].length;  } while (in->parms[i++].info);}/*------------------------------------------------------------------*//* CAPI remove function                                             *//*------------------------------------------------------------------*/word api_remove_start(void){  word i;  word j;  if(!remove_started) {    remove_started = TRUE;    for(i=0;i<max_adapter;i++) {      if(adapter[i].request) {        for(j=0;j<adapter[i].max_plci;j++) {          if(adapter[i].plci[j].Sig.Id) plci_remove(&adapter[i].plci[j]);        }      }    }    return 1;  }  else {    for(i=0;i<max_adapter;i++) {      if(adapter[i].request) {        for(j=0;j<adapter[i].max_plci;j++) {          if(adapter[i].plci[j].Sig.Id) return 1;        }      }    }  }  api_remove_complete();  return 0;}/*------------------------------------------------------------------*//* internal command queue                                           *//*------------------------------------------------------------------*/static void init_internal_command_queue (PLCI   *plci){  word i;  dbug (1, dprintf ("%s,%d: init_internal_command_queue",    (char   *)(FILE_), __LINE__));  plci->internal_command = 0;  for (i = 0; i < MAX_INTERNAL_COMMAND_LEVELS; i++)    plci->internal_command_queue[i] = NULL;}static void start_internal_command (dword Id, PLCI   *plci, t_std_internal_command command_function){  word i;  dbug (1, dprintf ("[%06lx] %s,%d: start_internal_command",    UnMapId (Id), (char   *)(FILE_), __LINE__));  if (plci->internal_command == 0)  {    plci->internal_command_queue[0] = command_function;    (* command_function)(Id, plci, OK);  }  else  {    i = 1;    while (plci->internal_command_queue[i] != 0)      i++;    plci->internal_command_queue[i] = command_function;  }}static void next_internal_command (dword Id, PLCI   *plci){  word i;  dbug (1, dprintf ("[%06lx] %s,%d: next_internal_command",    UnMapId (Id), (char   *)(FILE_), __LINE__));  plci->internal_command = 0;  plci->internal_command_queue[0] = NULL;  while (plci->internal_command_queue[1] != 0)  {    for (i = 0; i < MAX_INTERNAL_COMMAND_LEVELS - 1; i++)      plci->internal_command_queue[i] = plci->internal_command_queue[i+1];    plci->internal_command_queue[MAX_INTERNAL_COMMAND_LEVELS - 1] = NULL;    (*(plci->internal_command_queue[0]))(Id, plci, OK);    if (plci->internal_command != 0)      return;    plci->internal_command_queue[0] = NULL;  }}/*------------------------------------------------------------------*//* NCCI allocate/remove function                                    *//*------------------------------------------------------------------*/static dword ncci_mapping_bug = 0;static word get_ncci (PLCI   *plci, byte ch, word force_ncci){  DIVA_CAPI_ADAPTER   *a;  word ncci, i, j, k;  a = plci->adapter;  if (!ch || a->ch_ncci[ch])  {    ncci_mapping_bug++;    dbug(1,dprintf("NCCI mapping exists %ld %02x %02x %02x-%02x",      ncci_mapping_bug, ch, force_ncci, a->ncci_ch[a->ch_ncci[ch]], a->ch_ncci[ch]));    ncci = ch;  }  else  {    if (force_ncci)      ncci = force_ncci;    else    {      if ((ch < MAX_NCCI+1) && !a->ncci_ch[ch])        ncci = ch;      else      {        ncci = 1;        while ((ncci < MAX_NCCI+1) && a->ncci_ch[ncci])          ncci++;        if (ncci == MAX_NCCI+1)        {          ncci_mapping_bug++;          i = 1;          do          {            j = 1;            while ((j < MAX_NCCI+1) && (a->ncci_ch[j] != i))              j++;            k = j;            if (j < MAX_NCCI+1)            {              do              {                j++;              } while ((j < MAX_NCCI+1) && (a->ncci_ch[j] != i));            }          } while ((i < MAX_NL_CHANNEL+1) && (j < MAX_NCCI+1));          if (i < MAX_NL_CHANNEL+1)          {            dbug(1,dprintf("NCCI mapping overflow %ld %02x %02x %02x-%02x-%02x",              ncci_mapping_bug, ch, force_ncci, i, k, j));          }          else          {            dbug(1,dprintf("NCCI mapping overflow %ld %02x %02x",              ncci_mapping_bug, ch, force_ncci));          }          ncci = ch;        }      }      a->ncci_plci[ncci] = plci->Id;      a->ncci_state[ncci] = IDLE;      if (!plci->ncci_ring_list)        plci->ncci_ring_list = ncci;      else        a->ncci_next[ncci] = a->ncci_next[plci->ncci_ring_list];      a->ncci_next[plci->ncci_ring_list] = (byte) ncci;    }    a->ncci_ch[ncci] = ch;    a->ch_ncci[ch] = (byte) ncci;    dbug(1,dprintf("NCCI mapping established %ld %02x %02x %02x-%02x",      ncci_mapping_bug, ch, force_ncci, ch, ncci));  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -