Пример #1
0
/***********************************************************************
 *
 * FUNCTION NAME:    OBEX_RegisterService
 * DESCRIPTION:
 
 This function 

 * KNOWN ISSUES:

 none.
 
 *
 *
 ***********************************************************************/
APIDECL1 t_api APIDECL2 OBEX_RegisterService(u_int32 tid_s,t_obex_service_handler handler, u_int8 length, u_int8* target, void* cref)
{
  struct prh_obex_service_registration *p_temp, *p_new;
	
  /* check arguments */
	
  p_temp = obex_registered_services;
	
  if(p_temp)
	{
tim1:
	if(prh_obex_compair_registration(p_temp,length,target) == BT_NOERROR)
	{
		return BT_HOSTERROR;
	} else {
		if(p_temp->p_next)
		{
			p_temp = p_temp->p_next;
			goto tim1;	 
		} else {
			p_new = pMalloc(sizeof(struct prh_obex_service_registration));
			
			if(!p_new)
				return BT_NORESOURCES;
			
			p_new->handler = handler;
			p_new->tid = tid_s;
			p_new->target = pMalloc(length);
			pMemcpy(p_new->target,target,length);
			p_new->target_length = length;
			p_new->cid = 0x00;
			p_new->p_next = 0x00;
			
			p_temp->p_next = p_new;
		}
	}
	} else {
		p_temp = pMalloc(sizeof(struct prh_obex_service_registration));
		
		if(!p_temp)
			return BT_NORESOURCES;
		
		p_temp->handler = handler;
		p_temp->tid = tid_s;
		//p_temp->target = target;
		p_temp->target = pMalloc(length);
		pMemcpy(p_temp->target,target,length);
		p_temp->target_length = length;
		p_temp->cid = 0x00;
		p_temp->p_next = 0x00;
		
		obex_registered_services = p_temp;
	}
	
  return BT_NOERROR;
}
Пример #2
0
int prh_tcs_wug_keydb_trav_helper(void *data, void *input)
{
  struct prh_st_tcs_wug_member *instance=(struct prh_st_tcs_wug_member *)data;
  struct prh_st_tcs_wug_member *wug_mem=(struct prh_st_tcs_wug_member *)input;

  int ret;
  struct prh_st_tcs_wug_member_link_key *link_key1, *link_key2;

  /* generate link key */
  link_key1=(struct prh_st_tcs_wug_member_link_key *)pMalloc(sizeof(struct prh_st_tcs_wug_member_link_key));
  if (link_key1==pNULL)
    return BT_NORESOURCES;

  link_key2=(struct prh_st_tcs_wug_member_link_key *)pMalloc(sizeof(struct prh_st_tcs_wug_member_link_key));

  if (link_key2==pNULL)
    {
      pFree(link_key1);
      return BT_NORESOURCES;
    }
  
  prh_tcs_wug_keydb_generate_linkkey(link_key1->link_key);
  pMemcpy(link_key2->link_key, link_key1->link_key, 16);
  
  link_key1->peer = instance->addr;
  link_key2->peer = wug_mem->addr;

  /* add link key to both wug_members */
  ret=prh_tcs_wug_keydb_add_key(wug_mem, link_key1);
  
  if (ret!=BT_NOERROR)
    {
      pFree(link_key1);
      pFree(link_key2);
      return BT_NORESOURCES;
    }

  ret=prh_tcs_wug_keydb_add_key(instance, link_key2);
  if (ret!=BT_NOERROR)
    {
      prh_tcs_wug_keydb_remove_key_by_bd_addr(wug_mem, instance->addr, &link_key1);
      pFree(link_key1);
      pFree(link_key2);
      return BT_NORESOURCES;
    } 
      
  return BT_NOERROR;
}
Пример #3
0
// Returns an array of int containing the indexes of the entries to be elected
// from termEntries, an writes the size of the array in outElectedEntriesSize
static int* electedEntries (TermEntry** termEntries, int termEntriesSize,
    int* outElectedEntriesSize) {
  wchar_t* electedWord = NULL;
  int currentElectedEntriesSize = 0;
  int* electedEntries;

  for (int i = 0; i < termEntriesSize; i++) {
    if (termEntries[i] != NULL) {
      if (electedWord == NULL ||
          wcscmp(electedWord, termEntries[i]->token) > 0) {
        electedWord = termEntries[i]->token;
        currentElectedEntriesSize = 1;
      } else if (wcscmp(electedWord, termEntries[i]->token) == 0) {
        currentElectedEntriesSize++;
      }
    }
  }

  *outElectedEntriesSize = currentElectedEntriesSize;
  electedEntries = (int*) pMalloc(currentElectedEntriesSize * sizeof(int));
  if (!electedEntries) return NULL;

  int currentElectedIndex = 0;
  for (int i = 0; i < termEntriesSize; i++) {
    if (termEntries[i] != NULL &&
        wcscmp(electedWord, termEntries[i]->token) == 0) {
      electedEntries[currentElectedIndex++] = i;
    }
  }

  return electedEntries;
}
Пример #4
0
prh_t_l2_channel* prh_l2_chn_alloc_channel()
{
    t_channelId cid = 0;
    prh_t_l2_channel* p_channel = 0;

#if COMBINED_HOST==0
    while((prh_l2_channel_list[cid]) && (cid < PRH_L2_MAX_NUM_CHANNEL_IDENTIFIERS))
        cid++;
#else
    while((prh_l2_channel_list[cid].flag) && (cid < PRH_L2_MAX_NUM_CHANNEL_IDENTIFIERS))
        cid++;
#endif

    if(PRH_L2_MAX_NUM_CHANNEL_IDENTIFIERS != cid)
    {
#if COMBINED_HOST==0
        p_channel = prh_l2_channel_list[cid] = pMalloc(sizeof(prh_t_l2_channel));
#else
        p_channel = &(prh_l2_channel_list[cid]);// = pMalloc(sizeof(prh_t_l2_channel));
#endif
        if(p_channel)
        {
            pMemset(p_channel,0,sizeof(prh_t_l2_channel));
            p_channel->type = PRH_L2_CO_CHANNEL;
            p_channel->local_cid = cid+PRH_L2_MIN_USER_CID;
#if COMBINED_HOST==1
	     p_channel->flag = 1;
#endif
        }
    }
    return p_channel;
}
Пример #5
0
t_api PRH_RFCOMM_UE_Register_Server(prh_t_rfcomm_schan schan, struct prh_rfcomm_dlc_cb *dlc_cbs)
{
#if COMBINED_HOST==1
  struct prh_rfcomm_server_inst *serv_inst = &_serv_inst[prh_num];
#else
  struct prh_rfcomm_server_inst *serv_inst;
#endif
  int ret;
  
  pMutexLock(prh_rfcomm_core_lock);

  /* user should have asked for channel with Allocate_Server_Channel */
  
  if (schan==0 || schan>PRH_RFCOMM_MAX_SCHAN)
    {
      ret=BT_INVALIDPARAM;
      goto out;
    }

  if ((prh_rfcomm_core->channel_registered_state & (1U<<schan)) == (1U<<schan))
    {
      ret=BT_INVALIDPARAM;
      goto out;
    }
#if COMBINED_HOST==0

  serv_inst=(struct prh_rfcomm_server_inst *)pMalloc(sizeof(struct prh_rfcomm_server_inst));
  if (serv_inst==pNULL)
    {
      ret=BT_NORESOURCES;
      goto out;
    }
#endif
  serv_inst->server_chan=schan;
  serv_inst->dlc_cbs=*dlc_cbs;
  serv_inst->lock=pMutexCreate(FALSE);

  prh_rfcomm_core->channel_registered_state |= 1<<schan;
  ret=prh_host_ll_add(&(prh_rfcomm_core->server_list), (void *)serv_inst);
  if (ret!=BT_NOERROR)
    {
      prh_rfcomm_core->channel_registered_state &= ~(1<<schan);
      pMutexFree(serv_inst->lock);
      pFree(serv_inst);
      ret=BT_NORESOURCES;
      goto out;
    }
  /* reaffirm allocation of channel */
  prh_rfcomm_core->channel_allocation_state |= 1<<schan;
  ret=BT_NOERROR;

#if COMBINED_HOST==1
  prh_num++;
#endif
out:

  pMutexUnlock(prh_rfcomm_core_lock);
  return ret;
}
Пример #6
0
int main() {
  setlocale(LC_ALL, "en_US.UTF-8");  // For unicode handling

  FILE* input = stdin;
  FILE* output = stdout;

  unsigned int currentSize = kInitialNbFiles;
  unsigned int nbFiles = 0;
  FILE** openFiles = (FILE**) pMalloc(sizeof(FILE*) * currentSize);
  if (!openFiles) return MEMORY_ERROR;

  // Open an array of files
  for (unsigned int i = 0; !feof(input); ++i) {
    char filepath[kBufferSize];
    memset(filepath, 0, kBufferSize);

    if (!fgets(filepath, kBufferSize, input)) {
      if (!feof(input)) {
        return INPUT_ERROR;
      } else {
        break;
      }
    }

    unsigned int sizePath = strlen(filepath);
    if (filepath[sizePath - 1] == '\n') filepath[sizePath - 1] = '\0';

    if (i >= currentSize) {
      unsigned int previousSize = currentSize * sizeof(FILE*);
      currentSize *= 2;
      openFiles = (FILE**) pRealloc(openFiles, previousSize,
                                    currentSize * sizeof(FILE*));
      if (!openFiles) return MEMORY_ERROR;
    }

    openFiles[i] = fopen(filepath, "r");
    ++nbFiles;
  }

  TermEntry** terms = filesToTerms(openFiles, nbFiles);

  TermEntry * term = mergeFirst(terms, nbFiles, openFiles);
  while (term) {
    fprintTerm(output, term, SERIALIZATION);
    pFreeTerm(term);

    term = mergeFirst(terms, nbFiles, openFiles);
  }

  for (unsigned int i = 0; i < nbFiles; ++i) {
    if (openFiles[i]) fclose(openFiles[i]);  // Closing remaining files
    pFreeTerm(terms[i]);
  }
  pFree(terms, nbFiles * sizeof(TermEntry*));
  pFree(openFiles, currentSize * sizeof(FILE*));

  return 0;
}
void test_OBEX_Connect_header_gen(void)
{
	u_int32 tid;
	u_int8 version;
	u_int8 flags;
	u_int16 max_length;
	u_int16 target_length;
	u_int8* target;
	u_int16 header_length;
	t_DataBuf *databuf;
	int retValue;

  struct host_buf* h_buff;
	void (*callbackfunc)(u_int8 status, t_DataBuf* data)= connectCallbackFn;

  h_buff = host_buf_alloc(100);
	host_buf_reserve_header(h_buff,30);

  databuf= (t_DataBuf*)h_buff;

	tid = 0x000000bb;
	version = 0x10;
	flags = 0x00;
	max_length = 0x2000;

	target = pMalloc(10);

	target[0] = 0x01;
	target[1] = 0x02;
	target[2] = 0x03;
	target[3] = 0x04;
	target[4] = 0x05;

	target_length = 0x0005;

	header_length = 0x0000;

	/*databuf = pMalloc(240);*/

	retValue = OBEX_Connect(tid,version,flags,max_length,target_length,target,header_length,databuf,callbackfunc);
  cuReport("Connect not working with target- basic",(retValue == BT_NOERROR));

	target = 0x00;
	target_length = 0;

	retValue = OBEX_Connect(tid,version,flags,max_length,target_length,target,header_length,databuf,callbackfunc);
  cuReport("Connect not working without target - basic",(retValue == BT_NOERROR));

}
Пример #8
0
/***********************************************************************
 *
 * FUNCTION NAME:    OBEX_RegisterInbox
 * DESCRIPTION:
 
 This function will register the inbox handler for a transport. There
 can only be one inbox handler per transport.

 * KNOWN ISSUES:

 none.
 
 *
 *
 ***********************************************************************/
