Esempio n. 1
0
void
FroniusSimulator::readInterfaceCardHeader(
    unsigned char* buffer,
    unsigned char numBytesToRead)
{
    CHECK_PTR(buffer);

    switch (command_)
    {
    case FRONIUS_CMD_GET_VERSION:
        assert(numBytesToRead == NUM_ELEMS(GetVersionHeader));
        memcpy(buffer, GetVersionHeader, numBytesToRead);
        break;
    case FRONIUS_CMD_GET_ACTIVE_INVERTER_NUMBERS:
        assert(numBytesToRead ==
               NUM_ELEMS(GetActiveInverterNumbersHeader));
        memcpy(buffer, GetActiveInverterNumbersHeader, numBytesToRead);
        break;
    default:
        Args::dieMessage(
            Args::ExitSimulatorError,
            "Simulator: unsupported Interface Card Command: 0x%x\n",
            command_);
        break;
    }
}
Esempio n. 2
0
void
FroniusSimulator::readInterfaceCardData(
    unsigned char* buffer,
    unsigned char numBytesToRead)
{
    CHECK_PTR(buffer);

    if (command_ == FRONIUS_CMD_GET_VERSION)
    {
        assert(numBytesToRead == NUM_ELEMS(GetVersionData));
        memcpy(buffer, GetVersionData, numBytesToRead);

    }
    else if (command_ == FRONIUS_CMD_GET_ACTIVE_INVERTER_NUMBERS)
    {
        assert(numBytesToRead ==
               NUM_ELEMS(GetActiveInverterNumbersData));
        memcpy(buffer, GetActiveInverterNumbersData, numBytesToRead);
    }
    else
    {
        Args::dieMessage(
            Args::ExitSimulatorError,
            "Simulator: unsupported Interface Card Command: 0x%x\n",
            command_);
    }
}
Esempio n. 3
0
// customization for mediatek modem
static int isFinalResponseErrorEx(const char *line, RILChannelCtx *p_channel)
{
    size_t i;

#ifdef  MTK_GEMINI
    int j=0;
    for(j=0; j<MTK_GEMINI_SIM_NUM; j++){
        if( (p_channel->id == RIL_URC+j*RIL_CHANNEL_OFFSET) && (strStartsWith(line, "NO CARRIER")) ){
            // [ALPS01225455]NO CARRIER in URC channel is URC, not final response for mediatek modem
            return 0;
        }
    }
#else
    if( (p_channel->id == RIL_URC) && (strStartsWith(line, "NO CARRIER")) ){
        // [ALPS01225455]NO CARRIER in URC channel is URC, not final response for mediatek modem
        return 0;
    }
#endif

    for (i = 0; i < NUM_ELEMS(s_finalResponsesError); i++) {
        if (strStartsWith(line, s_finalResponsesError[i])) {
            return 1;
        }
    }
    return 0;
}
Esempio n. 4
0
static void update_shell_folder_listview(HWND dialog) {
    int i;
    LVITEMW item;
    LONG lSelected = SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_GETNEXTITEM, -1,
                                        MAKELPARAM(LVNI_SELECTED,0));

    SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_DELETEALLITEMS, 0, 0);

    for (i=0; i<NUM_ELEMS(asfiInfo); i++) {
        WCHAR buffer[MAX_PATH];
        HRESULT hr;
        LPITEMIDLIST pidlCurrent;

        /* Some acrobatic to get the localized name of the shell folder */
        hr = SHGetFolderLocation(dialog, asfiInfo[i].nFolder, NULL, 0, &pidlCurrent);
        if (SUCCEEDED(hr)) { 
            LPSHELLFOLDER psfParent;
            LPCITEMIDLIST pidlLast;
            hr = SHBindToParent(pidlCurrent, &IID_IShellFolder, (LPVOID*)&psfParent, &pidlLast);
            if (SUCCEEDED(hr)) {
                STRRET strRet;
                hr = IShellFolder_GetDisplayNameOf(psfParent, pidlLast, SHGDN_FORADDRESSBAR, &strRet);
                if (SUCCEEDED(hr)) {
                    hr = StrRetToBufW(&strRet, pidlLast, buffer, MAX_PATH);
                }
                IShellFolder_Release(psfParent);
            }
            ILFree(pidlCurrent);
        }

        /* If there's a dangling symlink for the current shell folder, SHGetFolderLocation
         * will fail above. We fall back to the (non-verified) path of the shell folder. */
        if (FAILED(hr)) {
            hr = SHGetFolderPathW(dialog, asfiInfo[i].nFolder|CSIDL_FLAG_DONT_VERIFY, NULL,
                                 SHGFP_TYPE_CURRENT, buffer);
        }
    
        item.mask = LVIF_TEXT | LVIF_PARAM;
        item.iItem = i;
        item.iSubItem = 0;
        item.pszText = buffer;
        item.lParam = (LPARAM)&asfiInfo[i];
        SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_INSERTITEMW, 0, (LPARAM)&item);

        item.mask = LVIF_TEXT;
        item.iItem = i;
        item.iSubItem = 1;
        item.pszText = strdupU2W(asfiInfo[i].szLinkTarget);
        SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_SETITEMW, 0, (LPARAM)&item);
        HeapFree(GetProcessHeap(), 0, item.pszText);
    }

    /* Ensure that the previously selected item is selected again. */
    if (lSelected >= 0) {
        item.mask = LVIF_STATE;
        item.state = LVIS_SELECTED;
        item.stateMask = LVIS_SELECTED;
        SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_SETITEMSTATE, lSelected, (LPARAM)&item);
    }
}
Esempio n. 5
0
eng_cmd_type eng_cmd_get_type(int cmd)
{
    if (cmd <= NUM_ELEMS(eng_linuxcmd))
        return eng_linuxcmd[cmd].type;
    else
        return CMD_INVALID_TYPE;
}
Esempio n. 6
0
const char *rfh_toktype_to_s(rfh_toktype_t toktype)
{
    static struct
    {
        rfh_toktype_t toktype;
        const char *str;
    } toktype_map[] = 
    {
        ENUM_TUPLE(TT_TOKEN),
        ENUM_TUPLE(TT_UNESCAPED_QUOTE),
        ENUM_TUPLE(TT_ILLEGAL_QUOTE),
        ENUM_TUPLE(TT_UNEXPECTED_EOS),
        ENUM_TUPLE(TT_TOKEN_TRUNCATED),
        ENUM_TUPLE(TT_INTERNAL_ERROR),
        ENUM_TUPLE(TT_ALLOC_FAILURE),
        ENUM_TUPLE(TT_END),
    };

    size_t i;

    for (i = 0; i < NUM_ELEMS(toktype_map); ++i)
        if (toktype_map[i].toktype == toktype)
            return toktype_map[i].str;

    return "";
}
static void
check_event_1 (void)
{
  static const char *NORMAL_ARGV[] =
    {
      "testlwes-event-counting-listener",
      "-m", TEST_LLOG_ADDRESS,
      "-p", TEST_LLOG_PORT,
      "-i", TEST_LLOG_INTERFACE,
    };
  static int NORMAL_ARGC = NUM_ELEMS (NORMAL_ARGV);

  /* this will totally not work if the order changes, or the SenderPort
     SenderIP or ReceiptTime are not the lengths represented here */
  const char *output =
    "TypeChecker[12]\n"
    "{\n"
    "\tanIPAddress = 224.0.0.100;\n"
    "\tanInt16 = -1;\n"
    "\tanInt64 = -1;\n"
    "\tReceiptTime = \1\1\1\1\1\1\1\1\1\1\1\1\1;\n"
    "\tSenderIP = \1\1\1\1\1\1\1\1\1;\n"
    "\taUInt32 = 4294967295;\n"
    "\taUInt16 = 65535;\n"
    "\taUInt64 = 18446744073709551615;\n"
    "\tSenderPort = \1\1\1\1\1;\n"
    "\taBoolean = true;\n"
    "\taString = \"http://www.test.com\";\n"
    "\tanInt32 = -1;\n"
    "}\n";

  fork_and_wait (NORMAL_ARGC, NORMAL_ARGV, 500, TRUE, TRUE, TRUE, output, NULL);
}
Esempio n. 8
0
int eng_linuxcmd_hdlr(int cmd, char *req, char* rsp)
{
    if(cmd >= (int)NUM_ELEMS(eng_linuxcmd)) {
        ENG_LOG("%s: no handler for cmd%d",__FUNCTION__, cmd);
        return -1;
    }
    return eng_linuxcmd[cmd].cmd_hdlr(req, rsp);
}
Esempio n. 9
0
static int test_full() {
	char *spec[] = {
		"10s:1m",
		"1m:5m",
	};
	TEST(murmur_create(PATH, NUM_ELEMS(spec), spec, agg_average, 0) == 0);
	
	struct murmur *mmr = murmur_open(PATH);
	TEST(mmr != NULL);
	
	mmr_test_time = 1000;
	
	double val = 100;
	time_t at = mmr_test_time;
	for (int i = 0; i < 6; i++) {
		TEST(murmur_set(mmr, at, val) == 0);
		val += 100;
		at -= 10;
	}
	
	// Start at 1: don't overwrite the propogated value from above
	// Go to 5: we only store 5 minutes of backlog
	for (int i = 1; i < 5; i++) {
		TEST(murmur_set(mmr, at, val) == 0);
		val += 100;
		at -= 60;
	}
	
	// This little bit of maths finds the highest timestamp that
	// will be contained in the archive given that we started at 1000.
	//
	// In reality, murmur won't let us go past the current timestamp, but
	// ignore that crap for testing purposes.
	//
	// Basically, the math reads:
	//   1) To find the start, we need to know where the intervals line up: 1000%60
	//   2) That's the distance we are from the start of this interval,
	//      but we need to get to the start of the NEXT interval, and were already ans
	//      seconds into this interval, so that start is: 60-ans
	//   3) Add our base time back in: 1000+ans
	//   4) That puts us at the start of the next interval, to get to the end of ours: ans-1
	at = (1000+(60-(1000%60)))-1;
	
	for (int i = 0; i < 5; i++) {
		M_INFO("------------");
		for (int j = 0; j < 6; j++) {
			TEST(_murmur_arch_get(mmr, mmr->archives + 1, at, &val) == 0);
			M_INFO("@%ld = %f", at, val);
			at -= 10;
		}
	}
	
	murmur_close(mmr);
	
	return 0;
}
Esempio n. 10
0
static int isSMSUnsolicited(const char *line)
{
	size_t i;
	for (i = 0; i < NUM_ELEMS(s_smsUnsoliciteds); i++) {
		if (strStartsWith(line, s_smsUnsoliciteds[i])) {
			return 1;
        }
	}
	return 0;
}
Esempio n. 11
0
static int isIntermediatePattern(const char *line)
{
	size_t i;
	for (i = 0; i < NUM_ELEMS(s_IntermediatePattern); i++) {
		if (!strcmp(line, s_IntermediatePattern[i])) {
			return 1;
                                }
	}
	return 0;
}
Esempio n. 12
0
static int isFinalResponseSuccess(const char *line)
{
	size_t i;
	for (i = 0; i < NUM_ELEMS(s_finalResponsesSuccess); i++) {
		if (strStartsWith(line, s_finalResponsesSuccess[i])) {
			return 1;
        }
	}
	return 0;
}
Esempio n. 13
0
static void apply_shell_folder_changes(void) {
    WCHAR wszPath[MAX_PATH];
    char szBackupPath[FILENAME_MAX], szUnixPath[FILENAME_MAX], *pszUnixPath = NULL;
    int i;
    struct stat statPath;
    HRESULT hr;

    for (i=0; i<NUM_ELEMS(asfiInfo); i++) {
        /* Ignore nonexistent link targets */
        if (asfiInfo[i].szLinkTarget[0] && stat(asfiInfo[i].szLinkTarget, &statPath))
            continue;
        
        hr = SHGetFolderPathW(NULL, asfiInfo[i].nFolder|CSIDL_FLAG_CREATE, NULL, 
                              SHGFP_TYPE_CURRENT, wszPath);
        if (FAILED(hr)) continue;

        /* Retrieve the corresponding unix path. */
        pszUnixPath = wine_get_unix_file_name(wszPath);
        if (!pszUnixPath) continue;
        lstrcpyA(szUnixPath, pszUnixPath);
        HeapFree(GetProcessHeap(), 0, pszUnixPath);
            
        /* Derive name for folder backup. */
        lstrcpyA(szBackupPath, szUnixPath);
        lstrcatA(szBackupPath, ".winecfg");
        
        if (lstat(szUnixPath, &statPath)) continue;
    
        /* Move old folder/link out of the way. */
        if (S_ISLNK(statPath.st_mode)) {
            if (unlink(szUnixPath)) continue; /* Unable to remove link. */
        } else { 
            if (!*asfiInfo[i].szLinkTarget) {
                continue; /* We are done. Old was real folder, as new shall be. */
            } else { 
                if (rename(szUnixPath, szBackupPath)) { /* Move folder out of the way. */
                    continue; /* Unable to move old folder. */
                }
            }
        }
    
        /* Create new link/folder. */
        if (*asfiInfo[i].szLinkTarget) {
            symlink(asfiInfo[i].szLinkTarget, szUnixPath);
        } else {
            /* If there's a backup folder, restore it. Else create new folder. */
            if (!lstat(szBackupPath, &statPath) && S_ISDIR(statPath.st_mode)) {
                rename(szBackupPath, szUnixPath);
            } else {
                mkdir(szUnixPath, 0777);
            }
        }
    }
}
Esempio n. 14
0
static void
check_opt_help (void)
{
  static const char *HELP_ARGV[] =
    {
      "testlwes-event-testing-emitter", "-h",
    };
  static int HELP_ARGC = NUM_ELEMS (HELP_ARGV);

  fork_and_wait (HELP_ARGC, HELP_ARGV, 500, TRUE, FALSE, TRUE, NULL, help);
}
Esempio n. 15
0
static int isFinalResponseSuccess(const char *line)
{
    size_t i;

    for (i = 0 ; i < NUM_ELEMS(s_finalResponsesSuccess) ; i++) {
        if (!line[1] && line[0] == s_finalResponsesSuccess[i][0]) {
            return 1;
        }
    }

    return 0;
}
Esempio n. 16
0
static void
check_opt_bad (void)
{
  static const char *BOGUS_ARGV[] =
    {
      "testlwes-event-testing-emitter", "-z",
    };
  static int BOGUS_ARGC = NUM_ELEMS (BOGUS_ARGV);

  const char *error =
    "error: unrecognized command line option -z\n";

  fork_and_wait (BOGUS_ARGC, BOGUS_ARGV, 500, TRUE, FALSE, TRUE, NULL, error);
}
Esempio n. 17
0
/**
 * RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG
 */
