示例#1
0
static void
rfcommpr(kvm_t *kvmd, u_long addr)
{
	static char const * const	states[] = {
	/* NG_BTSOCKET_RFCOMM_DLC_CLOSED */	   "CLOSED",
	/* NG_BTSOCKET_RFCOMM_DLC_W4_CONNECT */	   "W4CON",
	/* NG_BTSOCKET_RFCOMM_DLC_CONFIGURING */   "CONFIG",
	/* NG_BTSOCKET_RFCOMM_DLC_CONNECTING */    "CONN",
	/* NG_BTSOCKET_RFCOMM_DLC_CONNECTED */     "OPEN",
	/* NG_BTSOCKET_RFCOMM_DLC_DISCONNECTING */ "DISCON"
	};

	ng_btsocket_rfcomm_pcb_p	this = NULL, next = NULL;
	ng_btsocket_rfcomm_pcb_t	pcb;
	struct socket			so;
	int				first = 1;
	char				local[24], remote[24];

	if (addr == 0)
		return;

        if (kread(kvmd, addr, (char *) &this, sizeof(this)) < 0)
		return;

	for ( ; this != NULL; this = next) {
		if (kread(kvmd, (u_long) this, (char *) &pcb, sizeof(pcb)) < 0)
			return;
		if (kread(kvmd, (u_long) pcb.so, (char *) &so, sizeof(so)) < 0)
			return;

		next = LIST_NEXT(&pcb, next);

		if (first) {
			first = 0;
			fprintf(stdout,
"Active RFCOMM sockets\n" \
"%-8.8s %-6.6s %-6.6s %-17.17s %-17.17s %-4.4s %-4.4s %s\n",
				"PCB",
				"Recv-Q",
				"Send-Q",
				"Local address",
				"Foreign address",
				"Chan",
				"DLCI",
				"State");
		}

		fprintf(stdout,
"%-8lx %6d %6d %-17.17s %-17.17s %-4d %-4d %s\n",
			(unsigned long) this,
			so.so_rcv.sb_ccc,
			so.so_snd.sb_ccc,
			bdaddrpr(&pcb.src, local, sizeof(local)),
			bdaddrpr(&pcb.dst, remote, sizeof(remote)),
			pcb.channel,
			pcb.dlci,
			(so.so_options & SO_ACCEPTCONN)?
				"LISTEN" : state2str(pcb.state));
	}
} /* rfcommpr */
示例#2
0
static void ipv4(const char *filename, const char *label) {
    FILE *fp = fopen(filename, "r");
    if (fp == NULL) {
        return;
    }
    char buf[BUFSIZ];
    fgets(buf, BUFSIZ, fp);
    while (fgets(buf, BUFSIZ, fp)){
        char lip[ADDR_LEN];
        char rip[ADDR_LEN];
        iaddr laddr, raddr;
        unsigned lport, rport, state, txq, rxq, num;
        int n = sscanf(buf, " %d: %x:%x %x:%x %x %x:%x",
                       &num, &laddr.u, &lport, &raddr.u, &rport,
                       &state, &txq, &rxq);
        if (n == 8) {
            addr2str(AF_INET, &laddr, lport, lip);
            addr2str(AF_INET, &raddr, rport, rip);

            printf("%4s  %6d %6d %-22s %-22s %s\n",
                   label, rxq, txq, lip, rip,
                   state2str(state));
        }
    }
    fclose(fp);
}
static DBusMessage *dev_get_properties(DBusConnection *conn, DBusMessage *msg,
								void *data)
{
	struct audio_device *device = data;
	DBusMessage *reply;
	DBusMessageIter iter;
	DBusMessageIter dict;
	const char *state;

	reply = dbus_message_new_method_return(msg);
	if (!reply)
		return NULL;

	dbus_message_iter_init_append(reply, &iter);

	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);

	/* State */
	state = state2str(device->priv->state);
	if (state)
		dict_append_entry(&dict, "State", DBUS_TYPE_STRING, &state);

	dbus_message_iter_close_container(&iter, &dict);

	return reply;
}
示例#4
0
// show data entries
void print_smartrns_data(smartrns_data_t data)
{
    uint32_t i;
    cout << endl;
    cout << "smartrns-data" << endl;
    cout << endl;
    cout << "  Name:           " << data.name << endl;
    cout << "  Version:        " << data.version << endl;
    cout << "  Comment:        " << data.comment << endl;
    cout << "  Entries (" << data.entries.size() << "): " << endl;
    for(i=0;i<data.entries.size();i++){
        cout.width(3);
        cout << i <<" Name:         " << data.entries[i].name << endl;
        cout << "    Comment:      " << data.entries[i].comment << endl;
        cout << "    Type:         " << entrytype2str(data.entries[i].type) << endl;
        cout << "    State:        " << state2str(data.entries[i].state) << endl;
        if(PHONE_NR == data.entries[i].type){
            cout << "    Phone (" << subtype2str(((smartrns_data_entry_phone_t*) data.entries[i].entry)->subtype) << "): " << ((smartrns_data_entry_phone_t*) data.entries[i].entry)->country << " " << ((smartrns_data_entry_phone_t*) data.entries[i].entry)->prefix << " " << ((smartrns_data_entry_phone_t*) data.entries[i].entry)->number << " " << ((smartrns_data_entry_phone_t*) data.entries[i].entry)->suffix << " (" << usagetype2str(((smartrns_data_entry_phone_t*) data.entries[i].entry)->usage) << ")"<< endl;
        }else if(ICQ == data.entries[i].type){
            cout << "    ICQ:          " << ((smartrns_data_entry_icq_t*) data.entries[i].entry)->icq << endl;
        }else if(EMAIL == data.entries[i].type){
            cout << "    E-Mail:       " << ((smartrns_data_entry_email_t*) data.entries[i].entry)->email << endl;
        }else if(JABBER == data.entries[i].type){
            cout << "    Jabber:       " << ((smartrns_data_entry_jabber_t*) data.entries[i].entry)->jabber << endl;
        }else if(NO_ETYPE == data.entries[i].type){
            cout << "    No Entrytype! " << endl;
        }else if(ETYPE_NOT_SPEC == data.entries[i].type){
            cout << "    Entrytype not specified! " << endl;
        }
        cout << endl;
    }
    cout << endl;
}
示例#5
0
static void
l2cappr(kvm_t *kvmd, u_long addr)
{
	static char const * const	states[] = {
	/* NG_BTSOCKET_L2CAP_CLOSED */		"CLOSED",
	/* NG_BTSOCKET_L2CAP_CONNECTING */	"CON",
	/* NG_BTSOCKET_L2CAP_CONFIGURING */	"CONFIG",
	/* NG_BTSOCKET_L2CAP_OPEN */		"OPEN",
	/* NG_BTSOCKET_L2CAP_DISCONNECTING */	"DISCON"
	};

	ng_btsocket_l2cap_pcb_p	this = NULL, next = NULL;
	ng_btsocket_l2cap_pcb_t	pcb;
	struct socket		so;
	int			first = 1;
	char			local[24], remote[24];

	if (addr == 0)
		return;

        if (kread(kvmd, addr, (char *) &this, sizeof(this)) < 0)
		return;

	for ( ; this != NULL; this = next) {
		if (kread(kvmd, (u_long) this, (char *) &pcb, sizeof(pcb)) < 0)
			return;
		if (kread(kvmd, (u_long) pcb.so, (char *) &so, sizeof(so)) < 0)
			return;

		next = LIST_NEXT(&pcb, next);

		if (first) {
			first = 0;
			fprintf(stdout,
"Active L2CAP sockets\n" \
"%-8.8s %-6.6s %-6.6s %-23.23s %-17.17s %-5.5s %s\n",
				"PCB",
				"Recv-Q",
				"Send-Q",
				"Local address/PSM",
				"Foreign address",
				"CID",
				"State");
		}

		fprintf(stdout,
"%-8lx %6d %6d %-17.17s/%-5d %-17.17s %-5d %s\n",
			(unsigned long) this,
			so.so_rcv.sb_ccc,
			so.so_snd.sb_ccc,
			bdaddrpr(&pcb.src, local, sizeof(local)),
			pcb.psm,
			bdaddrpr(&pcb.dst, remote, sizeof(remote)),
			pcb.cid,
			(so.so_options & SO_ACCEPTCONN)?
				"LISTEN" : state2str(pcb.state));
	}
} /* l2cappr */
示例#6
0
static void device_set_state(struct audio_device *dev, audio_state_t new_state)
{
	struct dev_priv *priv = dev->priv;
	const char *state_str;
	DBusMessage *reply = NULL;

	state_str = state2str(new_state);
	if (!state_str)
		return;

	if (new_state == AUDIO_STATE_DISCONNECTED) {
		priv->authorized = FALSE;

		if (priv->dc_id) {
			device_remove_disconnect_watch(dev->btd_dev,
							priv->dc_id);
			priv->dc_id = 0;
		}
	} else if (new_state == AUDIO_STATE_CONNECTING)
		priv->dc_id = device_add_disconnect_watch(dev->btd_dev,
						disconnect_cb, dev, NULL);

	if (dev->priv->state == new_state) {
		DBG("state change attempted from %s to %s",
							state_str, state_str);
		return;
	}

	dev->priv->state = new_state;

	if (new_state == AUDIO_STATE_DISCONNECTED) {
		if (priv->dc_req) {
			reply = dbus_message_new_method_return(priv->dc_req);
			dbus_message_unref(priv->dc_req);
			priv->dc_req = NULL;
			g_dbus_send_message(dev->conn, reply);
		}
		priv->disconnecting = FALSE;
	}

	if (priv->conn_req && new_state != AUDIO_STATE_CONNECTING) {
		if (new_state == AUDIO_STATE_CONNECTED)
			reply = dbus_message_new_method_return(priv->conn_req);
		else
			reply = btd_error_failed(priv->conn_req,
							"Connect Failed");

		dbus_message_unref(priv->conn_req);
		priv->conn_req = NULL;
		g_dbus_send_message(dev->conn, reply);
	}

	emit_property_changed(dev->conn, dev->path,
				AUDIO_INTERFACE, "State",
				DBUS_TYPE_STRING, &state_str);
}
示例#7
0
static void
rfcommpr_s(kvm_t *kvmd, u_long addr)
{
	static char const * const	states[] = {
	/* NG_BTSOCKET_RFCOMM_SESSION_CLOSED */	       "CLOSED",
	/* NG_BTSOCKET_RFCOMM_SESSION_LISTENING */     "LISTEN",
	/* NG_BTSOCKET_RFCOMM_SESSION_CONNECTING */    "CONNECTING",
	/* NG_BTSOCKET_RFCOMM_SESSION_CONNECTED */     "CONNECTED",
	/* NG_BTSOCKET_RFCOMM_SESSION_OPEN */          "OPEN",
	/* NG_BTSOCKET_RFCOMM_SESSION_DISCONNECTING */ "DISCONNECTING"
	};

	ng_btsocket_rfcomm_session_p	this = NULL, next = NULL;
	ng_btsocket_rfcomm_session_t	s;
	struct socket			so;
	int				first = 1;

	if (addr == 0)
		return;

        if (kread(kvmd, addr, (char *) &this, sizeof(this)) < 0)
		return;

	for ( ; this != NULL; this = next) {
		if (kread(kvmd, (u_long) this, (char *) &s, sizeof(s)) < 0)
			return;
		if (kread(kvmd, (u_long) s.l2so, (char *) &so, sizeof(so)) < 0)
			return;

		next = LIST_NEXT(&s, next);

		if (first) {
			first = 0;
			fprintf(stdout,
"Active RFCOMM sessions\n" \
"%-8.8s %-8.8s %-4.4s %-5.5s %-5.5s %-4.4s %s\n",
				"L2PCB",
				"PCB",
				"Flags",
				"MTU",
				"Out-Q",
				"DLCs",
				"State");
		}

		fprintf(stdout,
"%-8lx %-8lx %-4x %-5d %-5d %-4s %s\n",
			(unsigned long) so.so_pcb,
			(unsigned long) this,
			s.flags,
			s.mtu,
			s.outq.len,
			LIST_EMPTY(&s.dlcs)? "No" : "Yes",
			state2str(s.state));
	}
} /* rfcommpr_s */
示例#8
0
文件: transport.c 项目: Thread974/bz
static gboolean get_state(const GDBusPropertyTable *property,
					DBusMessageIter *iter, void *data)
{
	struct media_transport *transport = data;
	const char *state = state2str(transport->state);

	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &state);

	return TRUE;
}
示例#9
0
bool state_write(const char *statedir, int keyholder_id, const char *keyholder_name, enum state status, const char *message) {
	char keyholder_id_str[16];
	bool result = true;
	snprintf(keyholder_id_str, sizeof(keyholder_id_str), "%d", keyholder_id);

	result &= file_write(statedir, "keyholder-id", keyholder_id_str);
	result &= file_write(statedir, "keyholder-name", keyholder_name);
	result &= file_write(statedir, "status", state2str(status));
	result &= file_write(statedir, "message", message);

	return result;
}
示例#10
0
文件: transport.c 项目: Thread974/bz
static void transport_set_state(struct media_transport *transport,
							transport_state_t state)
{
	transport_state_t old_state = transport->state;
	const char *str;

	if (old_state == state)
		return;

	transport->state = state;

	DBG("State changed %s: %s -> %s", transport->path, str_state[old_state],
							str_state[state]);

	str = state2str(state);

	if (g_strcmp0(str, state2str(old_state)) != 0)
		g_dbus_emit_property_changed(btd_get_dbus_connection(),
						transport->path,
						MEDIA_TRANSPORT_INTERFACE,
						"State");
}
/*---------------------------------------------------------------------*/
__task void task4(void)
{
	for(;;){
	U8 i=1;
  RL_TASK_INFO task_info;
  
  os_mut_wait(g_mut_uart, 0xFFFF);
	printf("TID\tNAME\t\tPRIO\tSTATE   \t%%STACK\n");
	os_mut_release(g_mut_uart);
    
  for(i = 0; i <7; i++) { // this is a lazy way of doing loop.
    if (os_tsk_get(i+1, &task_info) == OS_R_OK) {
      os_mut_wait(g_mut_uart, 0xFFFF);  
		  printf("%d\t%s\t\t%d\t%s\t%d%%\n", \
             task_info.task_id, \
             fp2name(task_info.ptask, g_tsk_name), \
             task_info.prio, \
             state2str(task_info.state, g_str),  \
             task_info.stack_usage);
		  os_mut_release(g_mut_uart);
    } 
  }
    
  if (os_tsk_get(0xFF, &task_info) == OS_R_OK) {
    os_mut_wait(g_mut_uart, 0xFFFF);  
	  printf("%d\t%s\t%d\t%s\t%d%%\n", \
           task_info.task_id, \
           fp2name(task_info.ptask, g_tsk_name), \
           task_info.prio, \
           state2str(task_info.state, g_str),  \
           task_info.stack_usage);
		os_mut_release(g_mut_uart);
  }
	 os_dly_wait(20);	
	}
	
}
示例#12
0
static void change_state(struct audio_device *dev, gateway_state_t new_state)
{
	struct gateway *gw = dev->gateway;
	const char *val;

	if (gw->state == new_state)
		return;

	val = state2str(new_state);
	gw->state = new_state;

	emit_property_changed(dev->conn, dev->path,
			AUDIO_GATEWAY_INTERFACE, "State",
			DBUS_TYPE_STRING, &val);
}
static int controller_show(struct seq_file *seq, void *v)
{
	struct capi_ctr *ctr = *(struct capi_ctr **) v;

	if (!ctr)
		return 0;

	seq_printf(seq, "%d %-10s %-8s %-16s %s\n",
		   ctr->cnr, ctr->driver_name,
		   state2str(ctr->state),
		   ctr->name,
		   ctr->procinfo ?  ctr->procinfo(ctr) : "");

	return 0;
}
示例#14
0
static void device_set_state(struct audio_device *dev, audio_state_t new_state)
{
	struct dev_priv *priv = dev->priv;
	const char *state_str;
	DBusMessage *reply = NULL;

	state_str = state2str(new_state);
	if (!state_str)
		return;

	if (new_state == AUDIO_STATE_DISCONNECTED)
		priv->authorized = FALSE;

	if (dev->priv->state == new_state) {
		debug("state change attempted from %s to %s",
							state_str, state_str);
		return;
	}

	dev->priv->state = new_state;

	if (priv->dc_req && new_state == AUDIO_STATE_DISCONNECTED) {
		reply = dbus_message_new_method_return(priv->dc_req);
		dbus_message_unref(priv->dc_req);
		priv->dc_req = NULL;
		g_dbus_send_message(dev->conn, reply);
	}

	if (priv->conn_req && new_state != AUDIO_STATE_CONNECTING) {
		if (new_state == AUDIO_STATE_CONNECTED)
			reply = dbus_message_new_method_return(priv->conn_req);
		else
			reply = g_dbus_create_error(priv->conn_req,
							ERROR_INTERFACE
							".ConnectFailed",
							"Connecting failed");
		dbus_message_unref(priv->conn_req);
		priv->conn_req = NULL;
		g_dbus_send_message(dev->conn, reply);
	}

	emit_property_changed(dev->conn, dev->path,
				AUDIO_INTERFACE, "State",
				DBUS_TYPE_STRING, &state_str);
}
示例#15
0
static void service_to_text(GtkTreeViewColumn *column, GtkCellRenderer *cell,
			GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
{
	gchar *name;
	guint type, state, security;
	gboolean favorite;
	gchar *markup, *str;
	const gchar *format, *val;

	gtk_tree_model_get(model, iter, CONNMAN_COLUMN_NAME, &name,
					CONNMAN_COLUMN_TYPE, &type,
					CONNMAN_COLUMN_STATE, &state,
					CONNMAN_COLUMN_FAVORITE, &favorite,
					CONNMAN_COLUMN_SECURITY, &security, -1);

	if (favorite == TRUE)
		format = "<b>%s</b>\n"
			"<span size=\"small\">%s service%s%s <i>(%s)</i></span>";
	else
		format = "%s\n<span size=\"small\">%s service%s%s <i>(%s)</i></span>";

	if (name == NULL) {
		if (type == CONNMAN_TYPE_WIFI)
			str = g_strdup("<i>hidden</i>");
		else
			str = g_strdup(type2str(type));
	} else
		str = g_markup_printf_escaped("%s", name);

	if (state == CONNMAN_STATE_UNKNOWN || state == CONNMAN_STATE_IDLE)
		val = NULL;
	else
		val = state2str(state);

	markup = g_strdup_printf(format, str, type2str(type),
					val ? " - " : "", val ? val : "",
						security2str(security));
	g_object_set(cell, "markup", markup, NULL);
	g_free(markup);
	g_free(str);

	g_free(name);
}
示例#16
0
文件: sink.c 项目: LittoCats/OT_4010D
static void sink_set_state(struct audio_device *dev, sink_state_t new_state)
{
	struct sink *sink = dev->sink;
	const char *state_str;
	sink_state_t old_state = sink->state;
	GSList *l;

	sink->state = new_state;

	state_str = state2str(new_state);
	if (state_str)
		emit_property_changed(dev->conn, dev->path,
					AUDIO_SINK_INTERFACE, "State",
					DBUS_TYPE_STRING, &state_str);

	for (l = sink_callbacks; l != NULL; l = l->next) {
		struct sink_state_callback *cb = l->data;
		cb->cb(dev, old_state, new_state, cb->user_data);
	}
}
示例#17
0
文件: net.c 项目: open-sw/vzctl
int run_net_script(envid_t veid, int op, list_head_t *ip_h, int state,
	int skip_arpdetect)
{
	char *argv[3];
	char *envp[10];
	char *script;
	int ret;
	char buf[STR_SIZE];
	int i = 0;
	char *skip_str = "SKIP_ARPDETECT=yes";

	if (list_empty(ip_h))
		return 0;
	snprintf(buf, sizeof(buf), "VEID=%d", veid);
	envp[i++] = strdup(buf);
	snprintf(buf, sizeof(buf), "VE_STATE=%s", state2str(state));
	envp[i++] = strdup(buf);
	envp[i++] = list2str("IP_ADDR", ip_h);
	envp[i++] = strdup(ENV_PATH);
	if (skip_arpdetect)
		envp[i++] = strdup(skip_str);
	envp[i] = NULL;
	switch (op) {
		case ADD:
			script = VPS_NET_ADD;
			break;
		case DEL:
			script = VPS_NET_DEL;
			break;
		default:
			return 0;
	}
	argv[0] = script;
	argv[1] = NULL;
	ret = run_script(script, argv, envp, 0);
	free_arg(envp);

	return ret;
}
static DBusMessage *sink_get_properties(DBusConnection *conn,
					DBusMessage *msg, void *data)
{
	struct audio_device *device = data;
	struct sink *sink = device->sink;
	DBusMessage *reply;
	DBusMessageIter iter;
	DBusMessageIter dict;
	const char *state;
	gboolean value;

	reply = dbus_message_new_method_return(msg);
	if (!reply)
		return NULL;

	dbus_message_iter_init_append(reply, &iter);

	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);

	/* Playing */
	value = (sink->stream_state == AVDTP_STATE_STREAMING);
	dict_append_entry(&dict, "Playing", DBUS_TYPE_BOOLEAN, &value);

	/* Connected */
	value = (sink->stream_state >= AVDTP_STATE_CONFIGURED);
	dict_append_entry(&dict, "Connected", DBUS_TYPE_BOOLEAN, &value);

	/* State */
	state = state2str(sink->state);
	if (state)
		dict_append_entry(&dict, "State", DBUS_TYPE_STRING, &state);

	dbus_message_iter_close_container(&iter, &dict);

	return reply;
}
示例#19
0
文件: gateway.c 项目: intgr/bluez
static void change_state(struct audio_device *dev, gateway_state_t new_state)
{
	struct gateway *gw = dev->gateway;
	const char *val;
	GSList *l;
	gateway_state_t old_state;

	if (gw->state == new_state)
		return;

	val = state2str(new_state);
	old_state = gw->state;
	gw->state = new_state;

	emit_property_changed(dev->path,
				AUDIO_GATEWAY_INTERFACE, "State",
				DBUS_TYPE_STRING, &val);

	for (l = gateway_callbacks; l != NULL; l = l->next) {
		struct gateway_state_callback *cb = l->data;
		cb->cb(dev, old_state, new_state, cb->user_data);
	}
}
示例#20
0
int
main(int argc, char **argv)
{
	int c;
	int is_state = 0;
	int is_power = 0;
	SaErrorT rv;
	SaHpiSessionIdT sessionid;
	SaHpiDomainInfoT domainInfo;
	SaHpiRptEntryT rptentry;
	SaHpiEntryIdT rptentryid;
	SaHpiEntryIdT nextrptentryid;
	SaHpiResourceIdT resourceid;
	SaHpiPowerStateT in_state = 0;
	SaHpiPowerStateT current_state;

	printf("%s ver %s\n", argv[0],progver);

	while ( (c = getopt( argc, argv,"udcx?")) != EOF )
		switch(c) {
			case 'u':	/* power up */
				in_state = SAHPI_POWER_ON;
				is_state = 1;
				break;

			case 'd':	/* power down */
				in_state = SAHPI_POWER_OFF;
				is_state = 1;
				break;
			case 'c':	/* power cycle */
				in_state = SAHPI_POWER_CYCLE;
				is_state = 1;
				break;
			default:
				usage(argv[0]);
				exit(1);
		}
	if ( ! is_state) {
		usage(argv[0]);
		exit(1);
	};

	rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID, &sessionid, NULL);
	if (rv != SA_OK) {
		if (rv == SA_ERR_HPI_ERROR)
			printf("saHpiSessionOpen: error %d, SpiLibd not running\n",rv);
		else
			printf("saHpiSessionOpen error %d\n",rv);
			exit(-1);
	}
	
  	rv = saHpiDiscover(sessionid);
	if (rv != SA_OK)
	      printf("saHpiDiscover rv = %d\n",rv);

	rv = saHpiDomainInfoGet(sessionid, &domainInfo);
	if (rv != SA_OK)
		printf("saHpiDomainInfoGet rv = %d\n",rv);

	/* walk the RPT list */
	rptentryid = SAHPI_FIRST_ENTRY;
	while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY)) {
		
		SaErrorT rv1;
		
		rv = saHpiRptEntryGet(sessionid,rptentryid,&nextrptentryid,&rptentry);
		if (rv != SA_OK) {
		       printf("RptEntryGet: rv = %d\n",rv);
		       break;
		};
		/* walk the RDR list for this RPT entry */
		resourceid = rptentry.ResourceId;
		rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0;
		printf("rptentry[%d] resourceid=%d tag: %s\n",
				rptentryid,resourceid, (char *)rptentry.ResourceTag.Data);

		if (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_POWER) {
			is_power = 1;

			/* read the current power state */
			rv1 = saHpiResourcePowerStateGet(sessionid, resourceid,
							&current_state);
			if (rv1 != SA_OK) {
				printf("saHpiResourcePowerStateGet: error = %d\n", rv1);
				rptentryid = nextrptentryid;
				continue;
			} 
				printf("Current power state:");
			state2str(current_state);

			/* set new power state */
			switch (in_state) {
			      	case SAHPI_POWER_OFF:
				case SAHPI_POWER_ON:
				    	printf("Setting power state to:");
					state2str(in_state);
					rv1 = saHpiResourcePowerStateSet(sessionid, resourceid, in_state);
					if (rv1 != SA_OK)
					      	printf("PowerStateSet status = %d\n",rv1);
					sleep(2);
					break;
				case SAHPI_POWER_CYCLE:
					printf("Cycling system power\n");
					rv1 = saHpiResourcePowerStateSet(sessionid, resourceid, in_state);
					if (rv1 != SA_OK)
					      	printf("PowerStateSet status = %d\n",rv1);
						
					printf("Cycling power, please wait a moment...\n");
					sleep(8);
					break;
			}
			/* check new state again */
			rv1 = saHpiResourcePowerStateGet(sessionid, resourceid,
									&current_state);
			if (rv1 != SA_OK) {
				      	printf("saHpiResourcePowerStateGet: error = %d\n", rv1);
					break;
			} else {
				      	printf("New power state:");
					state2str(current_state);
			}
		}
		rptentryid = nextrptentryid;
	}

	 rv = saHpiSessionClose(sessionid);

	 if (is_power == 0)
		 printf("No resources with Power capability found\n");

	 return(0);
}
示例#21
0
void
Cache :: line_data_writeback(Line *line)
{
    if (line->pdata == NULL) return;
    assert(! ((line->state & (LINE_MOD | LINE_EXC)) && (line->state & LINE_TXW)) );
    if (!(line->state & (LINE_MOD | LINE_TXW))) return;
    if (_parent_cache && line->parent_line)
    {
        NVLOG1("%s\tline_data_writeback to %s 0x%lx data 0x%lx -> 0x%lx\n", this->_name.c_str(), _parent_cache->_name.c_str(), line->addr, (Addr)line->pdata, (Addr)line->parent_line->pdata);
        assert(line->parent_line->pdata != NULL);
        memcpy(line->parent_line->pdata+(line->addr - line->parent_line->addr), line->pdata, get_line_size());
        if (line->state & LINE_MOD) { line->parent_line->state |= LINE_MOD; } // propagate modified state
        NVLOG1("%s\t0x%lx\t new state %s sharers %lx\n",  _parent_cache->_name.c_str(),  line->parent_line->addr,  state2str(line->parent_line->state).c_str(), line->parent_line->sharers );
    }
    else
    {
        NVLOG1("%s\tline_data_writeback to main_mem 0x%lx data <- 0x%lx\n", this->_name.c_str(), line->addr, (Addr)line->pdata);
        // write the line data to the memory
//        Fault fault = rw_array_silent(line->addr, get_line_size(), line->pdata, true);
//        assert(fault == NoFault);
    }
}
示例#22
0
void
Cache :: line_get_as_modified(Addr addr)
{
    Line *line;
    Line *line_iter;
    line = line_iter = addr2line_internal(addr);
    // get line as modified (and invalidate all other line copies)
    for (Cache *cache_iter = this; cache_iter->_parent_cache; cache_iter = cache_iter->_parent_cache, line_iter = line_iter->parent_line)
    {
        NVLOG1("%s\tline_get_as_modified 0x%lx\n", cache_iter->_name.c_str(), addr);
        // make me a unique owner
        cache_iter->_parent_cache->line_make_owner_in_child_caches(line_iter->parent_line, cache_iter->_index_in_parent);
        line_iter->state |= LINE_EXC;
        line_iter->parent_line->state |= LINE_EXC;
        NVLOG1("%s\t0x%lx\t new state %s sharers %lx\n",  cache_iter->_name.c_str(),  line_iter->addr,  state2str(line_iter->state).c_str(), line_iter->sharers);
        NVLOG1("%s\t0x%lx\t new state %s sharers %lx\n",  cache_iter->_parent_cache->_name.c_str(),  line_iter->parent_line->addr,  state2str(line_iter->parent_line->state).c_str(), line_iter->parent_line->sharers );
    }
    line->state |= LINE_MOD;
    NVLOG1("%s\t0x%lx\t new state %s sharers %lx\n",  this->_name.c_str(),  line->addr,  state2str(line->state).c_str(), line->sharers);
}
示例#23
0
void
Cache :: line_get(Addr addr, uint8_t line_state_req, size_t &latency, uint8_t *&pdata)
{
    //////////////////////////////////////////////////////////////////
    //
    //  proudly serving cache requests
    //  since september 2008
    //
    //////////////////////////////////////////////////////////////////
    //
    // line_state_req(uest) values:
    // LINE_SHR - request a read
    // LINE_EXC - request an exclusive access (invalidate other readers)
    // LINE_MOD - perform a write (invalidate other readers and mark line as dirty)

    bool set_overflow = false;
    Line *overflow_line = NULL;
    // this adds a line (if it's not already in the cache) but with LINE_INV state
    Line *line = addr2line(addr, set_overflow, overflow_line);
    // if some line has been replaced, get the value and evict/invalidate the same line and its parts
    // in all child caches
    if (set_overflow) {
        NVLOG1("%s\tline_get overflow 0x%lx\n", _name.c_str(), overflow_line->addr);
        this->line_evict(overflow_line);
    }
    uint8_t __attribute__((unused)) line_state_orig = line->state;
    uint64_t __attribute__((unused)) line_sharers_orig = line->sharers;

    bool hit = true;
    size_t old_ticks = latency;

    if (line->state & LINE_MOD)
    {
        switch (line_state_req) {
            case LINE_MOD:
            case LINE_EXC:
            case LINE_SHR:
                break;
            default:
                assert(!"invalid line_state request!");
        }
    }
    else if (line->state & LINE_EXC)
    { // line is EXCLUSIVE when it is not modified and there is no other line sharer
        // TODO update the functionality to reflect this;
        // first line sharer should automatically get exclusive access;
        // this exclusive access should be reduced to shared when another core requests line copy (for read)
        switch (line_state_req) {
            case LINE_MOD:
                if (_is_writeback_cache || !_parent_cache) {
                    // mark line as dirty (for writeback)
                    line->state |= line_state_req;
                } else {
                    // write latency should include writing to the parent
                    _parent->line_get_intercache(addr, line_state_req, latency, _index_in_parent, line->parent_line);
                    // TODO should also write data to the parent cache
                    hit = false;
                    break;
                }
            case LINE_EXC:
            case LINE_SHR:
                break;
            default:
                assert(!"invalid line_state request!");
        }
    }
    else if (line->state & LINE_SHR)
    {
        switch (line_state_req) {
            case LINE_MOD:
            case LINE_EXC:
                if (_parent_cache) {
                    if (_is_writeback_cache) {
                        _parent->line_get_intercache(addr, LINE_EXC, latency, _index_in_parent, line->parent_line);
                    } else {
                        _parent->line_get_intercache(addr, line_state_req, latency, _index_in_parent, line->parent_line);
                    }
                    hit = false;
                }
                line->state |= line_state_req;
                break;
            case LINE_SHR:
                break;
            default:
                assert(!"invalid line_state request!");
        }
    }
    else if (line->state == LINE_INV)
    {
        hit = false;
        switch (line_state_req) {
            case LINE_TXW:
            case LINE_TXR:
                _parent->line_get_intercache(addr, LINE_SHR, latency, _index_in_parent, line->parent_line);
                line->state |= line->parent_line->state & ( LINE_TXR | LINE_TXW);
                line->state |= (LINE_SHR | line_state_req);
                break;
            case LINE_MOD:
            case LINE_EXC:
                if (_is_writeback_cache) {
                    _parent->line_get_intercache(addr, LINE_EXC, latency, _index_in_parent, line->parent_line);
                } else {
                    _parent->line_get_intercache(addr, line_state_req, latency, _index_in_parent, line->parent_line);
                }
                line->state |= line_state_req;
                break;
            case LINE_SHR:
                _parent->line_get_intercache(addr, LINE_SHR, latency, _index_in_parent, line->parent_line);
                line->state |= line_state_req;
                break;
            default:
                assert(!"invalid line_state request!");
        }
    }
    else
    {
        NVLOG_ERROR("invalid current line_state %x\n", line->state);
        assert(false && "invalid current line_state!");
    }


    if (line->pdata == NULL) {
        line->pdata = (uint8_t*)malloc(get_line_size());
        if (_parent_cache && line->parent_line) { // if data found in parent cache
            NVLOG1("%s\tline_get data copy from %s 0x%lx data 0x%lx -> 0x%lx\n", this->_name.c_str(), _parent_cache->_name.c_str(), line->addr, (Addr)line->parent_line->pdata, (Addr)line->pdata);
            memcpy(line->pdata, line->parent_line->pdata+(line->addr - line->parent_line->addr), get_line_size());
        } else {
            // get the data from the memory
            NVLOG1("%s\tline_get data copy from memory 0x%lx data -> 0x%lx\n", this->_name.c_str(), line->addr, (Addr)line->pdata);
	    //Fault fault = rw_array_silent(line->addr, get_line_size(), line->pdata, false/*READ*/);
	    //assert(fault == NoFault);
        }
    }
    pdata = line->pdata;

    latency += _hit_latency;
    // update statistics
    if (hit) {
        this->stats.hits_inc();
    } else {
        this->stats.misses_inc();
        if (line_state_req & LINE_MOD || line_state_req & LINE_EXC)
        { this->stats.misses_st_inc(); }
        else
        { this->stats.misses_ld_inc(); }
    }
    this->stats.ticks_inc(latency - old_ticks);
    NVLOG1("%s\tline_get 0x%lx\t state %s->%s sharers 0x%lx->0x%lx\n",  _name.c_str(),  line->addr,  state2str(line_state_orig).c_str(), state2str(line->state).c_str(), line_sharers_orig, line->sharers);
    assert(! ((line->state & (LINE_MOD | LINE_EXC)) && (line->state & LINE_TXW)) );
}
示例#24
0
bool
Cache :: line_make_owner_in_child_caches(Line *line, unsigned child_index)
{
    NVLOG1("%s\tline_make_owner_in_child_caches 0x%lx sharers %lx caller %d\n", this->_name.c_str(), line->addr, line->sharers, child_index);
    uint8_t __attribute__((unused)) line_state_orig = line->state;
    uint64_t __attribute__((unused)) line_sharers_orig = line->sharers;
    // evict the line in all but the requesting child cache
    for (size_t child_i = 0; child_i<_children.size() && line->sharers>0; child_i++) {
        Cache *child = dynamic_cast<Cache *>(_children[child_i]); assert(child!=NULL);
        // NVLOG1("%s\tchecking for 0x%lx %lx 1\n", child->_name.c_str(), line->addr, line->sharers);
        if (!bit(line->sharers, child_i)) continue; // a child is not a sharer, so continue
        // NVLOG1("%s\tchecking for 0x%lx %lx 2\n", child->_name.c_str(), line->addr, line->sharers);
        if (child_i == child_index) continue; // skip the child cache that called us
        // NVLOG1("%s\tchecking for 0x%lx %lx 3\n", child->_name.c_str(), line->addr, line->sharers);
        for (Addr line_addr_iter=line->addr; line_addr_iter<line->addr+get_line_size(); line_addr_iter += child->get_line_size())
        {
            NVLOG1("%s\tis line sharer, checking segment 0x%lx\n", child->_name.c_str(), line_addr_iter);
            Line *child_line = child->addr2line_internal(line_addr_iter);
            if (!child_line) continue;
            NVLOG1("%s\thas segment 0x%lx, evicting\n", child->_name.c_str(), line_addr_iter);
            child->line_evict(child_line);
        }
    }
    line->sharers = 0;
    setbit(line->sharers, child_index);
    NVLOG1("%s\tline 0x%lx\t state %s->%s sharers 0x%lx->0x%lx\n",  _name.c_str(),  line->addr,  state2str(line_state_orig).c_str(), state2str(line->state).c_str(), line_sharers_orig, line->sharers);
    return true;
}
示例#25
0
void
Cache :: line_get_intercache(Addr addr, uint8_t line_state_req, size_t &latency, unsigned child_index, Line *&parent_line)
{
    //////////////////////////////////////////////////////////////////////
    // serving line relocations inside the cache hierarchy
    //////////////////////////////////////////////////////////////////////

    bool set_overflow = false;
    Line *overflow_line = NULL;
    // this adds a line (if it's not already in the cache) but with LINE_INV state
    Line *line = addr2line(addr, set_overflow, overflow_line);
    if (set_overflow) {
        // if some line has been replaced, get the value and invalidate the same line and its parts
        // in all child caches
        NVLOG1("%s\tline_get overflow 0x%lx\n", _name.c_str(), overflow_line->addr);
        this->line_evict(overflow_line);
    }
    uint8_t __attribute__((unused)) line_state_orig = line->state;
    uint64_t __attribute__((unused)) line_sharers_orig = line->sharers;

    bool hit = true;
    size_t old_ticks = latency;

    if (line->state & (LINE_MOD | LINE_EXC))
    {
        // this directory already owns a line (exclusively)
        // just in case we'll invalidate the line in
        // all other child-caches
        switch (line_state_req) {
            case LINE_MOD:
                if (line->sharers != (1ULL<<child_index)) {
                    this->line_make_owner_in_child_caches(line, child_index);
                    setbit(line->sharers, child_index);
                }
                if (_is_writeback_cache || !_parent_cache) {
                    line->state |= line_state_req;
                } else {
                    _parent->line_get_intercache(addr, line_state_req, latency, _index_in_parent, line->parent_line);
                    hit = false;
                    break;
                }
                break;
            case LINE_EXC:
                // this processor wants to have an exclusive copy
                // (and it didn't have it until now, as we got an intercache request)
                if (line->sharers != (1ULL<<child_index)) {
                    this->line_make_owner_in_child_caches(line, child_index);
                    setbit(line->sharers, child_index);
                }
                break;
            case LINE_SHR:
                if (line->sharers != (1ULL<<child_index)) {
                    this->line_writer_to_sharer(line, latency);
                    // and do not write the data up in the memory hierarchy
                    setbit(line->sharers, child_index);
                }
                break;
            default:
                assert(!"invalid line_state request!");
        }
        //assert(line_state_req == LINE_SHR || line_state_req == LINE_EXC || line_state_req == LINE_MOD);
        line->state |= line_state_req; // we might also reduce from writer to LINE_SHR in this cache
    }
    else if (line->state & LINE_SHR)
    {
        switch (line_state_req) {
            case LINE_MOD:
            case LINE_EXC:
                this->line_make_owner_in_child_caches(line, child_index);
                setbit(line->sharers, child_index);
                if (_parent_cache) {
                    if (_is_writeback_cache) {
                        _parent->line_get_intercache(addr, LINE_EXC, latency, _index_in_parent, line->parent_line);
                    } else {
                        _parent->line_get_intercache(addr, line_state_req, latency, _index_in_parent, line->parent_line);
                    }
                    hit = false;
                }
                line->state |= line_state_req;
                break;
            case LINE_SHR:
                setbit(line->sharers, child_index);
                break;
            default:
                assert(!"invalid line_state request!");
        }
    }
    else if (line->state == LINE_INV)
    {
        hit = false;
        switch (line_state_req) {
            case LINE_MOD:
            case LINE_EXC:
                if (_is_writeback_cache) {
                    _parent->line_get_intercache(addr, LINE_EXC, latency, _index_in_parent, line->parent_line);
                } else {
                    _parent->line_get_intercache(addr, line_state_req, latency, _index_in_parent, line->parent_line);
                }
                if (line->parent_line) { line->state = line->parent_line->state; }
                line->state |= line_state_req;
                setbit(line->sharers, child_index);
                break;
            case LINE_SHR:
                _parent->line_get_intercache(addr, LINE_SHR, latency, _index_in_parent, line->parent_line);
                if (line->parent_line) { line->state = line->parent_line->state; }
                line->state |= line_state_req;
                setbit(line->sharers, child_index);
                break;
            default:
                assert(!"invalid line_state request!");
        }
    }
    else
    {
        NVLOG_ERROR("invalid current line_state %x\n", line->state);
        assert(false && "invalid current line_state!");
    }

    if (line->pdata == NULL) {
        line->pdata = (uint8_t*)malloc(get_line_size());
        if (_parent_cache && line->parent_line) { // if data found in any parent cache
            NVLOG1("%s\tline_get data copy from %s 0x%lx data 0x%lx -> 0x%lx\n", this->_name.c_str(), _parent_cache->_name.c_str(), line->addr, (Addr)line->parent_line->pdata, (Addr)line->pdata);
            memcpy(line->pdata, line->parent_line->pdata+(line->addr - line->parent_line->addr), get_line_size());
        } else {
            // get the data from the memory
            NVLOG1("%s\tline_get data copy from memory 0x%lx data 0x%lx\n", this->_name.c_str(), line->addr, (Addr)line->pdata);
//            Fault fault = rw_array_silent(line->addr, get_line_size(), line->pdata, false/*READ*/);
//            assert(fault == NoFault);
        }
    }
    parent_line = line;

    latency += _hit_latency;
    // update statistics
    if (hit) {
        this->stats.hits_inc();
    } else {
        this->stats.misses_inc();
        if (line_state_req & LINE_MOD || line_state_req & LINE_EXC)
        { this->stats.misses_st_inc(); }
        else
        { this->stats.misses_ld_inc(); }
    }
    this->stats.ticks_inc(latency - old_ticks);
    NVLOG1("%s\tline_get 0x%lx\t state %s->%s sharers 0x%lx->0x%lx\n",  _name.c_str(),  line->addr,  state2str(line_state_orig).c_str(), state2str(line->state).c_str(), line_sharers_orig, line->sharers);
    assert(! ((line->state & (LINE_MOD | LINE_EXC)) && (line->state & LINE_TXW)) );
}
示例#26
0
文件: conn.c 项目: 32bitmicro/zephyr
void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
{
	bt_conn_state_t old_state;

	BT_DBG("%s -> %s", state2str(conn->state), state2str(state));

	if (conn->state == state) {
		BT_WARN("no transition");
		return;
	}

	old_state = conn->state;
	conn->state = state;

	/* Actions needed for exiting the old state */
	switch (old_state) {
	case BT_CONN_DISCONNECTED:
		/* Take a reference for the first state transition after
		 * bt_conn_add_le() and keep it until reaching DISCONNECTED
		 * again.
		 */
		bt_conn_ref(conn);
		break;
	case BT_CONN_CONNECT:
		if (conn->timeout) {
			fiber_delayed_start_cancel(conn->timeout);
			conn->timeout = NULL;

			/* Drop the reference taken by timeout fiber */
			bt_conn_unref(conn);
		}
		break;
	default:
		break;
	}

	/* Actions needed for entering the new state */
	switch (conn->state) {
	case BT_CONN_CONNECTED:
		nano_fifo_init(&conn->tx_queue);
		fiber_start(conn->stack, sizeof(conn->stack), conn_tx_fiber,
			    (int)bt_conn_ref(conn), 0, 7, 0);

		bt_l2cap_connected(conn);
		notify_connected(conn);
		break;
	case BT_CONN_DISCONNECTED:
		/* Notify disconnection and queue a dummy buffer to wake
		 * up and stop the tx fiber for states where it was
		 * running.
		 */
		if (old_state == BT_CONN_CONNECTED ||
		    old_state == BT_CONN_DISCONNECT) {
			bt_l2cap_disconnected(conn);
			notify_disconnected(conn);

			nano_fifo_put(&conn->tx_queue, net_buf_get(&dummy, 0));
		} else if (old_state == BT_CONN_CONNECT) {
			/* conn->err will be set in this case */
			notify_connected(conn);
		} else if (old_state == BT_CONN_CONNECT_SCAN && conn->err) {
			/* this indicate LE Create Connection failed */
			notify_connected(conn);
		}

		/* Release the reference we took for the very first
		 * state transition.
		 */
		bt_conn_unref(conn);

		break;
	case BT_CONN_CONNECT_SCAN:
		break;
	case BT_CONN_CONNECT:
		/*
		 * Timer is needed only for LE. For other link types controller
		 * will handle connection timeout.
		 */
		if (conn->type != BT_CONN_TYPE_LE) {
			break;
		}

		/* Add LE Create Connection timeout */
		conn->timeout = fiber_delayed_start(conn->stack,
						    sizeof(conn->stack),
						    timeout_fiber,
						    (int)bt_conn_ref(conn),
						    0, 7, 0, CONN_TIMEOUT);
		break;
	case BT_CONN_DISCONNECT:
		break;
	default:
		BT_WARN("no valid (%u) state was set", state);

		break;
	}
}
示例#27
0
/* Perform a state transition to NEW_STATE.  If this is an invalid
   transition, the module will go into a fatal error state. */