APIDECL1 t_api APIDECL2 OBEX_RegisterInbox(u_int32 tid_s,t_obex_service_handler handler, void *cref)
{
	struct prh_obex_inbox_registration *pRegistration;
	struct prh_obex_transport* pTransport;
	
	pTransport = prh_obex_server_transport;


	/* check parameters */

	/* does the transport exist */

	if(pTransport)
	{
		do {
			if(pTransport->tid == tid_s)
				break;
		} while((pTransport = pTransport->p_next));
	}
 
	if(!pTransport)
		return BT_INVALIDPARAM;

	pRegistration = obex_registered_inboxes;

	if(pRegistration)
	{
		do {
			if(pRegistration->tid == tid_s)
				break;
		} while ((pRegistration = pRegistration->p_next));
	}

	if(!pRegistration)
	{
		pRegistration = pMalloc(sizeof(struct prh_obex_inbox_registration));

		if(!pRegistration)
			return BT_NORESOURCES;	
	}

	pRegistration->handler = handler;
	pRegistration->tid = tid_s;
	pRegistration->p_next = obex_registered_inboxes;
	obex_registered_inboxes = pRegistration;


	return BT_NOERROR;
}
Пример #9
0
struct st_t_TCS_callInstance *prh_tcs_cc_core_GWaddBCastCallInstance(struct st_t_TCS_TLPeer *TLPeer, u_int16 cid)
{
	if(TLPeer)
	{
		TLPeer->bcastCallInstance = pMalloc(sizeof(struct st_t_TCS_callInstance));
		if(TLPeer->bcastCallInstance)
		{
			prh_tcs_cc_core_initCallInstance(TLPeer->bcastCallInstance);
			TLPeer->bcastCallInstance->cid = cid;
			TLPeer->bcastCallInstance->callType = PRH_TCS_CALLTYPE_PENDINGBCAST;
			TLPeer->bcastCallInstance->callHandle= prh_tcs_cc_core_GWgetFreeCallHandle();
		}
		return TLPeer->bcastCallInstance;
	}
	
	return NULL;
}
Пример #10
0
struct st_t_TCS_TLPeer *prh_tcs_cc_core_getNewTLPeer(t_bdaddr address, /*u_int8 initState,*/ u_int16 cid)
{
	int i, j;

	for(i=0; i<PRH_TCS_MAXTERMINALSPERGATEWAY; i++)
	{
		if(!(TCSInstance.TLPeer[i]))
		{
			TCSInstance.TLPeer[i] = (struct st_t_TCS_TLPeer *)pMalloc(sizeof(struct st_t_TCS_TLPeer));
			if(!(TCSInstance.TLPeer[i]))
				return NULL;
			
			pMemcpy(&(TCSInstance.TLPeer[i]->bdAddress.bytes), &(address.bytes), 6);
			TCSInstance.TLPeer[i]->cid = cid;
			for(j=0; j<PRH_TCS_MAX_CALLS_PER_DEVICE; j++)
				TCSInstance.TLPeer[i]->callInstance[j] = NULL;
			TCSInstance.TLPeer[i]->bcastCallInstance = NULL;
			return TCSInstance.TLPeer[i];
		}
	}

	return NULL;
}
Пример #11
0
struct st_t_TCS_callInstance *prh_tcs_cc_core_GWgetNewCallInstance(struct st_t_TCS_TLPeer *TLPeer, u_int16 cid, u_int16 callType)
{
	int i;
	/* Must also check global number of calls to TLPeers */
	
	for(i=0; i<PRH_TCS_MAX_CALLS_PER_DEVICE; i++)
	{
		if(!(TLPeer->callInstance[i]))
		{
			TLPeer->callInstance[i] = pMalloc(sizeof(struct st_t_TCS_callInstance));
			if(TLPeer->callInstance[i])
			{
				prh_tcs_cc_core_initCallInstance(TLPeer->callInstance[i]);
				TLPeer->callInstance[i]->cid = cid;
				TLPeer->callInstance[i]->callType = callType;
				TLPeer->callInstance[i]->callHandle = prh_tcs_cc_core_GWgetFreeCallHandle();
			}
			return TLPeer->callInstance[i];
		}
	}

	return NULL;
}
Пример #12
0
u_int8 prh_l2_chn_set_qos(prh_t_l2_channel* p_channel,t_L2_ChannelFlowSpec *p_outflow)
{
    if ((p_outflow == 0) || (p_channel == 0))
        return 0;

	/* ensure that a new QoS structure is not Malloced if one already exists */
#if COMBINED_HOST==0
	if (p_channel->outQOS == 0)
		p_channel->outQOS = pMalloc(sizeof(t_L2_ChannelFlowSpec));

    if (p_channel->outQOS)
    {
        p_channel->outQOS->flags = p_outflow->flags;
        p_channel->outQOS->bucketSize = p_outflow->bucketSize;
        p_channel->outQOS->delayVariation = p_outflow->delayVariation;
        p_channel->outQOS->latency = p_outflow->latency;
        p_channel->outQOS->peakBandwidth = p_outflow->peakBandwidth;
        p_channel->outQOS->serviceType = p_outflow->serviceType;
        p_channel->outQOS->tokenRate = p_outflow->tokenRate;
    }
    else
    {
        return 0;
    }
#else
    {
        p_channel->outQOS.flags = p_outflow->flags;
        p_channel->outQOS.bucketSize = p_outflow->bucketSize;
        p_channel->outQOS.delayVariation = p_outflow->delayVariation;
        p_channel->outQOS.latency = p_outflow->latency;
        p_channel->outQOS.peakBandwidth = p_outflow->peakBandwidth;
        p_channel->outQOS.serviceType = p_outflow->serviceType;
        p_channel->outQOS.tokenRate = p_outflow->tokenRate;
    }
#endif
    return 1;
}
Пример #13
0
struct st_t_TCS_callInstance *prh_tcs_cc_core_TLgetNewCallInstance(u_int16 cid, u_int8 callType)
{
	int i;

