Ejemplo n.º 1
0
/* ---------------------------------------------------------------------------

    \fn p2p_remain_on_channel
    \brief  API to post the remain on channel command.
    \param  hHal - The handle returned by mac_open.
    \param  sessinId - HDD session ID.
    \param  channel - Channel to remain on channel.
    \param  duration - Duration for which we should remain on channel
    \param  callback - callback function.
    \param  pContext - argument to the callback function
    \return CDF_STATUS

   -------------------------------------------------------------------------------*/
CDF_STATUS p2p_remain_on_channel(tHalHandle hHal, uint8_t sessionId,
				 uint8_t channel, uint32_t duration,
				 remainOnChanCallback callback,
				 void *pContext, uint8_t isP2PProbeReqAllowed,
				 uint32_t scan_id)
{
	CDF_STATUS status = CDF_STATUS_SUCCESS;
	tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
	tSmeCmd *pRemainChlCmd = NULL;
	uint32_t phyMode;

	pRemainChlCmd = sme_get_command_buffer(pMac);
	if (pRemainChlCmd == NULL)
		return CDF_STATUS_E_FAILURE;

	if (SIR_BAND_5_GHZ == get_rf_band(channel)) {
		phyMode = WNI_CFG_PHY_MODE_11A;
	} else {
		phyMode = WNI_CFG_PHY_MODE_11G;
	}

	cfg_set_int(pMac, WNI_CFG_PHY_MODE, phyMode);

	do {
		/* call set in context */
		pRemainChlCmd->command = eSmeCommandRemainOnChannel;
		pRemainChlCmd->sessionId = sessionId;
		pRemainChlCmd->u.remainChlCmd.chn = channel;
		pRemainChlCmd->u.remainChlCmd.duration = duration;
		pRemainChlCmd->u.remainChlCmd.isP2PProbeReqAllowed =
			isP2PProbeReqAllowed;
		pRemainChlCmd->u.remainChlCmd.callback = callback;
		pRemainChlCmd->u.remainChlCmd.callbackCtx = pContext;
		pRemainChlCmd->u.remainChlCmd.scan_id = scan_id;

		/* Put it at the head of the Q if we just finish finding the peer and ready to send a frame */
		status = csr_queue_sme_command(pMac, pRemainChlCmd, false);
	} while (0);

	sms_log(pMac, LOGW, "exiting function %s", __func__);

	return (status);
}
Ejemplo n.º 2
0
static char *mbox_store_literal_inner(char *boxname,
				      char *message, int msglen,
				      char *separator)
{
    int boxnum, need_set;
    int ret, fd;
    struct stat st;
    int maxsize, size;
    off_t oldlen, newlen;

    boxnum = cfg_get_int("current-mbox");
    maxsize = cfg_get_int("mbox-maxsize");

    boxnum--;			       /* to counter first `boxnum++' below */
    need_set = FALSE;
    do {
	boxnum++;
	sprintf(boxname, "%s/mbox%d", dirpath, boxnum);
	if (need_set)
	    cfg_set_int("current-mbox", boxnum);
	need_set = TRUE;

	/*
	 * See if our current mbox has space in it.
	 */
	ret = stat(boxname, &st);
	if (ret < 0) {
	    if (errno == ENOENT)
		size = 0;	       /* current mbox is empty */
	    else {
		error(err_perror, boxname, "stat");
		return NULL;	       /* failed to store message */
	    }
	} else
	    size = st.st_size;
	/*
	 * Special case: a single message that's too big always goes in
	 * its own mbox.
	 */
    } while (size > 0 && size + msglen > maxsize);

    /*
     * So now we know which mbox it's going into. Open the mbox and
     * put it there.
     */
    fd = open(boxname, O_RDWR | O_CREAT, 0600);
    if (fd < 0) {
	error(err_perror, boxname, "open");
	return NULL;		       /* failed to store message */
    }
    oldlen = lseek(fd, 0, SEEK_END);
    if (oldlen < 0) {
	error(err_perror, boxname, "lseek");
	return NULL;		       /* failed to store message */
    }

    /*
     * Invent a `From ' line if there isn't one already.
     */
    if (!separator || strncmp(separator, "From ", 5)) {
	char fromline[80];
	struct tm tm;
	time_t t;

	t = time(NULL);
	tm = *gmtime(&t);
	strftime(fromline, 80,
		 "From timber-mbox-storage %a %b %d %H:%M:%S %Y\n", &tm);

	if (!write_wrapped(fd, fromline, strlen(fromline))) {
	    if (ftruncate(fd, oldlen) < 0)
		error(err_perror, boxname, "ftruncate");
	    return NULL;
	}
    } else {
	if (!write_wrapped(fd, separator, strlen(separator)) ||
	    !write_wrapped(fd, "\n", 1)) {
	    if (ftruncate(fd, oldlen) < 0)
		error(err_perror, boxname, "ftruncate");
	    return NULL;
	}
    }

    /*
     * Now write the message.
     */
    if (!write_mbox(fd, message, msglen)) {
	if (ftruncate(fd, oldlen) < 0)
	    error(err_perror, boxname, "ftruncate");
	return NULL;
    }

    /*
     * Find out where we ended up.
     */
    newlen = lseek(fd, 0, SEEK_CUR);
    if (newlen < 0) {
	error(err_perror, boxname, "lseek");
	return NULL;		       /* failed to store message */
    }

    /*
     * Done. Sync and close the mbox, then return success.
     */
    if (!nosync && fsync(fd) < 0) {
	error(err_perror, boxname, "fsync");
	if (ftruncate(fd, oldlen) < 0)
	    error(err_perror, boxname, "ftruncate");
	return NULL;
    }
    if (close(fd) < 0) {
	error(err_perror, boxname, "close");
	if (ftruncate(fd, oldlen) < 0)
	    error(err_perror, boxname, "ftruncate");
	return NULL;
    }

    /*
     * Construct a string telling us where the message is kept.
     */
    {
	char *ret;
	ret = snewn(80, char);
	sprintf(ret, "mbox%d:%d:%d",
		boxnum, (int)oldlen, (int)(newlen - oldlen));
	return ret;
    }
}