void requestGSMSetBroadcastSMSConfig(void *data, size_t datalen,
                                     RIL_Token t)
{
    ATResponse *atresponse = NULL;
    int err, count, i;
    char *cmd, *tmp, *mids = NULL;
    RIL_GSM_BroadcastSmsConfigInfo **configInfoArray =
        (RIL_GSM_BroadcastSmsConfigInfo **) data;
    RIL_GSM_BroadcastSmsConfigInfo *configInfo = NULL;

    count = NUM_ELEMS(configInfoArray);
    LOGI("Number of MID ranges in BROADCAST_SMS_CONFIG: %d", count);

    for (i = 0; i < count; i++) {
        configInfo = configInfoArray[i];
        /* No support for "Not accepted mids" in AT */
        if (configInfo->selected) {
            tmp = mids;
            asprintf(&mids, "%s%d-%d%s", (tmp ? tmp : ""),
                configInfo->fromServiceId, configInfo->toServiceId,
                (i == (count - 1) ? "" : ",")); /* Last one? Skip comma */
            free(tmp);
        }
    }

    if (mids == NULL)
        goto error;

    asprintf(&cmd, "AT+CSCB=0,\"%s\"", mids);
    free(mids);

    err = at_send_command(cmd, &atresponse);
    free(cmd);

    if (err < 0 || atresponse->success == 0)
        goto error;

    RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
    goto exit;

error:
    RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);