	for(i=0; i<PRH_TCS_MAX_CALLS_PER_DEVICE; i++)
	{
		if(!TCSInstance.callInstance[i])
		{	
			TCSInstance.callInstance[i] = pMalloc(sizeof(struct st_t_TCS_callInstance));
			if(TCSInstance.callInstance[i])
			{
				prh_tcs_cc_core_initCallInstance(TCSInstance.callInstance[i]);
				TCSInstance.callInstance[i]->callType = callType;
				TCSInstance.callInstance[i]->cid = cid;
				TCSInstance.callInstance[i]->callHandle = i+1; /* callHandle starts at '1' */
			}

			return TCSInstance.callInstance[i];
		}
		else /* the call instance is in use */
		{
			if(cid==0 && TCSInstance.callInstance[i]->cid==0)
			{
				/* the new callInstance is for a broadcast SETUP messasge */
				/* and the existing callInstance is for a broadcast SETUP message */
				/* therefore we have to assume that they are for the same call */
				/* otherwise we would have a different call everytime we received */
				/* the broadcast SETUP message */
				return TCSInstance.callInstance[i];
			}
		
		}
	}

	return NULL;
}
Пример #14
0
APIDECL1 t_api APIDECL2 PE_SrvRegisterPort(char *port, prh_t_rfcomm_schan *serv_chan, void (*port_callback)(prh_t_rfcomm_schan schan, t_bdaddr bd_addr, u_int8 connection_state))
{
  struct prh_rfcomm_pe_port *pe_info;
  struct prh_rfcomm_dlc_cb dlc_cbs;
  int ret=0;
  int portnum;

  /* three traps, illegal server channel number, 0 server channel number (user requested), 1-30 */
  if (*serv_chan>PRH_RFCOMM_MAX_SCHAN)
    return BT_INVALIDPARAM;
  
  /* Has user requested a server channel */
  if (*serv_chan==0)
    {
      ret=PRH_RFCOMM_UE_Allocate_Server_Channel(serv_chan);
      if (ret!=BT_NOERROR)
	return ret;
    }
  else
    {
      ret=PRH_RFCOMM_UE_Get_Channel_State(*serv_chan);
      if (ret==BT_NOERROR)
	/*Channel Exists already */
	return BT_INVALIDPARAM;
    }
  
  portnum=*serv_chan;  

  /* Add port to list of registered port numbers */
  pe_info=(struct prh_rfcomm_pe_port *)pMalloc(sizeof(struct prh_rfcomm_pe_port));
  if (pe_info==pNULL)
    {
      ret=BT_NORESOURCES;
      goto err_out_dealloc;
    }

  pMemset(pe_info, 0, sizeof(struct prh_rfcomm_pe_port));      
  prh_rfcomm_init_pe_struct(pe_info);
  
  pe_info->portname=(char *)pMalloc(pStrlen(port)+1);
  if (pe_info->portname==pNULL)
    {
      ret=BT_NORESOURCES;
      goto err_out_free_info;
    }
  
  pStrcpy(pe_info->portname, port);
  pe_info->port_cbfunc=port_callback;
  pe_info->portnum=portnum;
  
  dlc_cbs.dlc_estab_ind=port_ent_dlc_estab_ind_cb;
  dlc_cbs.dlc_estab_conf=port_ent_dlc_estab_conf_cb;
  dlc_cbs.dlc_rel_ind=port_ent_dlc_rel_ind_cb;
  dlc_cbs.dlc_data_ind=port_ent_dlc_data_ind_cb;
  dlc_cbs.linestat=port_ent_dlc_linestat_cb;
  dlc_cbs.portneg=port_ent_dlc_portneg_cb;
  dlc_cbs.control=port_ent_dlc_control_cb;
  dlc_cbs.agg_flow_ind=port_ent_dlc_flow_ind_cb;
  dlc_cbs.dlc_paramneg=port_ent_dlc_paramneg_cb;
  dlc_cbs.credit_flow_ind=port_ent_dlc_credit_flow_cb;
  
  ret=prh_rfcomm_pe_add_port_entity(pe_info);
  if (ret==BT_NORESOURCES)
    {
      goto err_out_free_info;
    }
  
  ret=PRH_RFCOMM_UE_Register_Server(*serv_chan, &dlc_cbs);
  if (ret!=BT_NOERROR)
    {
      goto err_out_remove_pe;
    }

  /* Do OS Specific Registering */
  ret=PE_OS_SrvRegisterPort(pe_info);
  if (ret!=BT_NOERROR)
    {
      PRH_RFCOMM_UE_Deregister_Server(*serv_chan);
      goto err_out_remove_pe;
    }
  return BT_NOERROR;
  
  /* handle different error conditions .. make sure to clean up */
 err_out_remove_pe:
  prh_rfcomm_pe_remove_port_entity_by_portnum(&pe_info, *serv_chan);
 err_out_free_info:
  prh_rfcomm_free_pe_struct(pe_info);
 err_out_dealloc:
  PRH_RFCOMM_UE_Deallocate_Server_Channel(*serv_chan);
  return ret;
}
Пример #15
0
/*************************************************************************************************
* FUNCTION :- prh_mgr_store_inquiry_entry
*
* DESCRIPTION :- This function stores an inquiry result in the inq db. If the device is already 
*                 in the database the parameters will be updates otherwise a new entry will be
*                 added to the inq db.
*                 NOTE:inquiryresult passed in is one set of page parameters, there may be many 
*                 in a single hci event                          
*                 
************************************************************************************************/
struct st_t_BT_InquiryInfo *prh_mgr_store_inquiry_entry(u_int8 *inquiryResult) 
{
    struct st_t_BT_InquiryInfo *current;
    
	extern u_int32 prh_mgr_inqdb_num_entries;
//    char err_str[40]={0};


	if(inquiryResult == NULL)
		return  NULL;
	
    pMutexLock(prh_mgr_inqdb_list_lock);

	current=prh_mgr_inqdb_head;

	pDebugPrintfEX((pLOGDEBUG,pLOGMANAGER,"prh_mgr_store_inquiry_entry: linklist is NULL? %d\n", prh_mgr_inqdb_head?1:0));

	
    while (current) 
    {
        if (BD_ADDR_CMP(current->bdAddress,*(t_bdaddr*)(inquiryResult+0))) /* check alignment correctness here */
            break;
        current=current->next;
    }
#if pDEBUG
    if (!current) 
    {
        pDebugPrintfEX((pLOGDEBUG,pLOGMANAGER,"prh_mgr_store_inquiry_entry: cannot find existing entry for device %s\n",prh_mgr_printBDAddress(*(t_bdaddr*)(inquiryResult+0))));
    } 
#endif

    if (current) 
   {
        if(current->entryUsage)
	{
            /* entry already exists, but is in use, so cannot be updated */
	    pDebugPrintfEX((pLOGDEBUG,pLOGMANAGER,"prh_mgr_store_inquiry_entry: cannot find existing entry for device %s\n",prh_mgr_printBDAddress(*(t_bdaddr*)(inquiryResult+0))));

            pMutexUnlock(prh_mgr_inqdb_list_lock);
            return current;
        }
	else 
	{
            prh_mgr_unlink_inquiry_entry(current);
        }
    } 
   else 
   {  
        pDebugPrintfEX((pLOGDEBUG,pLOGMANAGER,"prh_mgr_store_inquiry_entry: prh_mgr_inqdb_num_entries=%d\n", prh_mgr_inqdb_num_entries));
        if (prh_mgr_inqdb_num_entries<(u_int32)HOST_INQDB_MAX_DEVICE_ENTRIES) 
        {
            /* alloc a new record */
            current=pMalloc(sizeof(struct st_t_BT_InquiryInfo));
            if (!current) 
            {
                pMutexUnlock(prh_mgr_inqdb_list_lock);
                return NULL;
            }
			current->deviceName = NULL;

#if HOST_INQDB_CULL_THRESHOLD!=0
            if (!prh_mgr_inqdb_num_entries)  /* we are adding to an empty database */
                prh_mgr_inqdb_timer_handle=pTimerCreate(HOST_INQDB_CULL_GRANULARITY,prh_mgr_cull_inquiry_db,NULL,pTIMER_ONESHOT);
#endif

            prh_mgr_inqdb_num_entries++;
        } 
        else 
        {
            /* find the oldest non-inuse record */        
            current=prh_mgr_inqdb_tail;
            while (current) 
            {
                if (current->entryUsage)
                    current=current->prev;
                else
                    break;
            }

            if (!current) 
            {
                /* no available entry */
                pMutexUnlock(prh_mgr_inqdb_list_lock);
                pDebugPrintfEX((pLOGNOTICE,pLOGMANAGER,"prh_mgr_store_inquiry_entry: prh_mgr_inqdb_num_entries==HOST_INQDB_MAX_DEVICE_ENTRIES (%d) and  all entries in use\n",HOST_INQDB_MAX_DEVICE_ENTRIES));
                return NULL;
            }
            prh_mgr_unlink_inquiry_entry(current);
        }

        current->entryAge=1; /* only modified when an entry did not already exist for this adress */
		current->nameRetrieved = 0;
    }
    
