/
hardware.ycp
947 lines (815 loc) · 32.3 KB
/
hardware.ycp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
/****************************************************************************
*
* Copyright (c) 2012 Novell, Inc.
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, contact Novell, Inc.
*
* To contact Novell about this file by physical or electronic mail,
* you may find current contact information at www.novell.com
*
****************************************************************************/
/**
* File: include/network/lan/hardware.ycp
* Package: Network configuration
* Summary: Hardware dialogs
* Authors: Michal Svec <msvec@suse.cz>
*
*/
{
textdomain "network";
import "Arch";
import "CWM";
import "Label";
import "Lan";
import "NetworkInterfaces";
import "Popup";
import "Wizard";
import "LanItems";
include "network/summary.ycp";
include "network/routines.ycp";
/* map NetworkCards */
include "network/lan/cards.ycp";
/**
* Determines if the dialog is used for adding new device or for editing existing one.
*
* Some widgets are disabled when creating new device. Also, when editing existing device, it is not possible
* to e.g. change device type.
*
* @return false if hardware widgets are embedded into another dialog, otherwise true.
*/
boolean isNewDevice()
{
return LanItems::operation == `add;
}
/**
* Dynamic initialization of help text.
*
* @return content of the help
*/
string initHelp()
{
/* Manual network card setup help 1/4 */
string hw_help = _("<p>Set up hardware-specific options for
your network device here.</p>
");
if( isNewDevice())
{
/* Manual network card setup help 2/4 */
/* translators: do not translated udev, MAC, BusID*/
hw_help = hw_help + _("<p><b>Device Type</b>. Various device types are available, select
one according your needs.</p>");
}
else
{
hw_help = hw_help + _("<p><b>Udev Rules</b> are rules for the kernel device manager that allow
associating the MAC address or BusID of the network device with its name (for
example, eth1, wlan0 ) and assures a persistent device name upon reboot.
")
+ _("<p><b>Show visible port identification</b> allows you to physically identify now configured NIC.
Set appropriate time, click <b>Blink</b> and LED diodes on you NIC will start blinking for selected time.
</p>");
}
/* Manual network card setup help 2/4 */
hw_help = hw_help + _("<p><b>Kernel Module</b>. Enter the kernel module (driver) name
for your network device here. If the device is already configured, see if there is more than one driver available for
your device in the drop-down list. If necessary, choose a driver from the list, but usually the default value works.</p>
") +
/* Manual networ card setup help 3/4 */
_("<p>Additionally, specify <b>Options</b> for the kernel module. Use this
format: <i>option</i>=<i>value</i>. Each entry should be space-separated, for example: <i>io=0x300 irq=5</i>. <b>Note:</b> If two cards are
configured with the same module name, the options will be merged while saving.</p>
") +
_("<p>If you specify options via <b>Ethtool options</b>, ifup will call ethtool with these options.</p>\n");
if( isNewDevice() && !Arch::s390() )
{
/* Manual dialog help 4/4 */
hw_help = hw_help + _("<p>If you have a <b>PCMCIA</b> network card, select PCMCIA.
If you have a <b>USB</b> network card, select USB.</p>
");
}
if(Arch::s390 ())
{
// overwrite help
/* Manual dialog help 5/4 */
hw_help = _("<p>Here, set up your networking device. The values will be
written to <i>/etc/modprobe.conf</i> or <i>/etc/chandev.conf</i>.</p>
") +
/* Manual dialog help 6/4 */
_("<p>Options for the module should be written in the format specified
in the <b>IBM Device Drivers and Installation Commands</b> manual.</p>");
}
return hw_help;
}
map<string, any> hardware = nil;
void initHardware(){
hardware = $[];
// hardware["modul"] = NetworkModules::Alias; // FIXME: MOD Lan::Module["module"]:"";
hardware["hotplug"] = LanItems::hotplug;
y2milestone("hotplug=%1", LanItems::hotplug);
hardware["modules_from_hwinfo"] = LanItems::GetItemModules(hardware["modul"]:"" );
hardware["type"] = LanItems::type;
if(hardware["type"]:"" == "") {
y2error("Shouldn't happen -- type is empty. Assuming eth.");
hardware["type"] = "eth";
}
hardware["realtype"] = NetworkInterfaces::RealType(hardware["type"]:"", hardware["hotplug"]:"");
/*if (hasAnyValue(NetworkInterfaces::Name))
{
hardware["device"] = NetworkInterfaces::device_num(NetworkInterfaces::Name);
}*/
//Use rather LanItems::device, so that device number is initialized correctly at all times (#308763)
hardware["device"] = LanItems::device;
string driver = LanItems::getCurrentItem()["udev", "driver"]:"";
hardware["default_device"] = hasAnyValue(driver) ? driver : LanItems::getCurrentItem()["hwinfo", "module"]:"" ;
hardware["options"] = LanItems::driver_options[hardware["default_device"]:""]:"";
// #38213, remember device id when we switch back from pcmcia/usb
hardware["non_hotplug_device_id"] = hardware["device"]:"";
/*
hardware["hwcfg"] = LanItems::nm_name;
if (!hasAnyValue(LanItems::nm_name) && hasAnyValue(LanItems::nm_name_old)) hardware["hwcfg"]=LanItems::nm_name_old;
*/
// FIXME duplicated in address.ycp
hardware["device_types"] = NetworkInterfaces::GetDeviceTypes();
if(issubstring(hardware["device"]:"", "bus-pcmcia")) hardware["hotplug"] = "pcmcia";
else if(issubstring(hardware["device"]:"", "bus-usb")) hardware["hotplug"] = "usb";
y2milestone("hotplug=%1", LanItems::hotplug);
hardware["devices"] = LanItems::FreeDevices(hardware["realtype"]:""); // TODO: id-, bus-, ... here
if(!contains(hardware["devices"]:[], hardware["device"]:"")) hardware["devices"] = prepend(hardware["devices"]:[], hardware["device"]:"");
hardware["no_hotplug"] = hardware["hotplug"]:"" == "";
hardware["no_hotplug_dummy"] = hardware["no_hotplug"]:false && hardware["type"]:"" != "dummy";
hardware["ethtool_options"] = LanItems::ethtool_options;
}
void initHwDialog(string text) {
/* Manual dialog caption */
string caption = _("Manual Network Card Configuration");
initHardware();
term CheckBoxes = `HBox(
`HSpacing(1.5),
/* CheckBox label */
`CheckBox(`id(`pcmcia), `opt(`notify), _("&PCMCIA"), hardware["hotplug"]:"" == "pcmcia"),
`HSpacing(1.5),
/* CheckBox label */
`CheckBox(`id(`usb), `opt(`notify), _("&USB"), hardware["hotplug"]:"" == "usb"),
`HSpacing(1.5)
);
/* Placeholders (translations) */
term XBox = `HBox(
/* ComboBox label */
`ComboBox(`id(`hotplug), `opt(`notify), _("&Hotplug Type"), []),
/* CheckBox label */
`CheckBox(`id(`pci), `opt(`notify), _("P&CI"), hardware["hotplug"]:"" == "pci"),
`HSpacing(1.5)
);
/* Disable PCMCIA and USB checkboxex on Edit and s390 */
if( !isNewDevice() || Arch::s390 ()) CheckBoxes = `VSpacing(0);
// #116211 - allow user to change modules from list
/* Frame label */
term KernelBox = `Frame(_("&Kernel Module"), `HBox(`HSpacing(0.5), `VBox(
`VSpacing(0.4),
`HBox(
/* Text entry label */
`ComboBox(`id(`modul), `opt(`editable), _("&Module Name"), hardware["modules_from_hwinfo"]:[]),
`HSpacing(0.2),
`InputField(`id(`options), `opt(`hstretch), Label::Options (), hardware["options"]:"")
),
`VSpacing(0.4),
CheckBoxes,
`VSpacing(0.4)
),`HSpacing(0.5)));
term DeviceNumberBox = `ReplacePoint(`id(`rnum),
/* TextEntry label */
`ComboBox (`id(`num), `opt(`editable, `hstretch), _("&Configuration Name"), [hardware["device"]:""]));
/* Manual dialog contents */
term TypeNameWidgets =
`VBox(
`VSpacing(0.2),
`HBox(
`HSpacing(0.5),
`ComboBox(`id(`dev), `opt(`hstretch, `notify),
/* ComboBox label */
_("&Device Type"), BuildTypesList(hardware["device_types"]:[], hardware["type"]:"")),
`HSpacing(1.5),
DeviceNumberBox,
`HSpacing(0.5)
)
);
term UdevWidget =
// TODO: Ud ... Rules
`Frame(_("Udev rules"),
`HBox(
`InputField(`id(`device_name), `opt(`hstretch), _("Device Name"), ""),
`PushButton(`id(`change_udev), _("Change"))
)
);
if( !isNewDevice()) TypeNameWidgets = `Empty();
else UdevWidget = `Empty();
term BlinkCard = `Frame(_("Show visible port identification"),
`HBox(
//translators: how many seconds will card be blinking
`IntField(`id(`blink_time), sformat("%1:", _("Seconds")), 0, 100, 5),
`PushButton(`id(`blink), _("Blink"))
)
);
term EthtoolWidget =
`Frame(_("Ethtool options"),
`HBox(
`InputField(`id(`ethtool_opts), `opt(`hstretch), _("Options"), hardware["ethtool_options"]:"")
)
);
term contents =
`VBox(
`HBox(UdevWidget,`HStretch(), ( isNewDevice()) ? `Empty() : BlinkCard ),
TypeNameWidgets,
KernelBox,
EthtoolWidget,
`VStretch()
);
UI::ReplaceWidget(`hw_content, contents);
UI::ChangeWidget(`modul, `Value, hardware["default_device"]:"");
UI::ChangeWidget(`id(`modul), `Enabled, hardware["no_hotplug_dummy"]:false);
// UI::ChangeWidget(`id(`options), `Enabled, hardware["no_hotplug_dummy"]:false);
ChangeWidgetIfExists(`id(`list), `Enabled, hardware["no_hotplug_dummy"]:false);
ChangeWidgetIfExists(`id(`hwcfg), `Enabled, hardware["no_hotplug"]:false);
ChangeWidgetIfExists(`id(`usb), `Enabled, (hardware["hotplug"]:"" == "usb" || hardware["hotplug"]:"" == "") && hardware["type"]:"" != "dummy");
ChangeWidgetIfExists(`id(`pcmcia), `Enabled, (hardware["hotplug"]:"" == "pcmcia" || hardware["hotplug"]:"" == "") && hardware["type"]:"" != "dummy");
ChangeWidgetIfExists(`id(`device_name), `Enabled, false);
ChangeWidgetIfExists(`id(`device_name), `Value, LanItems::GetItemUdev("NAME"));
if (!isNewDevice()) ChangeWidgetIfExists(`id(`dev), `Enabled,false);
ChangeWidgetIfExists(`id(`num), `ValidChars, NetworkInterfaces::ValidCharsIfcfg ());
// ChangeWidgetIfExists(`id(`hwcfg), `ValidChars, NetworkModules::ValidCharsHwcfg ());
}
/**
* Call back for a manual selection from the list
* @return dialog result
*/
define any SelectionDialog() {
string type = LanItems::type;
integer selected = 0;
list<map> hwlist = NetworkCards[type]:[];
list cards = hwlist2items(hwlist, 0);
/* Manual selection caption */
string caption = _("Manual Network Card Selection");
/* Manual selection help */
string helptext = _("<p>Select the network card to configure. Search
for a particular network card by entering the name in the search entry.</p>");
/* Manual selection contents */
term contents = `VBox(
`VSpacing(0.5),
/* Selection box label */
`ReplacePoint(`id(`rp), `SelectionBox(`id(`cards), _("&Network Card"), cards)),
`VSpacing(0.5),
/* Text entry field */
`InputField(`id(`search), `opt(`hstretch, `notify), _("&Search")),
`VSpacing(0.5)
);
Wizard::SetContentsButtons(caption, contents, helptext,
Label::BackButton(), Label::OKButton());
UI::SetFocus(`id(`cards));
any ret = nil;
while(true) {
ret = UI::UserInput();
/* abort? */
if(ret == `abort || ret == `cancel) {
if(ReallyAbort()) break;
else continue;
}
else if(ret == `search) {
string entry = (string) UI::QueryWidget(`id(`search), `Value);
list l = filter(term e, (list<term>) cards, {
return tolower(substring(e[1]:"", 0, size(entry))) == tolower(entry);
});
if(size(entry) == 0) selected = 0;
if(size(l) > 0) selected = l[0, 0, 0]:0;
cards = [];
cards = hwlist2items(hwlist, selected);
/* Selection box title */
UI::ReplaceWidget(`id(`rp), `SelectionBox(`id(`cards), _("&Network Card"), cards));
}
else if(ret == `back) {
break;
}
else if(ret == `next) {
/* FIXME: check_* */
break;
}
else {
y2error("Unexpected return code: %1", ret);
continue;
}
}
if(ret == `next) {
selected = (integer) UI::QueryWidget(`id(`cards), `CurrentItem);
if(selected == nil) selected = 0;
map card = hwlist[selected]:$[];
LanItems::description = card["name"]:"";
// NetworkModules::Alias /* FIXME: MOD Lan::Module["module"] */ = card["module"]:"";
// NetworkModules::Options /* FIXME: MOD Lan::Module["options"] */ = card["options"]:"";
}
return ret;
}
/**
* Checks if given name can be accepted as nic's new one.
*
* @returns false and pops up an explanation if the name is invalid
*/
boolean CheckUdevNicName( string name)
{
// when dev_name changed, rename ifcfg (both in NetworkInterfaces and LanItems)
boolean error = false;
if( UsedNicName( name) )
{
Popup::Error(_("Configuration name already exists."));
return false;
}
if( !ValidNicName( name) )
{
Popup::Error(_("Invalid configuration name."));
return false;
}
return true;
}
/**
* Dialog for editing nic's udev rules.
*
* @returns nic name. New one if `ok, old one otherwise.
*/
string EditUdevRulesDialog()
{
UI::OpenDialog(
`VBox(
`RadioButtonGroup(`id(`udev_type),
`VBox(
//make sure there is enough space (#367239)
`HSpacing(30),
`Label(_("Rule by:")),
`Left(`RadioButton(`id(`mac), sformat("MAC address : %1", LanItems::getCurrentItem()["hwinfo", "mac"]:""))),
`Left(`RadioButton(`id(`busid), sformat("BusID : %1", LanItems::getCurrentItem()["hwinfo", "busid"]:"") ))
)
),
`Left(
`HBox(
`CheckBox(`id(`change_dev_name), `opt(`notify), _("Change DeviceName"), false),
`InputField(`id(`dev_name), "", LanItems::GetItemUdev("NAME"))
)
),
`VSpacing(0.5),
`HBox( `PushButton (`id(`ok), `opt(`default), Label::OKButton ()),
`PushButton (`id(`cancel), Label::CancelButton ())
)
)
);
if (size(LanItems::GetItemUdev("ATTR{address}"))>0)
{
UI::ChangeWidget(`id(`udev_type), `CurrentButton, `mac);
}
else
{
if (size(LanItems::GetItemUdev("KERNELS"))>0)
{
UI::ChangeWidget(`id(`udev_type), `CurrentButton, `busid);
}
else
y2error("Unknown udev rule ");
}
UI::ChangeWidget(`dev_name, `Enabled, false);
any ret = nil;
while( ret != `cancel && ret != `abort && ret != `ok)
{
ret = UI::UserInput();
boolean change_name_active = (boolean)UI::QueryWidget(`change_dev_name, `Value);
if (ret == `change_dev_name)
{
UI::ChangeWidget(`dev_name, `Enabled, change_name_active);
}
if(ret == `ok)
{
string old_name = LanItems::GetItemUdev("NAME");
string new_name = (string)UI::QueryWidget(`dev_name, `Value);
string rule_key = UI::QueryWidget(`udev_type, `CurrentButton)==`mac ? "ATTR{address}" : "KERNELS";
string rule_value = UI::QueryWidget(`udev_type, `CurrentButton)==`mac ? LanItems::getCurrentItem()["hwinfo", "mac"]:"" : LanItems::getCurrentItem()["hwinfo", "busid"]:"";
if( change_name_active && (new_name != old_name))
{
if( CheckUdevNicName( new_name))
{
LanItems::SetItemUdev("NAME", new_name);
NetworkInterfaces::Delete2(old_name);
LanItems::Items[LanItems::current, "ifcfg"] = LanItems::GetItemUdev("NAME");
}
else
{
UI::SetFocus( `dev_name);
ret = nil;
continue;
}
}
// update udev rules
string old_key = isempty( LanItems::GetItemUdev( "KERNELS")) ? "ATTR{address}" : "KERNELS";
LanItems::ReplaceItemUdev( old_key, rule_key, rule_value);
}
}
UI::CloseDialog();
return LanItems::Items[LanItems::current, "ifcfg"]:"";
}
symbol handleHW (string key, map event) {
if (event["ID"]:nil==`cancel) LanItems::Rollback();
symbol ret=nil;
if (event["EventReason"]:"" == "ValueChanged" || event["EventReason"]:"" == "Activated") ret = (symbol)event["WidgetID"]:nil;
if (ret == `list) SelectionDialog();
// if (ret == `abort) LanItems::Rollback();
if(ret == `pcmcia || ret == `usb || ret == `dev) {
if(UI::WidgetExists(`id(`pcmcia)) || UI::WidgetExists(`id(`usb))) {
if(UI::QueryWidget(`id(`pcmcia), `Value) == true)
hardware["hotplug"] = "pcmcia";
else if(UI::QueryWidget(`id(`usb), `Value) == true)
hardware["hotplug"] = "usb";
else
hardware["hotplug"] = "";
}
y2debug("hotplug=%1", hardware["hotplug"]:"");
if(UI::WidgetExists(`id(`dev))) {
hardware["type"] = (string) UI::QueryWidget(`id(`dev), `Value);
hardware["realtype"] = NetworkInterfaces::RealType(hardware["type"]:"", hardware["hotplug"]:"");
UI::ChangeWidget (`id (`num), `Items, LanItems::FreeDevices(hardware["realtype"]:""));
}
y2debug("type=%1", hardware["type"]:"");
y2debug("realtype=%1", hardware["realtype"]:"");
if(hardware["type"]:"" == "usb") {
UI::ChangeWidget(`id(`usb), `Value, true);
hardware["hotplug"] = "usb";
}
hardware["no_hotplug"] = hardware["hotplug"]:"" == "";
hardware["no_hotplug_dummy"] = hardware["no_hotplug"]:false && hardware["type"]:"" != "dummy";
UI::ChangeWidget(`id(`modul), `Enabled, hardware["no_hotplug_dummy"]:false);
UI::ChangeWidget(`id(`options), `Enabled, hardware["no_hotplug_dummy"]:false);
ChangeWidgetIfExists(`id(`list), `Enabled, hardware["no_hotplug_dummy"]:false);
ChangeWidgetIfExists(`id(`hwcfg), `Enabled, hardware["no_hotplug"]:false);
ChangeWidgetIfExists(`id(`usb), `Enabled, (hardware["hotplug"]:"" == "usb" || hardware["hotplug"]:"" == "") && hardware["type"]:"" != "dummy");
ChangeWidgetIfExists(`id(`pcmcia), `Enabled, (hardware["hotplug"]:"" == "pcmcia" || hardware["hotplug"]:"" == "") && hardware["type"]:"" != "dummy");
hardware["device"] = (string) UI::QueryWidget (`id (`num), `Value);
if (hardware["device"]:"" != "bus-usb" && hardware["device"]:"" != "bus-pcmcia")
{
hardware["non_hotplug_device_id"] = hardware["device"]:"";
}
if(hardware["hotplug"]:"" == "usb") hardware["device"] = "bus-usb";
else if(hardware["hotplug"]:"" == "pcmcia") hardware["device"] = "bus-pcmcia";
else hardware["device"] = hardware["non_hotplug_device_id"]:"";
UI::ChangeWidget(`id(`num), `Value, hardware["device"]:"");
if(Arch::s390 ()) {
string drvtype = DriverType (hardware["type"]:"");
if (contains (["lcs", "qeth", "ctc"], drvtype))
hardware["modul"] = drvtype;
else if (drvtype == "iucv")
hardware["modul"] = "netiucv";
UI::ChangeWidget(`id(`modul), `Value, hardware["modul"]:"");
}
if(hardware["type"]:"" == "xp") {
hardware["modul"] = "xpnet";
UI::ChangeWidget(`id(`modul), `Value, hardware["modul"]:"");
}
else if (hardware["type"]:"" == "dummy") // #44582
{
hardware["modul"] = "dummy";
if( UI::WidgetExists( `id( `hwcfg))) // bnc#767946
{
hardware["hwcfg"] = (string) UI::QueryWidget (`id (`hwcfg), `Value);
hardware["options"] = sformat ("-o dummy-%1", hardware["hwcfg"]:"");
}
UI::ChangeWidget(`id(`modul), `Value, hardware["modul"]:"");
UI::ChangeWidget(`id(`options), `Value, hardware["options"]:"");
}
else if (contains(["bond", "vlan", "br", "tun", "tap"], hardware["type"]:""))
{
UI::ChangeWidget(`id(`hwcfg), `Enabled, false);
UI::ChangeWidget(`id(`modul), `Enabled, false);
UI::ChangeWidget(`id(`options), `Enabled, false);
UI::ChangeWidget(`id(`pcmcia), `Enabled, false);
UI::ChangeWidget(`id(`usb), `Enabled, false);
UI::ChangeWidget(`id(`list), `Enabled, false);
UI::ChangeWidget(`id(`hwcfg), `Value, "");
UI::ChangeWidget(`id(`modul), `Value, "");
UI::ChangeWidget(`id(`options), `Value, "");
}
}
if (ret==`change_udev){
UI::ChangeWidget(`device_name, `Value, EditUdevRulesDialog() );
}
if (ret==`blink){
string device = LanItems::device;
integer timeout = tointeger(UI::QueryWidget(`blink_time, `Value));
y2milestone("blink, blink ... %1 seconds on %2 device", timeout, device);
string cmd = sformat("ethtool -p %1 %2", device, timeout);
y2milestone("%1 : %2", cmd, SCR::Execute(.target.bash_output, cmd));
}
return nil;
}
void storeHW (string key, map event) {
if ( isNewDevice()){
LanItems::type = (string) UI::QueryWidget(`id(`dev), `Value);
string nm = sformat("%1%2", LanItems::type, (string) UI::QueryWidget(`id(`num), `Value));
//Remember current device number (#308763)
// see also bnc#391802
LanItems::device = hasAnyValue(LanItems::device) ? (string) UI::QueryWidget(`id(`num), `Value) : nm;
if(contains(NetworkInterfaces::List(""), nm)) {
Popup::Error(sformat(_("Configuration name %1 already exists.
Choose a different one."), nm));
UI::SetFocus(`id(`num));
}
NetworkInterfaces::Name = nm;
LanItems::Items[LanItems::current, "ifcfg"]= nm;
//Initialize udev map, so that setDriver (see below) sets correct module
LanItems::Items[LanItems::current, "udev"]= $[];
//FIXME: for interfaces with no hwinfo don't propose ifplugd
if (size(LanItems::getCurrentItem()["hwinfo"]:$[])==0) {
y2milestone("interface without hwinfo, proposing STARTMODE=auto");
LanItems::startmode="auto";
}
if (LanItems::type=="vlan"){
LanItems::vlan_id = (string) UI::QueryWidget(`id(`num), `Value);
}
}
string driver = (string) UI::QueryWidget(`modul, `Value);
LanItems::setDriver(driver);
LanItems::driver_options[driver] = (string) UI::QueryWidget(`options, `Value);
LanItems::ethtool_options = (string) UI::QueryWidget(`ethtool_opts, `Value);
}
/**
* S/390 devices configuration dialog
* @return dialog result
*/
define any S390Dialog() {
/* S/390 dialog caption */
string caption = _("S/390 Network Card Configuration");
string drvtype = DriverType (LanItems::type);
string helptext = "";
term contents = `Empty ();
if( contains(["qeth", "hsi"], LanItems::type) ) {
// CHANIDS
list<string> tmp_list=splitstring(LanItems::qeth_chanids, " ");
map<string, any> chanids_map = $[
"read" : tmp_list[0]:"",
"write" : tmp_list[1]:"",
"control" : tmp_list[2]:""
];
contents = `HBox(
`HSpacing(6),
/* Frame label */
`Frame(_("S/390 Device Settings"), `HBox(`HSpacing(2), `VBox(
`VSpacing(1),
`HBox(
/* TextEntry label */
`InputField(`id(`qeth_portname), `opt(`hstretch), _("&Port Name"), LanItems::qeth_portname),
`ComboBox(`id(`qeth_portnumber), _("Port Number"), [`item(`id("0"), "0", true), `item(`id("1"), "1")])
),
`VSpacing(1),
/* TextEntry label */
`InputField(`id(`qeth_options), `opt(`hstretch), Label::Options (), LanItems::qeth_options),
`VSpacing(1),
/* CheckBox label */
`Left(`CheckBox(`id(`ipa_takeover), _("&Enable IPA Takeover"))),
`VSpacing(1),
/* CheckBox label */
`Left(`CheckBox(`id(`qeth_layer2), `opt(`notify), _("Enable &Layer 2 Support"))),
/* TextEntry label */
`InputField(`id(`qeth_macaddress), `opt(`hstretch), _("Layer2 &MAC Address"), LanItems::qeth_macaddress),
`VSpacing(1),
`HBox(
`InputField(`id(`qeth_chan_read), `opt(`hstretch), _("Read Channel"), chanids_map["read"]:""),
`InputField(`id(`qeth_chan_write), `opt(`hstretch), _("Write Channel"), chanids_map["write"]:""),
`InputField(`id(`qeth_chan_control), `opt(`hstretch), _("Control Channel"), chanids_map["control"]:"")
)
), `HSpacing(2))),
`HSpacing(6)
);
/* S/390 dialog help: QETH Port name */
helptext = _("<p>Enter the <b>Port Name</b> for this interface (case-sensitive).</p>") +
/* S/390 dialog help: QETH Options */
_("<p>Enter any additional <b>Options</b> for this interface (separated by spaces).</p>") +
_("<p>Select <b>Enable IPA Takeover</b> if IP address takeover should be enabled for this interface.</p>") +
_("<p>Select <b>Enable Layer 2 Support</b> if this card has been configured with layer 2 support.</p>") +
_("<p>Enter the <b>Layer 2 MAC Address</b> if this card has been configured with layer 2 support.</p>");
}
if(drvtype == "lcs") {
list<string> tmp_list=splitstring(LanItems::qeth_chanids, " ");
map<string, any> chanids_map = $[
"read" : tmp_list[0]:"",
"write" : tmp_list[1]:""
];
contents = `HBox(
`HSpacing(6),
/* Frame label */
`Frame(_("S/390 Device Settings"), `HBox(`HSpacing(2), `VBox(
`VSpacing(1),
/* TextEntry label */
`InputField(`id(`chan_mode), `opt(`hstretch), _("&Port Number"), LanItems::chan_mode),
`VSpacing(1),
/* TextEntry label */
`InputField(`id(`lcs_timeout), `opt(`hstretch), _("&LANCMD Time-Out"), LanItems::lcs_timeout),
`VSpacing(1),
`HBox(
`InputField(`id(`qeth_chan_read), `opt(`hstretch), _("Read Channel"), chanids_map["read"]:""),
`InputField(`id(`qeth_chan_write), `opt(`hstretch), _("Write Channel"), chanids_map["write"]:"")
)
), `HSpacing(2))),
`HSpacing(6)
);
/* S/390 dialog help: LCS */
helptext = _("<p>Choose the <b>Port Number</b> for this interface.</p>") +
_("<p>Specify the <b>LANCMD Time-Out</b> for this interface.</p>");
}
list ctcitems = [
/* ComboBox item: CTC device protocol */
`item(`id("0"), _("Compatibility Mode")),
/* ComboBox item: CTC device protocol */
`item(`id("1"), _("Extended Mode")),
/* ComboBox item: CTC device protocol */
`item(`id("2"), _("CTC-Based tty (Linux to Linux Connections)")),
/* ComboBox item: CTC device protocol */
`item(`id("3"), _("Compatibility Mode with OS/390 and z/OS")),
];
if(drvtype == "ctc") {
list<string> tmp_list=splitstring(LanItems::qeth_chanids, " ");
map<string, any> chanids_map = $[
"read" : tmp_list[0]:"",
"write" : tmp_list[1]:"",
];
contents = `HBox(
`HSpacing(6),
/* Frame label */
`Frame(_("S/390 Device Settings"), `HBox(`HSpacing(2), `VBox(
`VSpacing(1),
/* TextEntry label */
`ComboBox(`id(`chan_mode), _("&Protocol"), ctcitems),
`VSpacing(1),
`HBox(
`InputField(`id(`qeth_chan_read), `opt(`hstretch), _("Read Channel"), chanids_map["read"]:""),
`InputField(`id(`qeth_chan_write), `opt(`hstretch), _("Write Channel"), chanids_map["write"]:"")
)
), `HSpacing(2))),
`HSpacing(6)
);
/* S/390 dialog help: CTC */
helptext = _("<p>Choose the <b>Protocol</b> for this interface.</p>");
}
if(drvtype == "iucv") {
contents = `HBox(
`HSpacing(6),
/* Frame label */
`Frame(_("S/390 Device Settings"), `HBox(`HSpacing(2), `VBox(
`VSpacing(1),
/* TextEntry label, #42789 */
`InputField(`id(`iucv_user), `opt(`hstretch), _("&Peer Name"), LanItems::iucv_user),
`VSpacing(1)
), `HSpacing(2))),
`HSpacing(6)
);
/* S/390 dialog help: IUCV, #42789 */
helptext = _("<p>Enter the name of the IUCV peer,
for example, the z/VM user name with which to connect (case-sensitive).</p>
");
}
Wizard::SetContentsButtons(caption, contents, helptext,
Label::BackButton(), Label::NextButton());
if (drvtype == "ctc")
UI::ChangeWidget(`id(`chan_mode), `Value, LanItems::chan_mode);
if (drvtype == "lcs")
{
UI::ChangeWidget(`id(`chan_mode), `Value, LanItems::chan_mode);
UI::ChangeWidget(`id(`lcs_timeout), `Value, LanItems::lcs_timeout);
}
if (drvtype == "qeth")
{
UI::ChangeWidget(`id(`ipa_takeover), `Value, LanItems::ipa_takeover);
UI::ChangeWidget(`id(`qeth_layer2), `Value, LanItems::qeth_layer2);
UI::ChangeWidget(`id(`qeth_macaddress), `ValidChars, ":0123456789abcdefABCDEF");
}
switch( LanItems::type)
{
case "hsi":
UI::SetFocus(`id(`qeth_options));
break;
case "qeth":
UI::SetFocus(`id(`qeth_portname));
break;
case "iucv":
UI::SetFocus(`id(`iucv_user));
break;
default:
UI::SetFocus(`id(`chan_mode));
}
// FIXME: no spaces
// UI::ChangeWidget(`id(`key), `ValidChars, "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_:;");
any ret = nil;
while(true) {
if (drvtype == "qeth") {
boolean mac_enabled = (boolean) UI::QueryWidget(`id(`qeth_layer2),`Value);
UI::ChangeWidget(`id(`qeth_macaddress), `Enabled, mac_enabled);
}
ret = UI::UserInput();
if(ret == `abort || ret == `cancel) {
if(ReallyAbort()) break;
else continue;
}
else if(ret == `back) {
break;
}
else if(ret == `next) {
if(LanItems::type == "iucv") {
// #176330, must be static
LanItems::nm_name = "static-iucv-id-" + (string) UI::QueryWidget(`id(`iucv_user), `Value);
LanItems::device = "id-" + (string) UI::QueryWidget(`id(`iucv_user), `Value);
LanItems::iucv_user = (string) UI::QueryWidget(`id(`iucv_user), `Value);
}
if(LanItems::type == "ctc")
{
LanItems::chan_mode = (string) UI::QueryWidget(`id(`chan_mode), `Value);
}
if(LanItems::type == "lcs")
{
LanItems::lcs_timeout = (string) UI::QueryWidget(`id(`lcs_timeout), `Value);
LanItems::chan_mode = (string) UI::QueryWidget(`id(`chan_mode), `Value);
}
if(LanItems::type == "qeth" || LanItems::type == "hsi") {
LanItems::qeth_options = (string) UI::QueryWidget(`id(`qeth_options), `Value);
LanItems::ipa_takeover = (boolean) UI::QueryWidget(`id(`ipa_takeover), `Value);
LanItems::qeth_layer2 = (boolean) UI::QueryWidget(`id(`qeth_layer2), `Value);
LanItems::qeth_macaddress = (string) UI::QueryWidget(`id(`qeth_macaddress), `Value);
LanItems::qeth_portnumber = (string) UI::QueryWidget(`id(`qeth_portnumber), `Value);
LanItems::qeth_portname = (string) UI::QueryWidget(`id(`qeth_portname), `Value);
}
string read = (string) UI::QueryWidget(`id(`qeth_chan_read), `Value);
string write = (string) UI::QueryWidget(`id(`qeth_chan_write), `Value);
string control = (string) UI::QueryWidget(`id(`qeth_chan_control), `Value);
if (control==nil) control="";
LanItems::qeth_chanids = String::CutBlanks( sformat("%1 %2 %3", read, write, control) );
if (!LanItems::createS390Device()){
Popup::Error(_("An error occurred while creating device.\nSee YaST log for details."));
ret=nil;
continue;
};
break;
}
else if(ret == `qeth_layer2) {
continue;
}
else {
y2error("Unexpected return code: %1", ret);
continue;
}
}
return ret;
}
map<string, map<string,any> > widget_descr_hardware = $[
"HWDIALOG" : $[
"widget" : `custom,
"custom_widget" :
`ReplacePoint(`id(`hw_content), `Empty()),
"init" : initHwDialog,
"handle" : handleHW,
"store" : storeHW,
"help" : initHelp(),
]];
/**
* Manual network card configuration dialog
* @return dialog result
*/
any HardwareDialog (){
string caption = _("Hardware Dialog");
list<map <string, any> > w = CWM::CreateWidgets (["HWDIALOG"], (map <string, map <string, any> >) widget_descr_hardware);
term contents =
`VBox(
`VStretch(),
`HBox(
`HStretch(),
`HSpacing (1),
`VBox(
w[0, "widget"]:`VSpacing (1)
),
`HSpacing (1),
`HStretch()
),
`VStretch()
);
string help = CWM::MergeHelps(w);
contents = CWM::PrepareDialog(contents, w);
Wizard::OpenNextBackDialog();
Wizard::SetContents(caption, contents, initHelp(),false, true);
Wizard::SetAbortButton(`cancel, Label::CancelButton());
// Wizard::DisableBackButton();
any ret = CWM::Run(w, $[ /*`abort:ReallyAbort*/ ]);
Wizard::CloseDialog();
// Wizard::RestoreAbortButton();
return ret;
}
/* EOF */
}