use of org.eclipse.kura.web.shared.model.GwtWifiHotspotEntry in project kura by eclipse.
the class GwtNetworkServiceImpl method findWifiHotspots.
@Override
public ArrayList<GwtWifiHotspotEntry> findWifiHotspots(GwtXSRFToken xsrfToken, String interfaceName) throws GwtKuraException {
checkXSRFToken(xsrfToken);
NetworkAdminService nas = ServiceLocator.getInstance().getService(NetworkAdminService.class);
SystemService systemService = ServiceLocator.getInstance().getService(SystemService.class);
List<GwtWifiHotspotEntry> gwtWifiHotspotsEntries = new ArrayList<GwtWifiHotspotEntry>();
try {
Map<String, WifiHotspotInfo> wifiHotspotInfoMap = nas.getWifiHotspots(interfaceName);
if (wifiHotspotInfoMap != null && !wifiHotspotInfoMap.isEmpty()) {
Collection<WifiHotspotInfo> wifiHotspotInfoCollection = wifiHotspotInfoMap.values();
Iterator<WifiHotspotInfo> it = wifiHotspotInfoCollection.iterator();
while (it.hasNext()) {
WifiHotspotInfo wifiHotspotInfo = it.next();
String ssid = GwtSafeHtmlUtils.htmlEscape(wifiHotspotInfo.getSsid());
// }
if (wifiHotspotInfo.getChannel() <= systemService.getKuraWifiTopChannel() && ssid != null) {
GwtWifiHotspotEntry gwtWifiHotspotEntry = new GwtWifiHotspotEntry();
gwtWifiHotspotEntry.setMacAddress(wifiHotspotInfo.getMacAddress());
gwtWifiHotspotEntry.setSSID(ssid);
gwtWifiHotspotEntry.setsignalStrength(wifiHotspotInfo.getSignalLevel());
gwtWifiHotspotEntry.setChannel(wifiHotspotInfo.getChannel());
gwtWifiHotspotEntry.setFrequency(wifiHotspotInfo.getFrequency());
if (wifiHotspotInfo.getSecurity() == WifiSecurity.NONE || wifiHotspotInfo.getSecurity() == WifiSecurity.SECURITY_NONE) {
gwtWifiHotspotEntry.setSecurity("None");
} else if (wifiHotspotInfo.getSecurity() == WifiSecurity.SECURITY_WEP) {
gwtWifiHotspotEntry.setSecurity("WEP");
} else if (wifiHotspotInfo.getSecurity() == WifiSecurity.SECURITY_WPA) {
gwtWifiHotspotEntry.setSecurity("WPA");
} else if (wifiHotspotInfo.getSecurity() == WifiSecurity.SECURITY_WPA2) {
gwtWifiHotspotEntry.setSecurity("WPA2");
} else if (wifiHotspotInfo.getSecurity() == WifiSecurity.SECURITY_WPA_WPA2) {
gwtWifiHotspotEntry.setSecurity("WPA/WPA2");
}
GwtWifiCiphers gwtPairCiphers = null;
GwtWifiCiphers gwtGroupCiphers = null;
EnumSet<WifiSecurity> pairCiphers = wifiHotspotInfo.getPairCiphers();
Iterator<WifiSecurity> itPairCiphers = pairCiphers.iterator();
while (itPairCiphers.hasNext()) {
WifiSecurity cipher = itPairCiphers.next();
if (gwtPairCiphers == null) {
if (cipher == WifiSecurity.PAIR_TKIP) {
gwtPairCiphers = GwtWifiCiphers.netWifiCiphers_TKIP;
} else if (cipher == WifiSecurity.PAIR_CCMP) {
gwtPairCiphers = GwtWifiCiphers.netWifiCiphers_CCMP;
}
} else if (gwtPairCiphers == GwtWifiCiphers.netWifiCiphers_TKIP) {
if (cipher == WifiSecurity.PAIR_CCMP) {
gwtPairCiphers = GwtWifiCiphers.netWifiCiphers_CCMP_TKIP;
}
} else if (gwtPairCiphers == GwtWifiCiphers.netWifiCiphers_CCMP) {
if (cipher == WifiSecurity.PAIR_TKIP) {
gwtPairCiphers = GwtWifiCiphers.netWifiCiphers_CCMP_TKIP;
}
}
}
EnumSet<WifiSecurity> groupCiphers = wifiHotspotInfo.getGroupCiphers();
Iterator<WifiSecurity> itGroupCiphers = groupCiphers.iterator();
while (itGroupCiphers.hasNext()) {
WifiSecurity cipher = itGroupCiphers.next();
if (gwtGroupCiphers == null) {
if (cipher == WifiSecurity.GROUP_TKIP) {
gwtGroupCiphers = GwtWifiCiphers.netWifiCiphers_TKIP;
} else if (cipher == WifiSecurity.GROUP_CCMP) {
gwtGroupCiphers = GwtWifiCiphers.netWifiCiphers_CCMP;
}
} else if (gwtGroupCiphers == GwtWifiCiphers.netWifiCiphers_TKIP) {
if (cipher == WifiSecurity.GROUP_CCMP) {
gwtGroupCiphers = GwtWifiCiphers.netWifiCiphers_CCMP_TKIP;
}
} else if (gwtGroupCiphers == GwtWifiCiphers.netWifiCiphers_CCMP) {
if (cipher == WifiSecurity.GROUP_TKIP) {
gwtGroupCiphers = GwtWifiCiphers.netWifiCiphers_CCMP_TKIP;
}
}
}
if (gwtPairCiphers != null) {
gwtWifiHotspotEntry.setPairwiseCiphers(gwtPairCiphers.name());
}
if (gwtGroupCiphers != null) {
gwtWifiHotspotEntry.setGroupCiphers(gwtGroupCiphers.name());
}
gwtWifiHotspotsEntries.add(gwtWifiHotspotEntry);
}
}
}
} catch (Throwable t) {
s_logger.error("Failed", t);
KuraExceptionHandler.handle(t);
}
return new ArrayList<GwtWifiHotspotEntry>(gwtWifiHotspotsEntries);
}
use of org.eclipse.kura.web.shared.model.GwtWifiHotspotEntry in project kura by eclipse.
the class WirelessConfigTab method createWifiNetworksWindow.
private Window createWifiNetworksWindow() {
final Window window = new Window();
window.setSize(700, 400);
window.setPlain(true);
window.setModal(true);
window.setBlinkModal(true);
window.setHeading("Wireless Networks");
// Create a table to layout the content
VerticalPanel dialogContents = new VerticalPanel();
dialogContents.setSpacing(4);
window.add(dialogContents);
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
ColumnConfig column = null;
column = new ColumnConfig("ssid", "SSID", 100);
column.setAlignment(HorizontalAlignment.LEFT);
configs.add(column);
column = new ColumnConfig("macAddress", "MAC Address", 100);
column.setAlignment(HorizontalAlignment.CENTER);
configs.add(column);
column = new ColumnConfig("signalStrength", "Signal (dBm)", 100);
column.setAlignment(HorizontalAlignment.CENTER);
configs.add(column);
column = new ColumnConfig("channel", "Channel", 100);
column.setAlignment(HorizontalAlignment.CENTER);
configs.add(column);
column = new ColumnConfig("frequency", "Frequency", 100);
column.setAlignment(HorizontalAlignment.CENTER);
configs.add(column);
column = new ColumnConfig("security", "Security", 100);
column.setAlignment(HorizontalAlignment.LEFT);
configs.add(column);
/*
CheckColumnConfig checkColumn = new CheckColumnConfig("selectAP", "Select", 55);
CellEditor checkBoxEditor = new CellEditor(new CheckBox());
checkColumn.setEditor(checkBoxEditor);
configs.add(checkColumn);
*/
// rpc data proxy
RpcProxy<ListLoadResult<GwtWifiHotspotEntry>> proxy = new RpcProxy<ListLoadResult<GwtWifiHotspotEntry>>() {
@Override
protected void load(Object loadConfig, final AsyncCallback<ListLoadResult<GwtWifiHotspotEntry>> callback) {
gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {
@Override
public void onFailure(Throwable ex) {
FailureHandler.handle(ex);
}
@Override
public void onSuccess(GwtXSRFToken token) {
gwtNetworkService.findWifiHotspots(token, m_selectNetIfConfig.getName(), callback);
}
});
}
};
m_wifiHotspotLoader = new BaseListLoader<ListLoadResult<GwtWifiHotspotEntry>>(proxy);
m_wifiHotspotLoader.setSortDir(SortDir.ASC);
m_wifiHotspotLoader.setSortField("signalStrength");
// m_wifiHotspotLoader.setRemoteSort(true);
SwappableListStore<GwtWifiHotspotEntry> store = new SwappableListStore<GwtWifiHotspotEntry>(m_wifiHotspotLoader);
store.setKeyProvider(new ModelKeyProvider<GwtWifiHotspotEntry>() {
public String getKey(GwtWifiHotspotEntry wifiHotspotEntry) {
return wifiHotspotEntry.getSignalStrength().toString();
}
});
m_grid = new Grid<GwtWifiHotspotEntry>(store, new ColumnModel(configs));
m_grid.setBorders(false);
m_grid.setStateful(false);
m_grid.setLoadMask(true);
m_grid.setStripeRows(true);
m_grid.setColumnLines(true);
m_grid.setColumnReordering(true);
m_grid.setAutoExpandColumn("ssid");
m_grid.getView().setAutoFill(true);
// m_grid.addPlugin(checkColumn);
m_wifiHotspotLoader.addLoadListener(new DataLoadListener(m_grid));
GridSelectionModel<GwtWifiHotspotEntry> selectionModel = new GridSelectionModel<GwtWifiHotspotEntry>();
selectionModel.setSelectionMode(SelectionMode.SINGLE);
m_grid.setSelectionModel(selectionModel);
// m_grid.addPlugin(selectionModel);
m_grid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<GwtWifiHotspotEntry>() {
@Override
public void selectionChanged(SelectionChangedEvent<GwtWifiHotspotEntry> se) {
if (se != null) {
List<GwtWifiHotspotEntry> list = se.getSelection();
if ((list != null) && (list.size() > 0)) {
GwtWifiHotspotEntry wifiHotspotEntry = list.get(0);
if (wifiHotspotEntry != null) {
m_ssidField.setValue(GwtSafeHtmlUtils.htmlUnescape(wifiHotspotEntry.getSSID()));
String security = wifiHotspotEntry.getSecurity();
if (security.equals("None")) {
m_securityCombo.setSimpleValue(MessageUtils.get(GwtWifiSecurity.netWifiSecurityNONE.name()));
} else if (security.equals("WEP")) {
m_securityCombo.setSimpleValue(MessageUtils.get(GwtWifiSecurity.netWifiSecurityWEP.name()));
} else if (security.equals("WPA")) {
m_securityCombo.setSimpleValue(MessageUtils.get(GwtWifiSecurity.netWifiSecurityWPA.name()));
} else if (security.equals("WPA2") || security.equals("WPA/WPA2")) {
m_securityCombo.setSimpleValue(MessageUtils.get(GwtWifiSecurity.netWifiSecurityWPA2.name()));
} else {
m_securityCombo.setSimpleValue(MessageUtils.get(GwtWifiSecurity.netWifiSecurityNONE.name()));
}
if (security.equals("WPA") || security.equals("WPA2") || security.equals("WPA/WPA2")) {
GwtWifiCiphers pairwiseCiphers = wifiHotspotEntry.getPairwiseCiphersEnum();
if (pairwiseCiphers == GwtWifiCiphers.netWifiCiphers_TKIP) {
m_pairwiseCiphersCombo.setSimpleValue(MessageUtils.get(GwtWifiCiphers.netWifiCiphers_TKIP.name()));
} else if (pairwiseCiphers == GwtWifiCiphers.netWifiCiphers_CCMP) {
m_pairwiseCiphersCombo.setSimpleValue(MessageUtils.get(GwtWifiCiphers.netWifiCiphers_CCMP.name()));
} else if (pairwiseCiphers == GwtWifiCiphers.netWifiCiphers_CCMP_TKIP) {
m_pairwiseCiphersCombo.setSimpleValue(MessageUtils.get(GwtWifiCiphers.netWifiCiphers_CCMP_TKIP.name()));
} else {
// let's set it for CCMP TKIP
m_pairwiseCiphersCombo.setSimpleValue(MessageUtils.get(GwtWifiCiphers.netWifiCiphers_CCMP_TKIP.name()));
}
GwtWifiCiphers groupCiphers = wifiHotspotEntry.getGroupCiphersEnum();
if (groupCiphers == GwtWifiCiphers.netWifiCiphers_TKIP) {
m_groupCiphersCombo.setSimpleValue(MessageUtils.get(GwtWifiCiphers.netWifiCiphers_TKIP.name()));
} else if (groupCiphers == GwtWifiCiphers.netWifiCiphers_CCMP) {
m_groupCiphersCombo.setSimpleValue(MessageUtils.get(GwtWifiCiphers.netWifiCiphers_CCMP.name()));
} else if (groupCiphers == GwtWifiCiphers.netWifiCiphers_CCMP_TKIP) {
m_groupCiphersCombo.setSimpleValue(MessageUtils.get(GwtWifiCiphers.netWifiCiphers_CCMP_TKIP.name()));
} else {
// let's set it for CCMP TKIP
m_groupCiphersCombo.setSimpleValue(MessageUtils.get(GwtWifiCiphers.netWifiCiphers_CCMP_TKIP.name()));
}
}
// deselect all channels
for (int channel = 1; channel <= MAX_WIFI_CHANNEL; channel++) {
m_checkboxChannelSelectionModel.deselect(channel - 1);
}
// select proper channels
m_checkboxChannelSelectionModel.select(wifiHotspotEntry.getChannel() - 1, true);
window.hide();
}
}
}
}
});
ContentPanel cp = new ContentPanel();
cp.setHeading("Wireless Networks in Range");
cp.setFrame(true);
cp.setSize(680, 365);
FillLayout layout = new FillLayout();
layout.setAdjustForScroll(true);
cp.setLayout(layout);
cp.add(m_grid);
dialogContents.add(cp);
window.add(dialogContents);
return window;
}
use of org.eclipse.kura.web.shared.model.GwtWifiHotspotEntry in project kura by eclipse.
the class TabWirelessUi method loadSsidData.
private void loadSsidData() {
this.ssidDataProvider.getList().clear();
this.searching.setVisible(true);
this.noSsid.setVisible(false);
this.ssidGrid.setVisible(false);
this.scanFail.setVisible(false);
// EntryClassUi.showWaitModal();
if (this.selectedNetIfConfig != null) {
this.gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {
@Override
public void onFailure(Throwable ex) {
FailureHandler.handle(ex);
// EntryClassUi.hideWaitModal();
}
@Override
public void onSuccess(GwtXSRFToken token) {
TabWirelessUi.this.gwtNetworkService.findWifiHotspots(token, TabWirelessUi.this.selectedNetIfConfig.getName(), new AsyncCallback<List<GwtWifiHotspotEntry>>() {
@Override
public void onFailure(Throwable caught) {
// EntryClassUi.hideWaitModal();
// FailureHandler.handle(caught);
TabWirelessUi.this.searching.setVisible(false);
TabWirelessUi.this.noSsid.setVisible(false);
TabWirelessUi.this.ssidGrid.setVisible(false);
TabWirelessUi.this.scanFail.setVisible(true);
}
@Override
public void onSuccess(List<GwtWifiHotspotEntry> result) {
for (GwtWifiHotspotEntry pair : result) {
TabWirelessUi.this.ssidDataProvider.getList().add(pair);
}
TabWirelessUi.this.ssidDataProvider.flush();
if (!TabWirelessUi.this.ssidDataProvider.getList().isEmpty()) {
TabWirelessUi.this.searching.setVisible(false);
TabWirelessUi.this.noSsid.setVisible(false);
int size = TabWirelessUi.this.ssidDataProvider.getList().size();
TabWirelessUi.this.ssidGrid.setVisibleRange(0, size);
TabWirelessUi.this.ssidGrid.setVisible(true);
TabWirelessUi.this.scanFail.setVisible(false);
} else {
TabWirelessUi.this.searching.setVisible(false);
TabWirelessUi.this.noSsid.setVisible(true);
TabWirelessUi.this.ssidGrid.setVisible(false);
TabWirelessUi.this.scanFail.setVisible(false);
}
// EntryClassUi.hideWaitModal();
}
});
}
});
}
}
Aggregations