    //Lu added
    

    /* fill out the parameters */
    pMemcpy(&current->bdAddress,inquiryResult+0,6);
    current->pageScanRepetitionMode=inquiryResult[6];
    current->pageScanPeriodMode=inquiryResult[7];
    current->pageScanMode=inquiryResult[8];
    current->classOfDevice=inquiryResult[9]|(inquiryResult[10]<<8)|(inquiryResult[11]<<16);
    current->clockOffset=inquiryResult[12]|(inquiryResult[13]<<8);

	/* Do not fill in current->deviceName until RemoteNameRequest is complete */

    current->entryUsage=1; /* entry starts marked as 'in-use' */

    /* add this new record (to the head of the list) */
    current->next=prh_mgr_inqdb_head;
    current->prev=NULL;
    if (current->next)
        current->next->prev=current;
    prh_mgr_inqdb_head=current;   
    if (!prh_mgr_inqdb_tail)
        prh_mgr_inqdb_tail=current;

    pDebugPrintfEX((pLOGDEBUG,pLOGMANAGER,"prh_mgr_store_inquiry_entry: current->entryAge=%d, current->classOfDevice=0x%x\n", current->entryAge,current->classOfDevice));


    pMutexUnlock(prh_mgr_inqdb_list_lock);
    return current;
}
Пример #16
0
t_api prh_tcs_cc_core_storeCallParams(struct st_t_TCS_callParams **destRef, struct st_t_TCS_callParams *src)
{
	struct st_t_TCS_callParams *dest;

	if(!destRef)
		return BT_INVALIDPARAM;

	if(*destRef)
		prh_tcs_cc_core_freeCallParams(*destRef);

	if(!src)
	{
		*destRef = NULL;
		return BT_NOERROR;
	}

	dest = (struct st_t_TCS_callParams *)pMalloc(sizeof(struct st_t_TCS_callParams));
	if(dest)
		pMemcpy(dest, src, sizeof(struct st_t_TCS_callParams));
	else
		return BT_NORESOURCES;

		
	if(dest)
	{
		pMemcpy(dest, src, sizeof(struct st_t_TCS_callParams));
		if(PRH_TCS_CC_PARAM_BEARERCAPABILITY_EXISTS(src->bitMask) && PRH_TCS_BEARER_CAP_LINK_TYPE_ACL == src->linkType && src->aclBearer)
		{
			dest->aclBearer = (struct st_t_TCS_aclBearer *)pMalloc(sizeof(struct st_t_TCS_aclBearer));
			if(dest->aclBearer)
				pMemcpy(dest->aclBearer, src->aclBearer, sizeof(struct st_t_TCS_aclBearer));
			else
				return BT_NORESOURCES;
		}
		
		if(PRH_TCS_CC_PARAM_AUDIOCONTROL_EXISTS(src->bitMask) && src->audioControlInfo)
		{
			dest->audioControlInfo = (u_int8 *)pMalloc(src->audioControlInfoLength);
			if(dest->audioControlInfo)
				pMemcpy(dest->audioControlInfo, src->audioControlInfo, src->audioControlInfoLength);
			else
				return BT_NORESOURCES;
		}

		if(PRH_TCS_CC_PARAM_COMPANYSPECIFIC_EXISTS(src->bitMask) && src->companySpecific)
		{
			dest->companySpecific = (u_int8 *)pMalloc(src->companySpecificLength);
			if(dest->companySpecific)
				pMemcpy(dest->companySpecific, src->companySpecific, src->companySpecificLength);
			else
				return BT_NORESOURCES;
		}

		if(PRH_TCS_CC_PARAM_CALLEDPARTYNUMBER_EXISTS(src->bitMask) && src->calledPartyNumber)
		{
			dest->calledPartyNumber = (u_int8*)pMalloc(src->calledPartyNumberLength); 
			if(dest->calledPartyNumber)
				pMemcpy(dest->calledPartyNumber, src->calledPartyNumber, src->calledPartyNumberLength); 
			else
				return BT_NORESOURCES;
		}

		if(PRH_TCS_CC_PARAM_CALLINGPARTYNUMBER_EXISTS(src->bitMask) && src->callingPartyNumber)
		{
			dest->callingPartyNumber = (u_int8*)pMalloc(src->callingPartyNumberLength);
			if(dest->callingPartyNumber)
				pMemcpy(dest->callingPartyNumber, src->callingPartyNumber, src->callingPartyNumberLength); 
			else
				return BT_NORESOURCES;
		}

		*destRef = dest;
	}

	return BT_NOERROR;
}
Пример #17
0
void bt_pin_code_ind_cb(t_bdaddr address )
{
    LINK_PIN_CODE_IND_ST mv;
    t_bdaddr  *addr = (t_bdaddr *)&address;
    btbm_bd_addr_t	bd_addr;
    bd_addr.lap= BDADDR_Get_LAP(&address);
    bd_addr.uap = BDADDR_Get_UAP(&address);
    bd_addr.nap = BDADDR_Get_NAP(&address);	
mmi_trace(1,"bt_pin_code_ind_cb is called!! bonding_role=%d,pincode_sent=%d",bonding_role,pincode_sent);
if(pincode_sent)//zhou siyou 20110628
{
	pincode_sent=0;
	mmi_trace(1,"!!!!!!!!!!!!!!!!!!!!!!!!!!bt_pin_code_ind_cb is called pin %s!!","0000");
	
	mmi_trace(1,"!!!!!!!!!!!!!!!!!!!!!!!!!!bt_pin_code_ind_cb is called pin %s!!","0000");

	mmi_trace(1,"!!!!!!!!!!!!!!!!!!!!!!!!!!bt_pin_code_ind_cb is called pin %s!!","0000");
	MGR_PINResponse(address, 1, "0000", 4);	
	return;

}
     responsePinCode = 0;
    if(bth_is_the_specified_device_paired(bd_addr))
    {		
    		mmi_trace(1,"bt_pin_code_ind_cb is called!!if(bth_is_the_specified_device_paired(bd_addr))");
		mv.type = LINK_PIN_CODE_IND;
		memcpy(mv.bd_addr.bytes,address.bytes,sizeof(t_bdaddr));
		MGR_GetRemoteName(address, (char*)mv.name, 47, &mv.name_len, NULL);

		rdabt_put_message(EXTERNAL_TASK_MASK,LINK_Q,&mv);
		pin_code_ind_timer = rdabt_timed_event_in(15*1000*1000,rdabt_InputPin_MoniterTimer_cb,(void *)addr);
    }
    else
    {
    if( bonding_role != 0)
    {		mmi_trace(1,"bt_pin_code_ind_cb is called!! if( bonding_role != 0)");

		mv.type = LINK_PIN_CODE_IND;
		memcpy(mv.bd_addr.bytes,address.bytes,sizeof(t_bdaddr));
		MGR_GetRemoteName(address, (char*)mv.name, 47, &mv.name_len, NULL);

		rdabt_put_message(EXTERNAL_TASK_MASK,LINK_Q,&mv);
		bonding_addr = address;		//add by tan, 7-12-2009
		pin_code_ind_timer = rdabt_timed_event_in(15*1000*1000,rdabt_InputPin_MoniterTimer_cb,NULL);
    	}		
	else 
	{ 
		//may be the other device has lost the security info..
		//anyway, we do not need to bond...

			deviceName = (char*)pMalloc(48);
			if( deviceName == NULL)
			{
				MGR_PINResponse(address,  0, NULL, 0);	
			}
			else
			{
				int status = 0;
				memset(deviceName, 0, 48);
				status = MGR_GetRemoteName( address, deviceName, 47,  &nameLen, rdabt_GetRemoteName_cb);
				if( status == 0)
				{
					rdabt_GetRemoteName_cb(address, 0);	
				}
			}

			/*
			bt_bm_link_connect_accept_ind_struct	  * accept_ind;

			accept_ind = (bt_bm_link_connect_accept_ind_struct*)construct_local_para((kal_uint16)sizeof(bt_bm_link_connect_accept_ind_struct), TD_CTRL);
			accept_ind->bd_addr.lap= BDADDR_Get_LAP(&address);
			accept_ind->bd_addr.uap = BDADDR_Get_UAP(&address);
			accept_ind->bd_addr.nap = BDADDR_Get_NAP(&address);	

			rdabt_send_msg_up(MOD_MMI, MSG_ID_BT_BM_LINK_CONNECT_ACCEPT_IND, (void *)accept_ind, NULL);		
	              MGR_SetBondingCallBack(address, rdabt_being_bonding_cb);	
	              */
		}

	}	
}
Пример #18
0
/*
 * prh_rfcomm_entity_connect_port
 * -- Port Entity DLC Establish helper function
 *
 * Allocate a Port entity structure, sets it up, 
 * finds a multiplexer, (either gets current one or starts one)
 * Sets up callbacks, sends Parameter negotiation, and then does 
 * the DLC establish.
 *
 * Returns: BT_NOERROR - a multiplexer is already started
 *          BT_PENDING - a multiplexer start is in progress or required
 *          BT_NORESOURCES - no resources were available
 */