static void
fips_new_state (enum module_states new_state)
{
  int ok = 0;
  enum module_states last_state;

  lock_fsm ();

  last_state = current_state;
  switch (current_state)
    {
    case STATE_POWERON:
      if (new_state == STATE_INIT
          || new_state == STATE_ERROR
          || new_state == STATE_FATALERROR)
        ok = 1;
      break;

    case STATE_INIT:
      if (new_state == STATE_SELFTEST
          || new_state == STATE_ERROR
          || new_state == STATE_FATALERROR)
        ok = 1;
      break;

    case STATE_SELFTEST:
      if (new_state == STATE_OPERATIONAL
          || new_state == STATE_ERROR
          || new_state == STATE_FATALERROR)
        ok = 1;
      break;

    case STATE_OPERATIONAL:
      if (new_state == STATE_SHUTDOWN
          || new_state == STATE_SELFTEST
          || new_state == STATE_ERROR
          || new_state == STATE_FATALERROR)
        ok = 1;
      break;

    case STATE_ERROR:
      if (new_state == STATE_SHUTDOWN
          || new_state == STATE_ERROR
          || new_state == STATE_FATALERROR
          || new_state == STATE_SELFTEST)
        ok = 1;
      break;

    case STATE_FATALERROR:
      if (new_state == STATE_SHUTDOWN )
        ok = 1;
      break;

    case STATE_SHUTDOWN:
      /* We won't see any transition *from* Shutdown because the only
         allowed new state is Power-Off and that one can't be
         represented.  */
      break;

    }

  if (ok)
    {
      current_state = new_state;
    }

  unlock_fsm ();

  if (!ok || _gcry_log_verbosity (2))
    log_info ("libgcrypt state transition %s => %s %s\n",
              state2str (last_state), state2str (new_state),
              ok? "granted":"denied");

  if (!ok)
    {
      /* Invalid state transition.  Halting library. */
#ifdef HAVE_SYSLOG
      syslog (LOG_USER|LOG_ERR,
              "Libgcrypt error: invalid state transition %s => %s",
              state2str (last_state), state2str (new_state));
#endif /*HAVE_SYSLOG*/
      fips_noreturn ();
    }
  else if (new_state == STATE_ERROR || new_state == STATE_FATALERROR)
    {
#ifdef HAVE_SYSLOG
      syslog (LOG_USER|LOG_WARNING,
              "Libgcrypt notice: state transition %s => %s",
              state2str (last_state), state2str (new_state));
#endif /*HAVE_SYSLOG*/
    }
}