exit:
    at_response_free(atresponse);
}
static void
check_opt_bad (void)
{
  static const char *BOGUS_ARGV[] =
    {
      "testlwes-event-printing-listener", "-z",
    };
  static int BOGUS_ARGC = NUM_ELEMS (BOGUS_ARGV);

  const char *error =
    "error: unrecognized command line option -z\n";

  /* It seems strange that lwes-event-printing-listener is supposed
     to go ahead and run when it gets a bad command-line argument,
     but that's the current behavior: */
  fork_and_wait (BOGUS_ARGC, BOGUS_ARGV, 500, TRUE, FALSE, TRUE, NULL, error);
}
Esempio n. 19
0
int eng_at2linux(char *buf)
{
    int ret=-1;
    int i;

    for (i = 0 ; i < (int)NUM_ELEMS(eng_linuxcmd) ; i++) {
        if (strcasestr(buf, eng_linuxcmd[i].name)!=NULL) {
            ENG_LOG("eng_at2linux %s",eng_linuxcmd[i].name);
			if((strcasestr(buf,"AT+TEMPTEST")) && ((strcasestr(buf, "AT+TEMPTEST=1,0,1"))||(strcasestr(buf, "AT+TEMPTEST=1,1,1"))
						||(strcasestr(buf, "AT+TEMPTEST=1,0,4"))||(strcasestr(buf, "AT+TEMPTEST=1,1,4"))))
				return -1;
			else
				return i;
        }
    }

    return ret;
}
Esempio n. 20
0
const char*
Interface::getModel(void) const
{
	unsigned int	i;
	unsigned char	interfaceType;

	interfaceType = versionResponse_.getInterfaceType();

	for (i = 0; i < NUM_ELEMS(interfaceTypeMap); i++)
	{
		if (interfaceTypeMap[i].id == interfaceType)
		{
			return interfaceTypeMap[i].model;
		}
	}

	return "unknown interface type";
}
Esempio n. 21
0
static void
check_event_1 (void)
{
  static const char *NORMAL_ARGV[] =
    {
      "testlwes-event-testing-emitter",
      "-m", TEST_LLOG_ADDRESS,
      "-p", TEST_LLOG_PORT,
      "-i", TEST_LLOG_INTERFACE,
    };
  static int NORMAL_ARGC = NUM_ELEMS (NORMAL_ARGV);

  /* this will totally not work if the order changes, or the SenderPort
     SenderIP or ReceiptTime are not the lengths represented here */
  const char *output =
    "\1\1:\1\1:\1\1 \1\1/\1\1/\1\1\1\1 :       1\n";

  fork_and_wait (NORMAL_ARGC, NORMAL_ARGV, 100000, TRUE, TRUE, TRUE, output, NULL);
}
Esempio n. 22
0
static int isFinalResponseError(const char *line)
{
    size_t i;

    for (i = 0 ; i < NUM_ELEMS(s_finalResponsesError) ; i++) {
        if ((line[0] == '+' && s_finalResponsesError[i][1] &&
            strStartsWith(line, s_finalResponsesError[i])) ||
            (line[1] == '\0' && line[0] == s_finalResponsesError[i][0]))
        {
            if (i == 3) {    /* BUSY */
                s_last_cme_error = CME_PHONE_BUSY;
            } else
            if (i == 6) {    /* CME ERROR */
                s_last_cme_error = atoi(line+sizeof("+CME ERROR:"));
            }
            return 1;
        }
    }

    return 0;
}
Esempio n. 23
0
/* Reads the currently set shell folder symbol link targets into asfiInfo. */
static void read_shell_folder_link_targets(void) {
    WCHAR wszPath[MAX_PATH];
    HRESULT hr;
    int i;
   
    for (i=0; i<NUM_ELEMS(asfiInfo); i++) {
        asfiInfo[i].szLinkTarget[0] = '\0';
        hr = SHGetFolderPathW(NULL, asfiInfo[i].nFolder|CSIDL_FLAG_DONT_VERIFY, NULL, 
                              SHGFP_TYPE_CURRENT, wszPath);
        if (SUCCEEDED(hr)) {
            char *pszUnixPath = wine_get_unix_file_name(wszPath);
            if (pszUnixPath) {
                struct stat statPath;
                if (!lstat(pszUnixPath, &statPath) && S_ISLNK(statPath.st_mode)) {
                    int cLen = readlink(pszUnixPath, asfiInfo[i].szLinkTarget, FILENAME_MAX-1);
                    if (cLen >= 0) asfiInfo[i].szLinkTarget[cLen] = '\0';
                }
                HeapFree(GetProcessHeap(), 0, pszUnixPath);
            }
        } 
    }    
}
Esempio n. 24
0
static const char *rfh_state_to_s(state_t state)
{
    static struct
    {
        state_t state;
        const char *str;
    } state_map[] = 
    {
        ENUM_TUPLE(ST_INITIAL),
        ENUM_TUPLE(ST_IN_QUOTED_ID),
        ENUM_TUPLE(ST_IN_UNQUOTED_ID),
        ENUM_TUPLE(ST_END),
    };

    size_t i;

    for (i = 0; i < NUM_ELEMS(state_map); ++i)
        if (state_map[i].state == state)
            return state_map[i].str;

    return "";
}
Esempio n. 25
0
static int test_high_precision_full() {
	char *spec[] = {
		"10s:1m",
		"1m:5m",
	};
	TEST(murmur_create(PATH, NUM_ELEMS(spec), spec, agg_average, 0) == 0);
	
	struct murmur *mmr = murmur_open(PATH);
	TEST(mmr != NULL);
	
	// So that the archive doesn't wrap and everything is
	// aggregated into 1 lower-precision point
	mmr_test_time = (mmr->archives->retention * 5) - 10;
	
	double val = 100;
	time_t at = mmr_test_time;
	for (int i = 0; i < 6; i++) {
		TEST(murmur_set(mmr, at, val) == 0);
		val += 100;
		at -= 10;
	}
	
	at = mmr_test_time;
	for (int i = 0; i < 6; i++) {
		TEST(murmur_get(mmr, at, &val) == 0);
		TEST(val == (100 + (i * 100)));
		at -= 10;
	}
	
	TEST(_murmur_arch_get(mmr, mmr->archives + 1, mmr_test_time, &val) == 0);
	TEST(val == (((double)100+200+300+400+500+600)/6));
	
	murmur_close(mmr);
	
	return 0;
}
Esempio n. 26
0
static int test_sane() {
	char *spec[] = {
		"10s:1m",
		"1m:5m",
	};
	TEST(murmur_create(PATH, NUM_ELEMS(spec), spec, agg_average, 0) == 0);
	
	struct murmur *mmr = murmur_open(PATH);
	TEST(mmr != NULL);
	
	mmr_test_time = 1000;
	
	double val = 100;
	TEST(murmur_set(mmr, mmr_test_time, val) == 0);
	TEST(murmur_get(mmr, mmr_test_time, &val) == 0);
	TEST(val == 100);
	
	TEST(_murmur_arch_get(mmr, mmr->archives + 1, mmr_test_time, &val) == 0);
	TEST(val == (((double)100)/6));
	
	murmur_close(mmr);
	
	return 0;
}
Esempio n. 27
0
static void
check_opt_c_and_q (void)
{
  static const char *NORMAL_ARGV[] =
    {
      "testlwes-event-counting-listener",
      "-c",
      "-q",
      "-m", TEST_LLOG_ADDRESS,
      "-p", TEST_LLOG_PORT,
      "-i", TEST_LLOG_INTERFACE,
    };
  static int NORMAL_ARGC = NUM_ELEMS (NORMAL_ARGV);

  /* this may prove to be a flakey test, we are trying to wait for one second
     using the usleep() calls in fork_and_wait, keeping fingers crossed this
     will work on different platforms */
  const char *output =
    "\1\1:\1\1:\1\1 \1\1/\1\1/\1\1\1\1 : 1\n"
    ;

  fork_and_wait (NORMAL_ARGC, NORMAL_ARGV, 90000,
                 TRUE, TRUE, TRUE, output, NULL);
}
Esempio n. 28
0
static void process_opt( int *parg, int argc, char *argv[] )
{
#define II (*parg)
    int		 j;
    char	*opt_arg_ptr;

    /* search opts_lu[] */
    for ( j = 0; j < NUM_ELEMS( opts_lu ); j++ )
    {
        if ( ( opt_arg_ptr = check_option( argv[II], opts_lu[j].long_opt ) ) != NULL ||
                ( opt_arg_ptr = check_option( argv[II], opts_lu[j].short_opt ) ) != NULL )
        {
            /* found option, opt_arg_ptr points to after option */
            switch ( opts_lu[j].type )
            {
            case OptClear:
                if ( *opt_arg_ptr )
                    error_illegal_option( argv[II] );
                else
                    *( ( Bool * )( opts_lu[j].arg ) ) = FALSE;

                break;

            case OptSet:
                if ( *opt_arg_ptr )
                    error_illegal_option( argv[II] );
                else
                    *( ( Bool * )( opts_lu[j].arg ) ) = TRUE;

                break;

            case OptCall:
                if ( *opt_arg_ptr )
                    error_illegal_option( argv[II] );
                else
                    ( ( void ( * )( void ) )( opts_lu[j].arg ) )();

                break;

            case OptCallArg:
                if ( *opt_arg_ptr )
                    ( ( void ( * )( char * ) )( opts_lu[j].arg ) )( opt_arg_ptr );
                else
                    error_illegal_option( argv[II] );

                break;

            case OptCallOptArg:
                ( ( void ( * )( char * ) )( opts_lu[j].arg ) )( opt_arg_ptr );
                break;

            case OptString:
                if ( *opt_arg_ptr )
                    *( ( char ** )( opts_lu[j].arg ) ) = opt_arg_ptr;
                else
                    error_illegal_option( argv[II] );

                break;

            case OptStringList:
				if (*opt_arg_ptr)
				{
					UT_array **p_path = (UT_array **)opts_lu[j].arg;
					utarray_push_back(*p_path, &opt_arg_ptr);
				}
                else
                    error_illegal_option( argv[II] );

                break;

            case OptDeprecated:
                if ( *opt_arg_ptr )
                    *opt_arg_ptr = '\0';		/* delete option argument for warning message */

                warn_option_deprecated( argv[II] );
                break;

            default:
                assert(0);
            }

            return;
        }
    }

    /* not found */
    error_illegal_option( argv[II] );

#undef II
}
Esempio n. 29
0
void 
do_load(int argc, char *argv[])
{
    int res, num_options;
    int i, err;
    bool verbose, raw;
    bool base_addr_set, mode_str_set;
    char *mode_str;
#ifdef CYGPKG_REDBOOT_NETWORKING
    struct sockaddr_in host;
    bool hostname_set, port_set;
    unsigned int port;	// int because it's an OPTION_ARG_TYPE_NUM, 
                        // but will be cast to short
    char *hostname;
#endif
#ifdef CYGBLD_REDBOOT_LOAD_INTO_FLASH
    bool flash_addr_set = false;
#endif
    bool decompress = false;
    int chan = -1;
#if CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS > 1
    bool chan_set;
#endif
    unsigned long base = 0;
    unsigned long end = 0;
    char type[4];
    char *filename = 0;
    struct option_info opts[9];
    connection_info_t info;
    getc_io_funcs_t *io = NULL;
    struct load_io_entry *io_tab;
#ifdef CYGSEM_REDBOOT_VALIDATE_USER_RAM_LOADS
    bool spillover_ok = false;
#endif

#ifdef CYGPKG_REDBOOT_NETWORKING
    memset((char *)&host, 0, sizeof(host));
    host.sin_len = sizeof(host);
    host.sin_family = AF_INET;
    host.sin_addr = my_bootp_info.bp_siaddr;
    host.sin_port = 0;
#endif

    init_opts(&opts[0], 'v', false, OPTION_ARG_TYPE_FLG, 
              (void *)&verbose, 0, "verbose");
    init_opts(&opts[1], 'r', false, OPTION_ARG_TYPE_FLG, 
              (void *)&raw, 0, "load raw data");
    init_opts(&opts[2], 'b', true, OPTION_ARG_TYPE_NUM, 
              (void *)&base, (bool *)&base_addr_set, "load address");
    init_opts(&opts[3], 'm', true, OPTION_ARG_TYPE_STR, 
              (void *)&mode_str, (bool *)&mode_str_set, "download mode (TFTP, xyzMODEM, or disk)");
    num_options = 4;
#if CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS > 1
    init_opts(&opts[num_options], 'c', true, OPTION_ARG_TYPE_NUM, 
              (void *)&chan, (bool *)&chan_set, "I/O channel");
    num_options++;
#endif
#ifdef CYGPKG_REDBOOT_NETWORKING
    init_opts(&opts[num_options], 'h', true, OPTION_ARG_TYPE_STR, 
              (void *)&hostname, (bool *)&hostname_set, "host name or IP address");
    num_options++;
    init_opts(&opts[num_options], 'p', true, OPTION_ARG_TYPE_NUM, 
              (void *)&port, (bool *)&port_set, "TCP port");
    num_options++;
#endif
#ifdef CYGBLD_BUILD_REDBOOT_WITH_ZLIB
    init_opts(&opts[num_options], 'd', false, OPTION_ARG_TYPE_FLG, 
              (void *)&decompress, 0, "decompress");
    num_options++;
#endif
#ifdef CYGBLD_REDBOOT_LOAD_INTO_FLASH
    init_opts(&opts[num_options], 'f', true, OPTION_ARG_TYPE_NUM,
              (void *)&base, (bool *)&flash_addr_set, "flash address");
    num_options++;
#endif
    CYG_ASSERT(num_options <= NUM_ELEMS(opts), "Too many options");
    
    if (!scan_opts(argc, argv, 1, opts, num_options, 
                   (void *)&filename, OPTION_ARG_TYPE_STR, "file name")) {
        return;
    }
#ifdef CYGPKG_REDBOOT_NETWORKING
    if (hostname_set) {
        ip_route_t rt;
        if (!_gethostbyname(hostname, (in_addr_t *)&host)) {
            err_printf("Invalid host: %s\n", hostname);
            return;
        }
        /* check that the host can be accessed */
        if (__arp_lookup((ip_addr_t *)&host.sin_addr, &rt) < 0) {
            err_printf("Unable to reach host %s (%s)\n",
                        hostname, inet_ntoa((in_addr_t *)&host));
            return;
        }
    }
    if (port_set) 
	    host.sin_port = port;
#endif
    if (chan >= CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS) {
        err_printf("Invalid I/O channel: %d\n", chan);
        return;
    }
    if (mode_str_set) {
        for (io_tab = __RedBoot_LOAD_TAB__; 
             io_tab != &__RedBoot_LOAD_TAB_END__;  io_tab++) {
            if (strncasecmp(&mode_str[0], io_tab->name, strlen(&mode_str[0])) == 0) {
                io = io_tab->funcs;
                break;
            }
        }
        if (!io) {
            diag_printf("Invalid 'mode': %s.  Valid modes are:", mode_str);
            for (io_tab = __RedBoot_LOAD_TAB__; 
                 io_tab != &__RedBoot_LOAD_TAB_END__;  io_tab++) {
                diag_printf(" %s", io_tab->name);
            }
            err_printf("\n");
        }
        if (!io) {
            return;
        }
        verbose &= io_tab->can_verbose;
        if (io_tab->need_filename && !filename) {
            diag_printf("File name required\n");
            err_printf("usage: load %s\n", usage);
            return;
        }
    } else {
        char *which = "";
        io_tab = (struct load_io_entry *)NULL;  // Default
#ifdef CYGPKG_REDBOOT_NETWORKING
#ifdef CYGSEM_REDBOOT_NET_TFTP_DOWNLOAD        
        which = "TFTP";
        io = &tftp_io;
#elif defined(CYGSEM_REDBOOT_NET_HTTP_DOWNLOAD)
        which = "HTTP";
        io = &http_io;
#endif
#endif
#if 0 //def CYGPKG_REDBOOT_FILEIO
        // Make file I/O default if mounted
	if (fileio_mounted) {
	    which = "file";
	    io = &fileio_io;
	}
#endif
        if (!io) {
#ifdef CYGBLD_BUILD_REDBOOT_WITH_XYZMODEM
            which = "Xmodem";
            io = &xyzModem_io;
            verbose = false;
#else
            err_printf("No default protocol!\n");
            return;
#endif
        }
        diag_printf("Using default protocol (%s)\n", which);
    }
#ifdef CYGSEM_REDBOOT_VALIDATE_USER_RAM_LOADS
#ifdef  CYGBLD_REDBOOT_LOAD_INTO_FLASH
    if (flash_addr_set && flash_verify_addr((unsigned char *)base)) {
        if (!verify_action("Specified address (%p) is not believed to be in FLASH", (void*)base))
          return;
        spillover_ok = true;
    }
#endif
    if (base_addr_set && !valid_address((unsigned char *)base)) {
        if (!verify_action("Specified address (%p) is not believed to be in RAM", (void*)base))
            return;
        spillover_ok = true;
    }
#endif
    if (raw && !(base_addr_set 
#ifdef CYGBLD_REDBOOT_LOAD_INTO_FLASH
                || flash_addr_set
#endif
        )) {
        err_printf("Raw load requires a memory address\n");
        return;
    }
    info.filename = filename;
    info.chan = chan;
    info.mode = io_tab ? io_tab->mode : 0;
#ifdef CYGPKG_REDBOOT_NETWORKING
    info.server = &host;
#endif
    res = redboot_getc_init(&info, io, verbose, decompress);
    if (res < 0) {
        return;
    }
#ifdef CYGBLD_REDBOOT_LOAD_INTO_FLASH
    flash_load_start();
#endif
    // Stream open, process the data
    if (raw) {
        unsigned char *mp = (unsigned char *)base;
        err = 0;
        while ((res = redboot_getc()) >= 0) {
#ifdef CYGSEM_REDBOOT_VALIDATE_USER_RAM_LOADS
#ifdef CYGBLD_REDBOOT_LOAD_INTO_FLASH
            if (flash_addr_set && flash_verify_addr(mp) && !spillover_ok) {
                // Only if there is no need to stop the download
                // before printing output can we ask confirmation
                // questions.
                redboot_getc_terminate(true);
                err_printf("*** Abort! RAW data spills over limit of FLASH at %p\n",(void*)mp);
                err = -1;
                break;
            }
#endif
            if (base_addr_set && !valid_address(mp) && !spillover_ok) {
                // Only if there is no need to stop the download
                // before printing output can we ask confirmation
                // questions.
                redboot_getc_terminate(true);
                err_printf("*** Abort! RAW data spills over limit of user RAM at %p\n",(void*)mp);
                err = -1;
                break;
            }
#endif
#ifdef CYGBLD_REDBOOT_LOAD_INTO_FLASH
            if (flash_addr_set) {
              flash_load_write(mp, res);
              mp++;
              res++;
            } else
#endif
            *mp++ = res;
        }
        end = (unsigned long) mp;

        // Save load base/top
        load_address = base;
        load_address_end = end;
        entry_address = base;           // best guess

        redboot_getc_terminate(false);
        if (0 == err)
            diag_printf("Raw file loaded %p-%p, assumed entry at %p\n", 
                        (void *)base, (void *)(end - 1), (void*)base);
    } else {
        // Read initial header - to determine file [image] type
        for (i = 0;  i < sizeof(type);  i++) {
            if ((res = redboot_getc()) < 0) {
                err = getc_info.err;
                break;
            } 
            type[i] = res;
        }
        if (res >= 0) {
            redboot_getc_rewind();  // Restore header to stream
            // Treat data as some sort of executable image
            if (strncmp(&type[1], "ELF", 3) == 0) {
                end = load_elf_image(redboot_getc, base);
            } else if ((type[0] == 'S') &&
                       ((type[1] >= '0') && (type[1] <= '9'))) {
		end = load_srec_image(redboot_getc, base);
            } else {
                redboot_getc_terminate(true);
                err_printf("Unrecognized image type: 0x%lx\n", *(unsigned long *)type);
            }
        }
    }
#ifdef CYGBLD_REDBOOT_LOAD_INTO_FLASH
    flash_load_finish();
#endif

    redboot_getc_close();  // Clean up
    return;
}
Esempio n. 30
0
// Mount disk/filesystem
static void
do_mount(int argc, char *argv[])
{
    char *dev_str = "<undefined>", *type_str, *mp_str;
    bool dev_set = false, type_set = false;
    struct option_info opts[3];
    int err, num_opts = 2;
    int i,m=0; /* Set to 0 to silence warning */
#ifdef CYGPKG_IO_FLASH_BLOCK_DEVICE_LEGACY
    char *part_str;
    bool part_set = false;
#endif

    init_opts(&opts[0], 'd', true, OPTION_ARG_TYPE_STR,
              (void *)&dev_str, &dev_set, "device");
    init_opts(&opts[1], 't', true, OPTION_ARG_TYPE_STR,
              (void *)&type_str, &type_set, "fstype");
#ifdef CYGPKG_IO_FLASH_BLOCK_DEVICE_LEGACY
    init_opts(&opts[2], 'f', true, OPTION_ARG_TYPE_STR,
              (void *)&part_str, &part_set, "partition");
    num_opts++;
#endif

    CYG_ASSERT(num_opts <= NUM_ELEMS(opts), "Too many options");

    if (!scan_opts(argc, argv, 1, opts, num_opts, &mp_str, OPTION_ARG_TYPE_STR, "mountpoint"))
        return;

    if (!type_set) {
        err_printf("fs mount: Must specify file system type\n");
        return;
    }

    if( mp_str == 0 )
        mp_str = "/";

    if( mount_count >= MAX_MOUNTS )
    {
        err_printf("fs mount: Maximum number of mounts exceeded\n");
        return;
    }
    
#ifdef CYGPKG_IO_FLASH_BLOCK_DEVICE_LEGACY
    if (part_set) {
        int len;
        cyg_io_handle_t h;

        if (dev_set && strcmp(dev_str, CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1)) {
            err_printf("fs mount: May only set one of <device> or <partition>\n");
            return;
        }

        dev_str = CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1;
        len = strlen(part_str);

        err = cyg_io_lookup(dev_str, &h);
        if (err < 0) {
            err_printf("fs mount: cyg_io_lookup of \"%s\" returned %d\n", err);
            return;
        }
        err = cyg_io_set_config(h, CYG_IO_SET_CONFIG_FLASH_FIS_NAME,
                                part_str, &len);
        if (err < 0) {
            diag_printf("fs mount: FIS partition \"%s\" not found\n",
                        part_str);
            return;
        }
    }
#endif

    for( i = 0; i < MAX_MOUNTS; i++ )
    {
        if( mounts[i].mp_str[0] != '\0' )
        {
            if( strcmp(mounts[i].dev_str, dev_str ) == 0 )
            {
                err_printf("fs mount: Device %s already mounted\n",dev_str);
                return;
            }
        }
        else
            m = i;
    }

    strcpy( mounts[m].mp_str, mp_str );
    strcpy( mounts[m].dev_str, dev_str );
    strcpy( mounts[m].type_str, type_str );
    
    err = mount(mounts[m].dev_str, mounts[m].mp_str, mounts[m].type_str);

    if (err)
    {
        err_printf("fs mount: mount(%s,%s,%s) failed %d\n", dev_str, mp_str, type_str, errno);
        mounts[m].mp_str[0] = '\0'; // mount failed so don't let it appear mounted
    }
    else
    {
        if( mount_count == 0 )
            chdir( "/" );
        mount_count++;
    }
}