int prh_rfcomm_entity_connect_port(t_bdaddr remote_bd_addr, prh_t_rfcomm_schan rem_schan, prh_t_rfcomm_dlci *dlci, prh_t_rfcomm_dlc_params *dlc_params, struct prh_rfcomm_dlc_cb *cbs, void **multi_inst_ptr)
{
  int dbit;
  struct prh_rfcomm_l2cap_inst *l2cap_inst;
  struct prh_rfcomm_entity_pending_dlc *pending_info;
  struct prh_rfcomm_entity_pending_conns *pending_conns;
  t_api ret;
  
#if COMBINED_HOST==1  
  int i =0; 
#endif

  pMutexLock(prh_rfcomm_pending_lock);
  
   /* Check does a multiplexer to the remote BD Address exist already or is one pending */
  ret=PRH_RFCOMM_UE_Get_Multiplexer_State(remote_bd_addr, (void **)&l2cap_inst);
  if (ret==BT_NOERROR)
    {
      /* A Multiplexer exists */
      dbit=l2cap_inst->initiating;

      /* If it exists establish the DLC */
      *dlci=((!dbit) | (rem_schan<<1));
      *multi_inst_ptr=(void *)l2cap_inst;
      
      PRH_RFCOMM_UE_DLC_Estab_Req(remote_bd_addr, *dlci, dlc_params, cbs, *multi_inst_ptr);
      ret=BT_NOERROR;
      goto out;
    }

#if COMBINED_HOST==1
  //cui jian changed to static malloc pending information. 2009.02.11
	for( i =0; i< PRH_RFCOMM_MAX_Connect_Port ; i++)
	{
		if( pending_info2[i].info_used == 0 )
		{
			pending_info = &pending_info2[i ];
			pending_info2[i].info_used  = 1;
			break;
		}
	}
	if( i == PRH_RFCOMM_MAX_Connect_Port )
	  {
	      ret=BT_NORESOURCES;
	      goto out;
	  }
#else

  /* we'll be pending - malloc pending information */
  pending_info=(struct prh_rfcomm_entity_pending_dlc *)pMalloc(sizeof(struct prh_rfcomm_entity_pending_dlc));
  if (pending_info==NULL)
    {
      ret=BT_NORESOURCES;
      goto out;
    }
#endif
  
  pMemset(pending_info, 0, sizeof(struct prh_rfcomm_entity_pending_dlc));

  pending_info->remote_schan=rem_schan;
  pending_info->cbs=*cbs;
  pending_info->dlc_params=*dlc_params;

  dbit=1;
  pending_info->dlci=*dlci=((!dbit) | (rem_schan<<1));

  if (ret==BT_INVALIDPARAM)
    {
      /* No Multiplexer exists or is being started */
      /* Need to start a pending list */

#if COMBINED_HOST==1
  //cui jian changed to static malloc pending information. 2009.02.11

	for( i =0; i< PRH_RFCOMM_MAX_Connect_Port ; i++)
	{
		if( pending_conns2[i].info_used == 0 )
		{
			pending_conns = &pending_conns2[i ];
			pending_conns2[i].info_used  = 1;
			break;
		}
	}
	if( i == PRH_RFCOMM_MAX_Connect_Port )
	  {
	      ret=BT_NORESOURCES;
	      goto out;
	  }
#else
      pending_conns=(struct prh_rfcomm_entity_pending_conns *)pMalloc(sizeof(struct prh_rfcomm_entity_pending_conns));
      if (pending_conns==NULL)
	{
	  ret=BT_NORESOURCES;
	  goto out_free_info;
	}
#endif

      pMemset(pending_conns, 0, sizeof(struct prh_rfcomm_entity_pending_conns));
      pending_conns->bd_addr=remote_bd_addr;
      pending_conns->pending_dlc_head=NULL;
      pending_conns->multi_inst=NULL;

      /* Add to the list */
      ret=prh_rfcomm_entity_add_pending_device(pending_conns);
      if (ret==BT_NORESOURCES)
	{
	  goto out_free_conns;
	}

      ret=prh_rfcomm_entity_add_pending_channel(remote_bd_addr, pending_info);
      if (ret==BT_NORESOURCES)
	{
	  prh_rfcomm_entity_remove_pending_device(remote_bd_addr);
	  goto out_free_info;
	}

      ret=prh_rfcomm_open_multiplexer(remote_bd_addr, &pending_conns->multi_inst);
      if (ret!=BT_PENDING && ret!=BT_NOERROR)
	{
	  prh_rfcomm_entity_remove_all_pending_channels(pending_conns);
	  prh_rfcomm_entity_remove_pending_device(remote_bd_addr);
	}
      else
	*multi_inst_ptr=pending_conns->multi_inst;	    

    }
  else if (ret==BT_PENDING)
    {
      /* A multiplexer start is pending */

      *multi_inst_ptr=(void *)l2cap_inst;
      /* add to the list */
      ret=prh_rfcomm_entity_add_pending_channel(remote_bd_addr, pending_info);
      /* if we are pending return pending not no-error */
      if (ret!=BT_NOERROR)
	{
	  ret=BT_NORESOURCES;
	  goto out_free_info;
	}
      else
	ret=BT_PENDING;
    }
  
  goto out;

 out_free_conns:
  pFree(pending_conns);
 out_free_info:
  pFree(pending_info);
 out:
  pMutexUnlock(prh_rfcomm_pending_lock);
  return ret;
}
Пример #19
0
BYTE* dataparser(LPCWSTR pStr,DWORD dwStrLen,MALLOC_FUNC pMalloc,DWORD* pdwDataLength)
{
	if (pStr[0]==L'\0')
		return NULL;
	
	if (_1stcontain2nd(pStr,L"int:"))
	{
		pStr+=4;
		BYTE* pRet=(BYTE*)pMalloc(4);
		*((DWORD*)pRet)=DWORD(_readnum(10,pStr));
		if (pdwDataLength!=NULL)
			*pdwDataLength=4;
		return pRet;
	}
	else if (_1stcontain2nd(pStr,L"dword"))
	{
		pStr+=5;
		int base=_getbase(pStr);
		if (*pStr!=':')
			return NULL;
		pStr++;
		BYTE* pRet=(BYTE*)pMalloc(4);
		*((DWORD*)pRet)=DWORD(_readnum(base,pStr));
		if (pdwDataLength!=NULL)
			*pdwDataLength=4;
		return pRet;
	}
	else if (_1stcontain2nd(pStr,L"word"))
	{
		pStr+=4;		
		int base=_getbase(pStr);
		if (*pStr!=':')
			return NULL;
		pStr++;
		BYTE* pRet=(BYTE*)pMalloc(2);
		*((WORD*)pRet)=WORD(_readnum(base,pStr));
		if (pdwDataLength!=NULL)
			*pdwDataLength=2;
		return pRet;
	}
	else if (_1stcontain2nd(pStr,L"byte"))
	{
		pStr+=4;		
		int base=_getbase(pStr);
		if (*pStr!=':')
			return NULL;
		pStr++;
		BYTE* pRet=(BYTE*)pMalloc(2);
		*pRet=BYTE(_readnum(base,pStr));
		if (pdwDataLength!=NULL)
			*pdwDataLength=1;
		return pRet;
	}
	else if (_1stcontain2nd(pStr,L"hex:") || _1stcontain2nd(pStr,L"bin:"))
	{
		pStr+=4;
		int i=0;
		
		// Calculating reqiured size
		for (LPCWSTR pStr2=pStr;*pStr2!='\0';i++)
		{
			if (!((*pStr2>='0' && *pStr2<='9') || 
				(*pStr2>='a' && *pStr2<='f') ||
				(*pStr2>='A' && *pStr2<='F')))
				break;
				
			pStr2++;

			if ((*pStr2>='0' && *pStr2<='9') || 
				(*pStr2>='a' && *pStr2<='f') ||
				(*pStr2>='A' && *pStr2<='F'))
				pStr2++;

			for (;*pStr2==' ';pStr2++);
		}

		if (i==0)
			return NULL;
			
		BYTE* pRet=(BYTE*)pMalloc(max(i,2));

		for (i=0;*pStr!='\0';i++)
		{
			if (*pStr>='0' && *pStr<='9')
				pRet[i]=*pStr-'0';
			else if (*pStr>='a' && *pStr<='f')
				pRet[i]=*pStr-'a'+0xa;
			else if (*pStr>='A' && *pStr<='F')
				pRet[i]=*pStr-'A'+0xa;
			else
				break;

			pStr++;

			if (*pStr>='0' && *pStr<='9')
			{
				pRet[i]<<=4;
				pRet[i]+=*pStr-'0';
				pStr++;
			}
			else if (*pStr>='a' && *pStr<='f')
			{
				pRet[i]<<=4;
				pRet[i]+=*pStr-'a'+0xa;
				pStr++;
			}
			else if (*pStr>='A' && *pStr<='F')
			{
				pRet[i]<<=4;
				pRet[i]+=*pStr-'A'+0xa;
				pStr++;
			}

			for (;*pStr==' ';pStr++);
		}
		if (pdwDataLength!=NULL)
			*pdwDataLength=i;
		return pRet;
	}
	else if (_1stcontain2nd(pStr,L"str:"))
	{
		dwStrLen-=4;
		pStr+=4;
		if (int(dwStrLen)<=0)
			return NULL;

		WCHAR* pUnicode;
		int len=_readstringW(pUnicode,pStr,dwStrLen,malloc);

		// Get Length
		len=WideCharToMultiByte(CP_ACP,0,pUnicode,len,NULL,0,NULL,NULL);
		char* pRet=(char*)pMalloc(len+1);		
		len=WideCharToMultiByte(CP_ACP,0,pUnicode,len,pRet,len+1,NULL,NULL);

		free(pUnicode);
		
		if (pdwDataLength!=NULL)
			*pdwDataLength=len;
		return (BYTE*)pRet;
	}
	else if (_1stcontain2nd(pStr,L"oem:"))
	{
		dwStrLen-=4;
		pStr+=4;
		if (int(dwStrLen)<=0)
			return NULL;
		
		WCHAR* pUnicode;
		int len=_readstringW(pUnicode,pStr,dwStrLen,malloc);

		// Get Length
		len=WideCharToMultiByte(CP_OEMCP,0,pUnicode,len,NULL,0,NULL,NULL);
		char* pRet=(char*)pMalloc(len+1);		
		len=WideCharToMultiByte(CP_OEMCP,0,pUnicode,len,pRet,len+1,NULL,NULL);

		free(pUnicode);
		
		if (pdwDataLength!=NULL)
			*pdwDataLength=len;
		return (BYTE*)pRet;
	}
	else if (_1stcontain2nd(pStr,L"wstr:") || _1stcontain2nd(pStr,L"uni:") || _1stcontain2nd(pStr,L"utf16:"))
	{
		for (pStr+=3,dwStrLen-=3;*pStr!=':';pStr++,dwStrLen--);
		pStr++;dwStrLen--;

		if (int(dwStrLen)<=0)
			return NULL;
	
		WCHAR* pRet;
		int len=_readstringW(pRet,pStr,dwStrLen,pMalloc);
		
		if (pdwDataLength!=NULL)
			*pdwDataLength=len*2;
		return (BYTE*)pRet;
	}
	else if (_1stcontain2nd(pStr,L"utf8:"))
	{
		dwStrLen-=5;
		pStr+=5;
		if (int(dwStrLen)<=0)
			return NULL;
		
		WCHAR* pUnicode;
		int len=_readstringW(pUnicode,pStr,dwStrLen,malloc);

		// Get Length
		char* pRet=(char*)pMalloc((len+1)*2);		
		len=WideCharToMultiByte(CP_UTF8,0,pUnicode,len,pRet,(len+1)*2,NULL,NULL);

		free(pUnicode);
		
		if (pdwDataLength!=NULL)
			*pdwDataLength=len;
		return (BYTE*)pRet;
	}
	else if (_1stcontain2nd(pStr,L"utf7:"))
	{
		dwStrLen-=5;
		pStr+=5;
		if (int(dwStrLen)<=0)
			return NULL;
		
		WCHAR* pUnicode;
		int len=_readstringW(pUnicode,pStr,dwStrLen,malloc);

		// Get Length
		char* pRet=(char*)pMalloc((len+1)*5);		
		len=WideCharToMultiByte(CP_UTF7,0,pUnicode,len,pRet,(len+1)*5,NULL,NULL);

		free(pUnicode);
		
		if (pdwDataLength!=NULL)
			*pdwDataLength=len;
		return (BYTE*)pRet;
	}
	else
	{
		if (int(dwStrLen)<=0)
			return NULL;
		
		if (pdwDataLength!=NULL)
			*pdwDataLength=dwStrLen;

		int nAllocLen=LenWtoA(pStr,dwStrLen);
		char* pNew=(char*)pMalloc(nAllocLen+1);
		MemCopyWtoA(pNew,nAllocLen+1,pStr,dwStrLen);
		pNew[nAllocLen]='\0';
		return (BYTE*)pNew;
	}
}
Пример #20
0
prh_t_l2_acl_link* prh_l2_acl_alloc_link(t_bdaddr* p_bd_addr, u_int16 pending_cid)
{
    prh_t_l2_acl_link* p_link;
    int i;

    /* First Check does a link already exist to this Address */
    
    for(i=0;i<PRH_L2_MAX_NUM_LINKS;i++)
    {
#if COMBINED_HOST==1
       p_link = &(prh_l2_acl_links[i]);
       if(p_link->flag == 0)
       {
           pMemset(p_link,0,sizeof(prh_t_l2_acl_link)); 
		   p_link->flag = 1;
#else
       p_link = prh_l2_acl_links[i];
       if(p_link == 0)
       {
           p_link = pMalloc(sizeof(prh_t_l2_acl_link));
		   if (!p_link)
			   return 0;
           pMemset(p_link,0,sizeof(prh_t_l2_acl_link)); 
           prh_l2_acl_links[i] = p_link;
		   p_link->cur_pos=0;
#endif
           prh_l2_utils_set_bd_addr(&p_link->bd_addr, p_bd_addr);
           p_link->pending_cid = pending_cid;
		   p_link->mtu_complete = 1;
           return p_link;
       }
    }
    return 0;
}

/**************************************************************
 * Function : prh_l2_acl_free_Link 
 *      
 * Parameters :
 *      p_link :- A pointer to the link structure to be freed.
 *
 * Returns
 *     --
 *
 * Description 
 * Frees a link structure for a link to a specific Bd_ADDR.
 * Also cancels any timers associated with the link.
 **************************************************************/

void  prh_l2_acl_free_link(prh_t_l2_acl_link* p_link)
{
#if COMBINED_HOST==0
    u_int16 i;
#endif
#if (L2CAP_GROUPS_SUPPORTED==1)
	prh_t_l2_channel* p_channel;
    #endif
    if (p_link != 0)
    {
#if (L2CAP_GROUPS_SUPPORTED==1)
        for (i = PRH_L2_MIN_USER_CID; i < (PRH_L2_MAX_NUM_CHANNEL_IDENTIFIERS + PRH_L2_MIN_USER_CID);i++)
		{
			
			p_channel = prh_l2_chn_get_p_channel(i);
			if ((p_channel) && (p_channel->bda_list))
			{
				prh_l2_bda_list_remove(p_channel->bda_list,&p_link->bd_addr);
			}
		}
#endif
#if COMBINED_HOST==1
        p_link->flag = 0;
        if (p_link->timer_active)
            pTimerCancel(p_link->timer_handle);
#else
        for(i=0;i<PRH_L2_MAX_NUM_LINKS;i++)
        {
            if(prh_l2_acl_links[i] == p_link)
            {
                if (p_link->timer_active)
                	{
        	            pTimerCancel(p_link->timer_handle);
       			p_link->timer_active = 0;
       			p_link->timer_handle=0;
                	}
                pFree(p_link);
                prh_l2_acl_links[i] = 0;
                return;
            }
        }
#endif
    }
}
Пример #21
0
/***********************************************************************
 *
 * FUNCTION NAME:    OBEX_SuggestSync
 * DESCRIPTION:
 
 This function will send a PUSH command to the IrMC Client

 * KNOWN ISSUES:

 none.
 
 *
 *
 ***********************************************************************/
APIDECL1 t_api APIDECL2 OBEX_SuggestSync(u_int32 tid_s, u_int8 type, char* pAny, u_int8 length,t_obex_command_handler handler)
{
		t_DataBuf* buff;

	// object name is " t e l e c o m / p u s h . t x t ";
	// \r\n
	
	// "telecom/pb.vcf"
	// "telecom/cal.vcs"
	// "telecom/note.vnt"
	// "telecom/inmsg.vmg"
	// "telecom/outmsg.vmg"
	// "telecom/sentmsg.vmg"f
	// "telecom/rtc.txt"
	// "default"

	u_int8 *buffer;
	u_int8 offset_len;
	u_int16 t_offset;
	u_int8 lcv;
	u_int8 obj_name[34];
	pMemcpy(obj_name," t e l e c o m / p u s h . t x t ",34);

	buffer = pMalloc(165 + length);

	offset_len = 0;

	if(type & 1)
	{
		pMemcpy(buffer + offset_len ,"SYNC:",5);
		offset_len += 5;
		pMemcpy(buffer + offset_len , "telecom/pb.vcf\r\n",16);
		offset_len += 16;
	}

	if(type & 2)
	{
		pMemcpy(buffer + offset_len ,"SYNC:",5);
		offset_len += 5;
		pMemcpy(buffer + offset_len , "telecom/cal.vcf\r\n",17);
		offset_len += 17;
	}

	if(type & 4)
	{
		pMemcpy(buffer + offset_len ,"SYNC:",5);
		offset_len += 5;
		pMemcpy(buffer + offset_len , "telecom/note.vcf\r\n",18);
		offset_len += 18;
	}

	if(type & 8)
	{
		pMemcpy(buffer + offset_len ,"SYNC:",5);
		offset_len += 5;
		pMemcpy(buffer + offset_len , "telecom/inmsg.vcf\r\n",19);
		offset_len += 19;
	}

	if(type & 16)
	{
		pMemcpy(buffer + offset_len ,"SYNC:",5);
		offset_len += 5;
		pMemcpy(buffer + offset_len , "telecom/outmgs.vcf\r\n",20);
		offset_len += 20;
	}

	if(type & 32)
	{
		pMemcpy(buffer + offset_len ,"SYNC:",5);
		offset_len += 5;
		pMemcpy(buffer + offset_len , "telecom/sentmgs.vcf\r\n",21);
		offset_len += 21;
	}

	if(type & 64)
	{
		pMemcpy(buffer + offset_len ,"SYNC:",5);
		offset_len += 5;
		pMemcpy(buffer + offset_len , "telecom/rtc.vcf\r\n",17);
		offset_len += 17;
	}

	if(!type)
	{
		pMemcpy(buffer + offset_len ,"SYNC:",5);
		offset_len += 5;
		pMemcpy(buffer + offset_len , "default\r\n",9);
		offset_len += 9;
	}

	if(pAny)
	{
		pMemcpy(buffer + offset_len ,"SYNC:",5);
		offset_len += 5;
		pMemcpy(buffer + offset_len , pAny ,length);

		offset_len += length;
		buffer[offset_len++] = '\r';
		buffer[offset_len++] = '\n';
	}


	OBEX_GetWriteBuffer(300,&buff);
	/*
	buff =  (t_DataBuf*)host_buf_alloc(300);
	host_buf_reserve_header((struct host_buf*)buff,20);
*/
	t_offset = 3;
	
	for(lcv = 0; lcv < 33; lcv+=2)
	{
		obj_name[lcv] = 0;
	}

	OBEX_CreateStringHeader(OBEX_NAME,(u_int16)16,(u_int16*)obj_name,buff,&t_offset);
	OBEX_Create4ByteHeader(OBEX_LENGTH,offset_len,buff, &t_offset);
	OBEX_CreateSequenceHeader(OBEX_BODY,offset_len,buffer,buff,&t_offset);
	OBEX_CreateSequenceHeader(OBEX_END_BODY,0,0,buff,&t_offset);

	OBEX_Put(tid_s,0x01,t_offset,buff,handler);

	return BT_NOERROR;
}
Пример #22
0
/***********************************************************************
 *
 * FUNCTION NAME:    OBEX_FindSyncCommandServer
 * DESCRIPTION:


 * KNOWN ISSUES:

 .
 
 *
 *
 ***********************************************************************/
APIDECL1 t_api APIDECL2 OBEX_FindSyncCommandServer(t_bdaddr* address,u_int8* channel)
{
	u_int32 uuid;
	t_SDP_Addresses devs;
	u_int16 criteria;
	t_SDP_SearchPattern pattern;
	t_SDP_AttributeIDs attribs;
	
	t_SDP_StopRule rule;
	
	t_SDP_Results *pResults;
	u_int8* finger;
	u_int8 counter;
	u_int16 aid;
	u_int8 offset_len;
	u_int32 length;
	u_int32 outer;
	u_int32 inner;
	t_SDP_Element *pElement;


	devs.numItems = 1;
	devs.addresses = (t_bdaddr*)pMalloc(sizeof(t_bdaddr));  
	
	devs.addresses[0] = *address;
	
	criteria = SDP_TRUSTED;
	
	/* search pattern */
	
	pattern.numItems = 1;
	pattern.patternUUIDs = (u_int32*)pMalloc(4);
	pattern.patternUUIDs[0] = SDP_SCLASS_UUID_IRMC_COMMAND;
	
	/* attributes to retrieve */
	
	attribs.numItems = 1;
	attribs.attributeIDs = (u_int32*)pMalloc(12);
	attribs.attributeIDs[0] = SDP_AID_PROTOCOL;
	//attribs.attributeIDs[2] = SDP_AID_DATA_STORES;
	
	
	/* stop rule */
	
	rule.maxItems = 100;
	rule.maxDuration = 60;
	rule.maxBytes = 0xf000;
	
	prh_sync_server_lock = pEventCreate(FALSE);
	
	/* call a service search and do not retrieve the device name */
		
	SDP_ServiceBrowse(&pResults,&devs,&pattern,&attribs,&rule,criteria,prh_obex_sync_server_search_callback);    

	
	pEventWait(prh_sync_server_lock);

	if(!pResults->numElements)
	{
		*channel = 0xff;
		return BT_NOERROR;
	}

	pElement = &(pResults->element);


	if(pElement->dataLen == 2)
	{
		*channel = 0xff;
		return BT_NOERROR;
	}

	finger = pElement->pData;

	prh_sync_get_list_length(finger,&length,&offset_len);
	finger+= offset_len;
	prh_sync_get_list_length(finger,&length,&offset_len);
	finger+= offset_len;
	counter = length;
	do {
		counter--;
		finger++; /* bypass type code */
		aid = (finger[0] << 8) + finger[1];
		finger+=2;
		counter-=2;
		switch(aid)
		{
		case SDP_AID_PROTOCOL:
			prh_sync_get_list_length(finger,&length,&offset_len);
			finger += offset_len;
			counter -= offset_len;
			outer = length;
			do {
				do {
					prh_sync_get_list_length(finger,&length,&offset_len);
					finger +=offset_len;
					counter -=offset_len;
					outer -=offset_len;
					inner = length;
					prh_sync_read_uuid(finger,&uuid,&offset_len);
					finger += offset_len;
					counter -= offset_len;
					outer -= offset_len;
					inner -= offset_len;
					if(uuid == SDP_PROTOCOL_UUID_RFCOMM && inner)
					{
						*channel = finger[1];
						finger+=2;
						counter-=2;
						inner-=2;
						outer-=2;
					} else {
						finger += inner;
						counter -= inner;
						outer -= inner;
						inner = 0;
					}					
				} while(inner);
			} while (outer);
			break;	
		default:
			/* I will do this another time */
			break;
		}
	} while (counter);

	return BT_NOERROR;
}
Пример #23
0
void rdabt_SDP_serviceSearch(bt_bm_service_search_req_struct * msg_p)
{

	
	t_SDP_Addresses 		devices;
	t_SDP_SearchPattern  	pattern;
	t_SDP_AttributeIDs  	attributes;
	t_SDP_StopRule 		rule;
	 u_int16 criteria=0;
	t_bdaddr bdAddr;

	u_int32 	cod = 0;

	btbm_bd_addr_t	bd_addr;
	
	kal_prompt_trace(1,"--> rdabt_SDP_serviceSearch");

	BDADDR_Set_LAP(&bdAddr,msg_p ->bd_addr.lap);
	BDADDR_Set_UAP(&bdAddr,msg_p ->bd_addr.uap);
	BDADDR_Set_NAP(&bdAddr,msg_p ->bd_addr.nap);	




	bd_addr = msg_p->bd_addr;

	bth_get_specified_device_class(bd_addr, &cod);

	kal_prompt_trace(1,"--> rdabt_SDP_serviceSearch, cod == %d", cod);
	
	devices.numItems = 1;
	devices.addresses = ( t_bdaddr *)pMalloc(sizeof(t_bdaddr));
	if(devices.addresses)
		devices.addresses[0] = bdAddr;

	pattern.numItems = 1;
	pattern.patternUUIDs = (u_int32*)pMalloc(pattern.numItems*sizeof(u_int32));
	if(pattern.patternUUIDs)
		pattern.patternUUIDs[0] = SDP_PROTOCOL_UUID_L2CAP;

	if(cod & 0x200)
		attributes.numItems = 1;
	else
		attributes.numItems = 4;
	attributes.attributeIDs =(u_int32*)pMalloc(attributes.numItems*sizeof(u_int32));
	if(attributes.attributeIDs)
	{
		attributes.attributeIDs[0] = SDP_AID_SERVICE_CLASS;
		if(!(cod&0x200))
	  	{
	  		attributes.attributeIDs[1] = SDP_AID_PROFILE_LIST;
	 		attributes.attributeIDs[2] = SDP_AID_PROTOCOL;
	 		attributes.attributeIDs[3] = SDP_AID_SUPPORTED_FEATURES;
		}
	}

	rule.maxBytes = 512;
	rule.maxDuration = 50;
	rule.maxItems = 10;

	SDP_ServiceBrowse(&pResults,&devices,&pattern,&attributes,&rule,criteria,(sdp_api_callback)rdabt_ServiceSearch_cb);    

	pFree(devices.addresses);
	pFree(pattern.patternUUIDs);
	pFree(attributes.attributeIDs);


}
Пример #24
0
/***********************************************************************
 *
 * FUNCTION NAME:    OBEX_TransportListen_RF
 * DESCRIPTION:
 
 This function should be generic

 * KNOWN ISSUES:

 none.
 
 *
 *
 ***********************************************************************/
APIDECL1 t_api APIDECL2 OBEX_TransportListen_RF(u_int8 server_channel,u_int32* tid_b, void (*disconnect)(u_int32 tid_s))
{
	struct prh_obex_transport* pTransport;
	u_int8 match = 0;
	
	pTransport = prh_obex_server_transport;
	
	if(!pTransport)
    {
		/* allocate */
		pTransport = pMalloc(sizeof(struct prh_obex_transport));
		
		if(!pTransport)
			return BT_NORESOURCES;
		pTransport->p_next = 0x00;
		prh_obex_server_transport  = pTransport;
		
		goto end; 
    }
	
	/* search for entry */
	
	do {
		if(pTransport->type == 0 && pTransport->use.rfcomm.server_channel == server_channel)
		{
			match = 1;
			break;
		}
		
		if(!pTransport->p_next)
		{
			/* end of list */
			pTransport->p_next = pMalloc(sizeof(struct prh_obex_transport));
			
			if(!pTransport->p_next)
				return BT_NORESOURCES;
			
			pTransport = pTransport->p_next;
			pTransport->p_next = 0x00;
			
			break;
		}    
	} while((pTransport = pTransport->p_next));
	
end:
	
	if(!match)
    {
		/* a new one */      
		pTransport->type = 0;
		pTransport->tid = prh_obex_allocate_tid();
		/*  prh_obex_t_list.rf.address*/
		pTransport->use.rfcomm.server_channel = server_channel;
    } 
	
	pTransport->use.rfcomm.flow_state = PRH_RFCOMM_FLOW_DATA_GO; /* it might not be needed here */
	pTransport->use.rfcomm.disconnect = disconnect;
	prh_obex_tal_rfcomm_reg_port(server_channel);
	
	*tid_b = pTransport->tid;
	
	return BT_NOERROR;
}
Пример #25
0
APIDECL1 t_api APIDECL2 TCS_TLRegister(u_int8 flag, struct st_t_TCS_callbacks *callbacks, t_bdaddr *GWBDAddress, u_int8 connectToGW, void (*callback)(t_api status))
{
	t_api status;
	int i;


#if (PRH_TCS_TERMINAL && PRH_TCS_GATEWAY)
	tcsMode = PRH_TCS_MODE_TERMINAL;
#endif

	
	if( !(PRH_TCS_ENABLE_TCSCORDLESS(flag)) && !(PRH_TCS_ENABLE_TCSBIN(flag)) )
		return BT_INVALIDPARAM;

	/* Use flags to register for TCSBIN and TCSCORDLESS psms */
	if(BT_NOERROR != (status = prh_tcs_init(flag)))
		return status;

	if(BT_NOERROR != (status = prh_tcs_register_connectionCallbacks(prh_tcs_cc_core_TLconnectIndCallback, prh_tcs_cc_core_TLdisconnectIndCallback)))
		return status;

	if(!callbacks)
		return BT_INVALIDPARAM;
	
	/* Currently only allowing one TL instance, so return BT_NORESOURCES */
	if(TCSInstance.callbacks)
		return BT_NORESOURCES;
	
	TCSInstance.callbacks = (struct st_t_TCS_callbacks*)pMalloc(sizeof(struct st_t_TCS_callbacks));
	if(!TCSInstance.callbacks)
		return BT_NORESOURCES;
	pMemcpy(TCSInstance.callbacks, (struct st_t_TCS_callbacks*)callbacks, sizeof(struct st_t_TCS_callbacks));


	if(PRH_TCS_ENABLE_TCSCORDLESS(flag))
	{
		/* For receiving broadcast data from GW */
		status = L2_EnableConnectionlessTraffic(PRH_TCS_PSM_TCSCORDLESS);
        if(status != BT_NOERROR)
        {
            /* 4 now take no action as we still want to continue even though
                we can't get broadcast info. may want to review this when
                a definite scheme (re broadcast)for call setup is in place
                ie if broadcast all the time then no point in continuing here*/
        }

		if(GWBDAddress)
			pMemcpy(&(TCSInstance.GWBDAddress.bytes), GWBDAddress->bytes, 6);
		for(i=0; i<PRH_TCS_MAX_CALLS_PER_DEVICE; i++)
			TCSInstance.callInstance[i] = NULL;

		if(connectToGW)
		{
			if(!callback)
				return BT_INVALIDPARAM;

			registerCompleteCB = callback; 
			/* NULL is passed as callInstance because no call is being initiated */
			prh_tcs_connect_device_control(TCSInstance.GWBDAddress, PRH_TCS_PSM_TCSCORDLESS, NULL, prh_tcs_cc_callback_L2ConnComplete);
			return BT_PENDING;
		}

	}
	return BT_NOERROR;
}
Пример #26
0
int prh_test_rfcomm_pe_connect_port(t_bdaddr remote_bd_addr, prh_t_rfcomm_schan rem_schan, char *pName, prh_t_rfcomm_dlci *dlci, struct prh_rfcomm_pe_port **pe_info_ptr, u_int16 max_frame_size)
{
  struct prh_rfcomm_multi_cb multi_cbs;
  struct prh_rfcomm_dlc_cb dlc_cbs;
  prh_t_rfcomm_dlc_params dlc_params;
  int dbit;
  t_api ret;
  struct prh_rfcomm_l2cap_inst *l2cap_inst;
  void *multi_inst;
  struct prh_rfcomm_pe_port *pe_info;

  /* Allocate memory for pe_info */
  pe_info=(struct prh_rfcomm_pe_port *)pMalloc(sizeof(struct prh_rfcomm_pe_port));
  if (pe_info==pNULL)
    return BT_NORESOURCES;

  pe_info->portname=(char *)pMalloc(pStrlen(pName)+1);
  if (pe_info->portname==pNULL)
    {
      pFree(pe_info);
      return BT_NORESOURCES;
    }

  /* copy in portname */
  pStrcpy(pe_info->portname, pName);
    
  /* Check does a multiplexer to the remote BD Address exist already */
  ret=prh_rfcomm_lookup_l2cap_inst_by_bd_addr(remote_bd_addr, &l2cap_inst);
  if (ret==BT_INVALIDPARAM)
    {
      ret=prh_test_rfcomm_open_multiplexer(remote_bd_addr, &multi_inst);
      if (ret!=BT_NOERROR)
    return ret;
      dbit=1;
    }
  else
    {
      dbit=l2cap_inst->initiating;
      multi_inst=(void *)l2cap_inst;
    }
  
  /* Either Multiplexer is started or we've returned */
  dlc_params.max_frame_size=max_frame_size;
  dlc_params.priority=0;
  
  /* Generate the DLCI from direction and remote server channel */
  pe_info->dlci=*dlci=((!dbit) | (rem_schan<<1));
  pe_info->multi_inst=multi_inst;
  pe_info->flow_sem=pSemCreate(0);
  pe_info->remote_device_addr=remote_bd_addr;
  pe_info->portnum=0;
  pe_info->mode=PRH_PORT_ENT_CLIENT_CONN;
  prh_rfcomm_init_pe_struct(pe_info);
  
  prh_test_rfcomm_dlc_estab(remote_bd_addr, *dlci,multi_inst, &dlc_params);

  pSemLock(test_prh_rfcomm_ms.sem, 0);

  
  pSemFree(test_prh_rfcomm_ms.sem);
  
  if (test_prh_rfcomm_ms.status==PRH_RFCOMM_REFUSE)
    return BT_UNKNOWNERROR;
  else
    {
      prh_rfcomm_pe_add_port_entity(pe_info);
      *pe_info_ptr=pe_info;
      return BT_NOERROR;
    }

}